Changing entity properties

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
User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Changing entity properties

Post by andrew » Thu Aug 08, 2013 1:52 pm

From a QCAD developer:

How can I set / change properties and custom properties of existing entities?

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

Re: Changing entity properties

Post by andrew » Thu Aug 08, 2013 2:02 pm

You can change properties through an operation in the same way as you would change the geometry of an entity.

Note that operations live on a higher level than transactions. An operation triggers a transaction underneath and in addition keeps the views up to date. Operations can also be previewed. Whenever a document has views attached to it, use operations. If a document is being modified without views, a transaction may be used instead.
// create new operation:
RModifyObjectsOperation* op = new RModifyObjectsOperation();

// fetch existing entity:
QSharedPointer<REntity> entity = document->queryEntity(entityId);

// TODO: check if entity is NULL

// change entity:
// set / change custom property:
entity->setProperty(RPropertyTypeId("MyProperty"), 37.5);

// set fixed property:
entity->setProperty(REntity::PropertyColor, RColor("blue"));
// which is the same as:
entity->setColor(RColor("blue"));

// set layer ID:
entity->setLayerId(...);

// add modified entity to operation:
op->addObject(entity);

// apply operation to document (trigger transaction) and update views, etc.
// document interface takes ownership of the operation (deletes it when done)
documentInterface->applyOperation(op);
The same in ECMAScript:
// create new operation:
var op = new RModifyObjectsOperation();
 
// fetch existing entity:
var entity = document.queryEntity(entityId);

// TODO: check if entity is undefined
 
// change entity:
// set / change custom property:
entity.setProperty(new RPropertyTypeId("MyProperty"), 37.5);
 
// set fixed property:
entity.setProperty(REntity.PropertyColor, new RColor("blue"));
// which is the same as:
entity.setColor(new RColor("blue"));
 
// set layer ID:
entity.setLayerId(...);
 
// add modified entity to operation:
op.addObject(entity);
 
// apply operation to document (trigger transaction) and update views, etc:
documentInterface.applyOperation(op);

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”