Hi,
How do I replace a block reference with another block reference in qcad script.
I am using qcad 3.28.1 on linux.
Thanks,
Arun
replace a block reference with another block
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Re: replace a block reference with another block
Query the block reference entity by id:
var doc = this.getDocument();
var blockref = doc.queryEntity(entityId);
Query the block definition by the intended block name:
var block = doc.queryBlockDirect("MyNewBlock");
(Query Direct, no modification required)
Set the referenced block id of your block:
blockref.setReferencedBlockId(block.getId());
Cast the modified block reference back to the drawing:
var di = this.getDocumentInterface();
var op = new RAddObjectOperation(blockref, false, true);
(NOTuseCurrentAttributes, undoAble)
di.applyOperation(op);
Another option is to use an RModifyObjectOperation() instead:
var op = new RModifyObjectOperation(blockref);
It is best that you verify that a block reference entity and a block is returned instead of nothing.
And it might be required to clone the reference first.
Regards,
CVH
Re: replace a block reference with another block
Thanks CVH . Will check this out.