QCAD Project

This forum is for 'Work-in-Progress' QCAD user developed script Add Ons and Plug-ins.

Please use this forum to request/submit your script Add-Ons & Plug-in idea's.

Moderators: andrew, Husky, J-J

Post Reply
cjh
Active Member
Posts: 31
Joined: Tue Jul 12, 2016 4:51 pm

QCAD Project

Post by cjh » Fri Jul 22, 2016 6:12 pm

Hi!

I recently posted an outline of my intentions in the new user area.
http://www.qcad.org/rsforum/viewtopic.php?f=55&t=4325

I have a question on receiving events from a UI created in Qt Designer.
I would like to use the search button to modify a listView's query as seen in this image.

Image

Currently I have this dialog box pop up when I run a script from a menu item.
How can I read the text in the search box when a user presses the Search button?

Thanks for any help.

Connor

cjh
Active Member
Posts: 31
Joined: Tue Jul 12, 2016 4:51 pm

Re: QCAD Project

Post by cjh » Sun Jul 24, 2016 3:08 pm

I've been reading about signals/slots in Qt.
To handle the "Search" button on-click event, you must connect the signal to a slot.
In this case, I connect an in-line function to the on-click signal.

The following code can be used:
var button = dialog.findChild("pushButton");
	button.clicked.connect(
		function() {
			appWin.handleUserMessage("button pressed");
		});
When the user clicks the search button, "button pressed" is printed in the command history in QCAD.
Last edited by cjh on Mon Jul 25, 2016 8:12 pm, edited 1 time in total.

cjh
Active Member
Posts: 31
Joined: Tue Jul 12, 2016 4:51 pm

Re: QCAD Project

Post by cjh » Sun Jul 24, 2016 4:20 pm

I'm trying to set up a filter on my tableView shown above.
It looks like I should be using QSortFilterSqlQueryModel() to connect my text box's textChanged signal to the filter function available in QSortFilterSqlQueryModel.

When I try this:

Code: Select all

var partsProxy = new QSortFilterSqlQueryModel();
there is an error "can't find variable" when I try to run the script.

QSortFilterSqlQueryModel is included in QtCore, but it doesn't seem to have made it to QCAD.
How can I include the QSortFilterSqlQueryModel.h that exists in a full installation of Qt?

Please let me know if I'm looking at this incorrectly.

****EDIT****
I'm using a QSqlTableModel as a workaround to a QSortFilterSqlQueryModel.

As a side note, is there a way to call the Synchronize Attributes command from a script?
This will make my Title Block update much cleaner.
I believe it's hidden in qcadproscripts.dll and I can't figure out how to call it.

Connor

User avatar
andrew
Site Admin
Posts: 5602
Joined: Fri Mar 30, 2007 6:07 am

Re: QCAD Project

Post by andrew » Thu Jul 28, 2016 10:57 am

cjh wrote:As a side note, is there a way to call the Synchronize Attributes command from a script?
You should be able to trigger the tool using:
var guiAction = RGuiAction.getByScriptFile("scripts/Pro/Block/Attribute/AttributeSynchronization/AttributeSynchronization.js");
if (!isNull(guiAction)) {
    guiAction.slotTrigger();
}
Note that the file "scripts/Pro/Block/Attribute/AttributeSynchronization/AttributeSynchronization.js" is embedded as resource in the QCAD Professional plugin (qcadproscripts.dll).

cjh
Active Member
Posts: 31
Joined: Tue Jul 12, 2016 4:51 pm

Re: QCAD Project

Post by cjh » Fri Jul 29, 2016 3:36 pm

Thanks andrew.

Is it possible to see a list of the available functions provided by qcadproscripts.dll?

I'm writing a script to handle batch operations on all drawings in a folder.
I want to use it to change an attribute (Total Number of Pages) in a title block.
Is there a change attribute operation?

I'll keep digging!

Connor

User avatar
andrew
Site Admin
Posts: 5602
Joined: Fri Mar 30, 2007 6:07 am

