[solved] Add Block Attributes

This forum is for 'Work-in-Progress' QCAD user developed script Add Ons and Plug-ins.

Please use this forum to request/submit your script Add-Ons & Plug-in idea's.

Moderators: andrew, Husky, J-J

Post Reply
oldStrogg
Newbie Member
Posts: 3
Joined: Wed May 13, 2020 8:40 am

[solved] Add Block Attributes

Post by oldStrogg » Sat Aug 28, 2021 2:29 pm

Hi,

please take a look on my simple script, and tell/direct me what do I miss.

When I place block manualy, all ok. All Block Attributs on place.
But script not add Block Attributes ("Dependent Entities"). Only Block itself.

How add Block Childes and change there values before op.addObject(blockEntity); ?

Code: Select all

di.setCurrentLayer("myLayer");
var op = new RAddObjectsOperation();    
var blockId = document.getBlockId("blockName");

var position = new RVector(x,y);
var scale = new RVector(1,1);
var angle = RMath.deg2rad(0);
var columnCount = 1;
var rowCount = 1;
var columnSpacing = 0;
var rowSpacing = 0;        

var blockEntity = new RBlockReferenceEntity(document, new RBlockReferenceData (
    blockId,
    position,
    scale,
    angle,
    columnCount,
    rowCount,
    columnSpacing,
    rowSpacing
    ));

op.addObject(blockEntity, false)
    
di.applyOperation(op);
Thankyou.

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

Re: Add Block Attributes

Post by CVH » Sat Aug 28, 2021 6:08 pm

hi,
we see you creating a new RBlockReferenceData and casting a new RBlockReferenceEntity to the document.
But your script doesn't handle any attribute entities in the block.

Have a look at AddBlock.js https://github.com/qcad/qcad/blob/maste ... ddBlock.js
And further: Block.js & BlockDialog.js ...

Regards,
CVH
Last edited by CVH on Sun Aug 29, 2021 7:19 am, edited 1 time in total.

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

Re: Add Block Attributes

Post by CVH » Sun Aug 29, 2021 6:53 am

oldStrogg wrote:
Sat Aug 28, 2021 2:29 pm
When I place block manualy, all ok. All Block Attributs on place.
In this common case one uses InsertBlock.js https://github.com/qcad/qcad/blob/maste ... rtBlock.js
There the .getOperation function handles attributes entities in the block.

Regards,
CVH

oldStrogg
Newbie Member
Posts: 3
Joined: Wed May 13, 2020 8:40 am

Re: Add Block Attributes

Post by oldStrogg » Wed Sep 01, 2021 4:30 pm

Thank you very much, CVH.
Its solve my problem.

For beginners like me, it is hard to find right piece of code in such huge js soft.

Post Reply

Return to “QCAD 'Script Add-On & Plug-in challenge' - Work in Progress”