How to add objects cloned objects to a Document (scripting)?

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
garciadelcastillo
Active Member
Posts: 28
Joined: Fri May 10, 2019 6:26 pm

How to add objects cloned objects to a Document (scripting)?

Post by garciadelcastillo » Fri Jul 19, 2019 9:03 pm

Hi there!

Question: using the ECMA scripting interface, how can I add cloned Objects to a document, without overriding the original ones?

Description: I am writing a script that recursively explodes all RBlockReferenceEntities in a document, i.e. retrieves all the REntities inside a block, and adds them to the document via a transaction of the kind:

Code: Select all

// Add all the new 
var expAddOp = new RAddObjectsOperation();
for (var i = 0; i < debris.length; i++) {
	expAddOp.addObject(debris[i], false);
}
var transaction = expAddOp.apply(doc);
However, I am running into the problem that, when a RBlock has more that one RBlockReferenceEntity, since the underlying entities have the same ids, they get "overwritten." So, if a block has more than one reference, I lose all of them but the last one.

I have tried cloning the underlying block entities, but the clones have the same id as the original. I have also tried to use `RObject.setId`, but it is a protected method.

So, how can I clone an entity with a new unique Id not present in the drawing? Or how can I create an RAddObjectOperation that looks at the ids, and generate new ones if duplicate?

Thanks!

garciadelcastillo
Active Member
Posts: 28
Joined: Fri May 10, 2019 6:26 pm

Re: How to add objects cloned objects to a Document (scripting)?

Post by garciadelcastillo » Fri Jul 19, 2019 9:40 pm

Nevermind, can `forceNew` with:

Code: Select all

expAddOp.addObject(debris[i], true, true);

Post Reply

Return to “QCAD 'How Do I' Questions”