Block references in a particular layer [Solved]

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
arun
Active Member
Posts: 34
Joined: Tue May 09, 2023 9:04 am

Block references in a particular layer [Solved]

Post by arun » Tue Jun 06, 2023 12:12 pm

Hi,
How do I get the all the Block References from a particular layer.
I tried the

Code: Select all

doc.queryLayerBlockEntities(layerId)
with the following code and I got an error message. Any pointer on the correct usage of this command

Code: Select all

var doc = getDocument();
var layerName = getText();
var layerId = doc.getLayerId(layerName)
var blockEntities = doc.queryLayerBlockEntities(layerId)
Thanks,
Arun
Last edited by arun on Tue Jun 06, 2023 12:46 pm, edited 1 time in total.

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

Re: Block references in a particular layer

Post by andrew » Tue Jun 06, 2023 12:34 pm

queryLayerBlockEntities returns all entities that are member of a given layer and of a given block (i.e. are part of that block definition).

You could get all entity IDs on a given layer with:

Code: Select all

var entityIds = doc.queryLayerEntities(layerId);
And all block reference IDs with:

Code: Select all

var blockReferenceIds = doc.queryAllBlockReferences();
Then intersect the two (sorted) arrays:

Code: Select all

entityIds.sort();
blockReferenceIds.sort();
var blockReferenceOnLayerIds = Array.intersect(entityIds, blockReferenceIds);

arun
Active Member
Posts: 34
Joined: Tue May 09, 2023 9:04 am

Re: Block references in a particular layer

Post by arun » Tue Jun 06, 2023 12:46 pm

Thanks Andrew. This is good :) .

CVH
Premier Member
Posts: 3467
Joined: Wed Sep 27, 2017 4:17 pm

Re: Block references in a particular layer [Solved]

Post by CVH » Tue Jun 06, 2023 4:19 pm

arun,

Remark that queryLayerBlockEntities() requires 2 parameters:
https://qcad.org/doc/qcad/3.0/developer ... 66b85e5e31

Regards,
CVH

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”