ECMAScript block attributes access

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
michal_w
Newbie Member
Posts: 7
Joined: Sun Nov 29, 2020 6:32 pm
Location: Poland

ECMAScript block attributes access

Post by michal_w » Mon Feb 10, 2025 10:16 am

HI,

Would you please tell me how to get read/write a block attribute ?

Thank you
Michał

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

Re: ECMAScript block attributes access

Post by CVH » Mon Feb 10, 2025 11:07 am

Hi,

With an RDocument reference in doc, all entity ID's of the type EntityAttribute:

Code: Select all

var attribIds = doc.queryAllEntities(false, false, RS.EntityAttribute);
Or all entity ID's of the type EntityBlockRefAttr:

Code: Select all

var attribIds = doc.queryAllEntities(false, false, RS.EntityBlockRefAttr);
In some way you need to filter on the intended attribute with querying the attributes themselves by id.

Code: Select all

var attrib = doc.queryEntity(id);
The RAttributeEntity has several methods including reading/writing the tag content, the plain text and so on.
See reference
The parent Block Reference id can be retrieved by a method of the REntity class: attrib.getParentId()
See reference

Then:
On any change you have to cast the entity back to the document (With an RDocumentInterface reference in di):

Code: Select all

var op = new RAddObjectOperation(attrib);
di.applyOperation(op);
If this doesn't answer your question then please provide some code where a known RAttributeEntity must be read or written.
Or a drawing with block attributes and what to select to alter.

Regards,
CVH

michal_w
Newbie Member
Posts: 7
Joined: Sun Nov 29, 2020 6:32 pm
Location: Poland

Re: ECMAScript block attributes access

Post by michal_w » Mon Feb 10, 2025 7:51 pm

Hi,

Thank you for your thorough answer. I'll try it out.

Michał

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”