[Solved] Getting an entities id or handle returns -1

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
Taygete
Full Member
Posts: 50
Joined: Wed May 14, 2014 8:53 am

[Solved] Getting an entities id or handle returns -1

Post by Taygete » Sat Sep 06, 2014 9:21 am

Hi Andrew,

I have a script which allows a user to create two entities, a circle and some text. The circle entity has some custom properties that are created when the script is run. The text depicts (in textual form) what the circles type is, for example type a, b, c etc.

The user is to be allowed to change some of the custom properties of the circle entity via our dialog box (not the QCAD properties editor) and I need to be able to change the text entity (associated with the circle) when this happens.

I thought a way to do this would be to add a custom property to the circle entity that holds the text entities id (or handle) but whenever I try to set the value getId() always returns an id of -1, however QCAD property editor lists a correct handle.

I have tried setting the value before and after the applyOperation but still get the same result.

Do you have any idea why getId might return -1?

Edit:
I meant to add I may look into creating a block at some point to group the two items together but I am not sure if this will cause me other issues down the line.

Thanks,

Andrew.
Last edited by Taygete on Fri Sep 12, 2014 6:59 am, edited 1 time in total.

Taygete
Full Member
Posts: 50
Joined: Wed May 14, 2014 8:53 am

Re: Getting an entities id or handle returns -1

Post by Taygete » Fri Sep 12, 2014 6:59 am

It appears the issue I was having is because (I think) I was trying to get the entities ids too early and it had not been set.

I resolved this the other day by using the transaction returned from applyOperation(...) and setting the ids accordingly.

Code: Select all

var transaction = di.applyOperation(...);
var ids = transaction.getAffectedObjects();
var committedEntity = document.queryEntity(ids[0]);
...

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”