[solved] Need to get info global position of a block

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
sperez
Junior Member
Posts: 11
Joined: Thu Apr 25, 2019 4:41 pm

[solved] Need to get info global position of a block

Post by sperez » Sun Feb 20, 2022 8:19 pm

Hi , I'm a begginer developing with QCAD, and I need to solve the next issue:

I'm developing a script in order to get infro about the global position of a block in the draw but if I call the getOrigin() method I always obtain for all of them RVector(0, 0, 0, true).

Code: Select all

    
    var doc = new RDocument(new RMemoryStorage(), new RSpatialIndexNavel());
    .....
    var idblock = doc.queryAllBlocks();
    for (var i=0;i<idblock.length;i++) {
        var obj = doc.queryBlock(idblock[i]);
        print (idblock[i]+"-"+obj.getName()+"-"+obj.getOrigin());
    }
 
If I call the entities inside the block I have obtained the position inside the block , but I need the global position in the draw.

If I select the block inside QCAD ide I have obtained the global position that is what I need to obtain with my code
Screenshot_20220220_201700.png
Screenshot_20220220_201700.png (33.13 KiB) Viewed 4429 times


Santi Perez
[email protected]

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

Re: Need to get info global position of a block

Post by andrew » Sun Feb 20, 2022 8:39 pm

A block does not have a position in the drawing as a block merely defines the contents of the block. You can think of a block as a separate drawing stored within your drawing. For example, a block "Door" might contain a drawing of a door. An offset may be applied to a block, essentially shifting that drawing by an offset (this is rather unusual in practice). Blocks are not visible in the drawing but they are listed in the block list of QCAD.

What you are likely looking for is the block references. Each block can be inserted into the drawing at various positions, scales and angles. Each such insertion of a block into the drawing is called a block reference. Unlike blocks, block references are drawing entities like lines or arcs and as such are visible in the drawing.

To solve your problem, you'd have to query the list of block references for each block:

Code: Select all

doc.queryBlockReferences(blockId)
You can then get the position of each block reference using

Code: Select all

blockRef.getPosition()
Note that each block can have zero, one or several block references to it, so there can be no answer or multiple answers to the question "What is the position of my block in the drawing?".

sperez
Junior Member
Posts: 11
Joined: Thu Apr 25, 2019 4:41 pm

Re: Need to get info global position of a block

Post by sperez » Mon Feb 21, 2022 10:22 pm

Ok thanks for your quickly help.

But is It possible yo explode the content of the block with ecmascript ? I have found the way to add, remove, list, ... but I don't know the way to explode.

Thanks

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

Re: Need to get info global position of a block

Post by andrew » Mon Feb 21, 2022 10:25 pm

Yes:
- include("scripts/Modify/Explode/Explode.js")
- select the entities (block references to explode)
- Explode.explodeSelection(documentInterface);

Please post new, unrelated questions to a new topic, thanks.

sperez
Junior Member
Posts: 11
Joined: Thu Apr 25, 2019 4:41 pm

Re: Need to get info global position of a block

Post by sperez » Fri Feb 25, 2022 7:19 pm

Thanks It works perfectly.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”