using the script shell, I can find the BlockId for the block highlighted in blue using Block.getActiveBlockId(). Using the term "Active" for the block to be insterted vs. "Current" for the block it will be inserted into, I need to change the active block, either by name or Id from a script. What function would perform this?
I can change the current block with documentInterface().setCurrentBlock(blockname).
qcad pro 3.28.1.0 on ubuntu 22.04
How to change active block via script.
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.
-
- Junior Member
- Posts: 17
- Joined: Thu Sep 07, 2023 1:17 am
-
- Junior Member
- Posts: 17
- Joined: Thu Sep 07, 2023 1:17 am
Re: How to change active block via script.
I have not solved my problem yet, but it seems that RBlockReferenceData() has the structure and methods to accomplish what I am setting out to do. I finally started understanding InsertBlock.js in order to discover this.
Re: How to change active block via script.
Hi,
Indeed, you can use a RBlockReferenceData()
var blockRefData = new RBlockReferenceData();
The block it refers to can be set by blockRefData.setReferencedBlockId(blockId);
Or by block name blockRefData.setReferencedBlockName(....);
From this data object you need to construct an RBlockReferenceEntity and cast that to the drawing.
The same can be done when you have a RBlockReferenceEntity() queried from the drawing.
blockRefEntity.setReferencedBlockId(blockId);
blockRefEntity.setReferencedBlockName(....);
The change is not immediate, you need to cast this RBlockReferenceEntity back to the drawing.
InsertBlock.js includes BlockInsert.js
BlockInsert.js includes Block.js
Block.js includes BlockList.js
Block.getActiveBlockId() will retrieve the highlighted block in the block list:
https://github.com/qcad/qcad/blob/maste ... ck.js#L110
The current active block (the one you are editing) can be retrieved by doc.getCurrentBlockId()
There is a danger in setting the current block, Block.editBlock() will verify if you are not editing a block in-place among other things:
https://github.com/qcad/qcad/blob/maste ... ck.js#L159
Regards,
CVH
Indeed, you can use a RBlockReferenceData()
var blockRefData = new RBlockReferenceData();
The block it refers to can be set by blockRefData.setReferencedBlockId(blockId);
Or by block name blockRefData.setReferencedBlockName(....);
From this data object you need to construct an RBlockReferenceEntity and cast that to the drawing.
The same can be done when you have a RBlockReferenceEntity() queried from the drawing.
blockRefEntity.setReferencedBlockId(blockId);
blockRefEntity.setReferencedBlockName(....);
The change is not immediate, you need to cast this RBlockReferenceEntity back to the drawing.
InsertBlock.js includes BlockInsert.js
BlockInsert.js includes Block.js
Block.js includes BlockList.js
Block.getActiveBlockId() will retrieve the highlighted block in the block list:
https://github.com/qcad/qcad/blob/maste ... ck.js#L110
The current active block (the one you are editing) can be retrieved by doc.getCurrentBlockId()
There is a danger in setting the current block, Block.editBlock() will verify if you are not editing a block in-place among other things:
https://github.com/qcad/qcad/blob/maste ... ck.js#L159
Regards,
CVH
-
- Junior Member
- Posts: 17
- Joined: Thu Sep 07, 2023 1:17 am
Re: How to change active block via script.
Thank you. I've gotten my block insertions working. You have been helpful.