Again add custom properties

Discussion forum for contributors and developers who are using the QCAD version 3 ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Again add custom properties

Postby sramp » Tue Dec 10, 2013 6:42 pm

Hi All,
I'm new with scripting and till now I have spent several hours reading and studying the scripts.
I have experimented with success the use of the Qt api to create custom user interface elements and I'm really impressed by the results.
QCAD is really a powerful enviroment. Many thanks to Qt and Andrew.
Now I'm facing the QCAD api and I need some help.
Reading documentation and the forum it seems that it doesn't exist a unique and persistent identifier for the entities of the drawing (DXF/DWG). Am I correct ?
In my project I need to retrieve at different times and also after drawing revisions some entities.

I've tried to use custom properties to store an unique id, but I 'm encountering a problem in my test script.
This is an excerpt of my test code :

var di = this.getDocumentInterface();
var document = this.getDocument();

// find all selected entities:
var ids = document.querySelectedEntities();
var i;
var op = new RAddObjectsOperation();
for (i=0; i<ids.length; i++)
{
debugger;
var id = ids[i];
var entity = document.queryEntityDirect(id);
//var entity = document.queryEntity(id);
entity.setProperty(new RPropertyTypeId("TEST"), 25);
//entity.setCustomProperty("QCAD","TEST",25);

op.addObject(entity);
di.applyOperation(op);
}
this.terminate();


Using queryEntityDirect the entity is deleted.
Using queryEntity the entity is not deleted, but the custom property is not added, QCAD become instable and crash.
No problems when I read the custom property ( obviously created with QCAD gui).

I'm using QCAD-PRO with a Mac (open -n QCAD-Pro.app --args -enable-script-debugger -enable-xdata ) :

QCAD version: 3.4.3.0
Date: Nov 12 2013
Qt version: 4.8.4
Compiler version: gcc 4.2.1
OS: Mac
OS version: Mac OS X 10.7

Hope somebody out of here is able to kick me in the right direction.
Thanks
sramp
sramp
Active Member
 
Posts: 26
Joined: Mon Dec 02, 2013 4:15 pm

Re: Again add custom properties

Postby sramp » Wed Dec 11, 2013 11:12 am

It seems I have found the problem with my code.
When I created the RPropertyTypeId I have omitted to put the title of the custom property.

//entity.setProperty(new RPropertyTypeId("TEST"), 25); 
entity.setProperty(new RPropertyTypeId("QCAD","TEST"), 25);


After this modifications everything works as expected.
sramp
Active Member
 
Posts: 26
Joined: Mon Dec 02, 2013 4:15 pm

Re: Again add custom properties

Postby Clive » Wed Dec 11, 2013 12:21 pm

sramp wrote:I have experimented with success the use of the Qt api to create custom user interface elements and I'm really impressed by the results.

This sounds really interesting, any chance of a screenshot of what you've managed to do ?
Clive
User avatar
Clive
Moderator
 
Posts: 896
Joined: Thu Aug 25, 2011 9:28 pm
Location: UK

Re: Again add custom properties

Postby andrew » Wed Dec 11, 2013 1:02 pm

queryEntity should be used in this case. queryEntityDirect is faster but should only be used if the entity will not be modified in any way.
The call to applyOperation should be outside of the loop (this might have caused the crash).
Calling setCustomProperty or setProperty with a custom property ID is equivalent.

sramp wrote:
var di = this.getDocumentInterface();
var document = this.getDocument();

// find all selected entities:
var ids = document.querySelectedEntities();
var i;
var op = new RAddObjectsOperation();
for (i=0; i<ids.length; i++) {
var id = ids[i];
var entity = document.queryEntity(id);
entity.setCustomProperty("QCAD","TEST",25);
op.addObject(entity);
}
di.applyOperation(op);
this.terminate();
User avatar
andrew
Site Admin
 
Posts: 2522
Joined: Fri Mar 30, 2007 6:07 am

Re: Again add custom properties

Postby sramp » Wed Dec 11, 2013 6:08 pm

Thanks Andrew,
yes, I realized to move outside the loop the RAddObjectsOperation creation and applyOperation later this morning.
Now I'm looking for a fast way to find an entity with a specific custom properties, but I suppose I have to iterate all the entities.
sramp
Active Member
 
Posts: 26
Joined: Mon Dec 02, 2013 4:15 pm


Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: No registered users and 2 guests