From a QCAD developer:
How can I set / change properties and custom properties of existing entities?
Changing entity properties
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Re: Changing entity properties
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.
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);