Page 1 of 1

[solved] Add Block Attributes

Posted: Sat Aug 28, 2021 2:29 pm
by oldStrogg
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.

Re: Add Block Attributes

Posted: Sat Aug 28, 2021 6:08 pm
by CVH
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

Re: Add Block Attributes

Posted: Sun Aug 29, 2021 6:53 am
by CVH
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

Re: Add Block Attributes

Posted: Wed Sep 01, 2021 4:30 pm
by oldStrogg
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.