Re: QCAD Project

Post by andrew » Fri Jul 29, 2016 4:03 pm

cjh wrote:Is it possible to see a list of the available functions provided by qcadproscripts.dll?
The QCAD Pro tools should not be considered part of the API (even tough you can trigger individual tools as described above).
You can get a list of all tools, including QCAD Pro tools under Help > About.. > Scripts
cjh wrote:Is there a change attribute operation?
You'd typically proceed like this:
- query the block reference entity (RDocument::getBlockId(), RDocument::queryBlockReferences())
- query the child entities (=block attributes) of the block reference (RDocument::queryChildEntities)
- the child entities are of type RAttributeEntity, so you can find the desired attributes based on its tag
- change attribute as desired, as usual in an operation:
var op = new RAddObjectOperation(attribute);
di.applyOperation(op);

cjh
Active Member
Posts: 31
Joined: Tue Jul 12, 2016 4:51 pm

Re: QCAD Project

Post by cjh » Fri Jul 29, 2016 5:00 pm

Right. I go through the first three steps as outlined.
BlockListAttributes.js was particularly helpful here.

When I run the following, attribute value changes do not show up until I select the edited block.
These changes are not undoable.
Should I be using a Modify Operation on the attributes that already exist in the block?
var attVal; // attribute value from attMap
var attributeIds = doc.queryChildEntities(bRefID, RS.EntityAttribute);
var op = new RAddObjectsOperation();
for (var i=0; i<attributeIds.length; i++) {
	var attributeId = attributeIds;
	var attribute = doc.queryEntityDirect(attributeId);
	if (attribute.isNull()) {
		continue;
	}
	attVal = att_val_Map.get(attribute.getTag(), null);
	if (isNull(attVal)) {
		//skip attributes wihtout values defined in the map
		continue;
	} 
     // have valid attribute + value pair
	attribute.setText(attVal);
	op.addObject(attribute);
}
di.applyOperation(op);

User avatar
andrew
Site Admin
Posts: 5602
Joined: Fri Mar 30, 2007 6:07 am

Re: QCAD Project

Post by andrew » Fri Jul 29, 2016 7:48 pm

queryEntityDirect should only be used to speed up performance when using an entity to retrieve data (read-only).

Entities that are modified and added to operations should be queried using queryEntity instead. This ensures that the modifications are then made on a clone of the entity and when the operation is applied, the difference can be recorded for undo / redo.

cjh
Active Member
Posts: 31
Joined: Tue Jul 12, 2016 4:51 pm

Re: QCAD Project

Post by cjh » Fri Jul 29, 2016 8:12 pm

AWESOME!

Thanks for the quick reply - that was it!
The whole operation process makes a lot more sense now.
Once I clean up the code for this I'll post it for others.

Next order of business will be producing a Bill of Materials from the blocks in a drawing.

Does anyone have any suggestions on how to store the part information for the drawing?
I will be pulling it from a database and formatting it within the drawing.

I will probably make a new drawing tool "Table" that draws a table of the items.

Connor

User avatar
andrew
Site Admin
Posts: 5602
Joined: Fri Mar 30, 2007 6:07 am

Re: QCAD Project

Post by andrew » Tue Aug 02, 2016 1:58 pm

cjh wrote:Does anyone have any suggestions on how to store the part information for the drawing?
Custom properties might come in handy to attach custom information to objects (i.e. entities, layers, blocks).

An example for adding a custom property to a layer can be found at:
https://github.com/qcad/qcad/tree/maste ... omProperty

Functions related to custom properties are part of the RObject class.

User avatar
andrew
Site Admin
Posts: 5602
Joined: Fri Mar 30, 2007 6:07 am

Re: QCAD Project

Post by andrew » Thu Aug 04, 2016 6:56 pm

Connor: I've split your new question into a new topic at:
http://www.qcad.org/rsforum/viewtopic.php?f=33&t=4340

Post Reply

Return to “QCAD 'Script Add-On & Plug-in challenge' - Work in Progress”