[Solved]Adding/Deleting entities with specific IDs?

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
Ghost_of_Magellan
Full Member
Posts: 58
Joined: Wed Mar 16, 2016 5:10 pm

[Solved]Adding/Deleting entities with specific IDs?

Post by Ghost_of_Magellan » Thu May 12, 2016 5:39 pm

Greetings once again!
Hope you missed me (though I doubt it).

After testing the SetRelativeZero, I though that maybe this method wasn't suited for my needs, so I went testing alternatives to see if I come around something preferable, so I tried adding a circle through code. after studying a bit of the Three Points example on the scripting tutorials page, I came up with the following functioning code:
var teste = new RAddObjectsOperation();
		//How to add circles. For dummies. I could do it, so can you!
		vl_Xf = 10;
		vl_Yf = 10;
		var point = new RCircleEntity(doc, new RCircleData(new RVector(vl_Xf, vl_Yf), 2));
		teste.addObject(point);
		docInterface.applyOperation(teste);
Fantastic.
So my question is: Is there a way to create this object with a specific ID?
I saw in the QCad documentation this contructor. Is this RObject::Id what I'm looking for?
Under the assumption that it was, I searched the RObject Constructor and attempted to create one without much success:
var teste = new RAddObjectsOperation();
		vl_Xf = 10;
		vl_Yf = 10;
		var ObjCircl = RObject(doc, 999999);
		var point = new RCircleEntity(doc, new RCircleData(new RVector(vl_Xf, vl_Yf), 2), ObjCircl);
		teste.addObject(point);
		docInterface.applyOperation(teste);
Not surprisingly, Qcad went Postal on me.
Uncaught exception at scripts/IuSYS/FirstWidget/FirstWidget.js:387: Error: :-1:-1: Abstract class RObject: Cannot be constructed.
<native>(RDocument(0x74ba308), 999999) at -1
<anonymous>(false) at scripts/IuSYS/FirstWidget/FirstWidget.js:387
<global>() at -1
I can do without this function. However that would demand that I create for() instructions that would cycle through the entire entity list just for the sake of deleting the circle, and when dealing with large quantities of entities, this would prove inefficient.

If this is possible (and the hopeful me is still assuming it is) I may need an example on how to declare and build RObject variables (I believe this is the main focus of my troubles), if no other reason than because the deleteObject also seems to work with it and I'll need it soo, as well, and under the same set of requirements. Provide examples, if possible.

Thank you very much.
Last edited by Ghost_of_Magellan on Wed May 18, 2016 9:19 am, edited 1 time in total.

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

Re: Adding/Deleting entities with specific IDs?

Post by andrew » Fri May 13, 2016 7:45 am

Ghost_of_Magellan wrote:Is there a way to create this object with a specific ID?
No. Just like when inserting records into a database, the ID is assigned automatically.

If you need to keep track of an object, you can simply store it's automatically assigned ID:
var op = new RAddObjectsOperation();
op.addObject(myEntity);
di.applyOperation(op);
var idOfAddedEntity = myEntity.getId();

Ghost_of_Magellan
Full Member
Posts: 58
Joined: Wed Mar 16, 2016 5:10 pm

Re: Adding/Deleting entities with specific IDs?

Post by Ghost_of_Magellan » Fri May 13, 2016 2:39 pm

Roger.
I've managed to make it work with your advice.

Thank you, andrew.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”