Page 1 of 1

Scripting question, add custom property

Posted: Sat Jun 18, 2011 2:39 pm
by hungerburg
The DXF file format allows custom properties for entities. Qcad3 can handle those. I've tried to script this, but failed so far. Watching in the debugger what the propertyEditor does also did not make me any wiser. Being just a monkey with a typewriter, same with the doxygen reference. Where in the code below would I append a property? Please advise!
var operation = new RAddObjectsOperation(false);
var linedata = new RLineData(start, end);
var entity = new RLineEntity(zeichnung.document, linedata);
operation.addObject(entity);
zeichnung.documentInterface.applyOperation(operation);

Re: Scripting question, add custom property

Posted: Sat Jun 18, 2011 2:56 pm
by andrew
var operation = new RAddObjectsOperation(false);
var linedata = new RLineData(start, end);
var entity = new RLineEntity(zeichnung.document, linedata);
entity.setProperty(new RPropertyTypeId("Wall Height"), 2.5);
entity.setProperty(new RPropertyTypeId("Material"), "Cinder block");
operation.addObject(entity);
zeichnung.documentInterface.applyOperation(operation);
This adds two custom properties to the line:
  • "Wall Height", a number with value 2.5
    "Material", a string with value "Cinder block"

Re: Scripting question, add custom property

Posted: Thu Dec 27, 2012 3:49 pm
by mariosboarina
Hi,
I've tried setting properties as described (attaching to a block, then to a blockReference).
No problem in setting and getting, but setted properties seem not to be permanent: if I save, close QCad, and then reopen it, I find no property attached, but only a kind of ",RPropertyAttributes(0x6bbe2f0)" object (in which the fisrt element of couple, containing the val, is null).
It looks like it retains only a pointer to the value object, but non the actual property.
I set property with
var operation = new RAddObjectsOperation(false);
       var blockEntity = doc.queryBlock("0");
	var blockID=blockEntity.getId();
	var entityID = doc.queryBlockReferences(blockID);
	var entity=doc.queryEntityDirect(entityID[0]);
	var di = this.getDocumentInterface();
	entity.setProperty(new RPropertyTypeId("Wall Height"), 2.5);
       operation.addObject(entity);
       di.applyOperation(operation);
I then retrive the property with
entity.getProperty(new RPropertyTypeId("Wall Height"));
It works fine, returning the right value, only until I reopen the drawing:then it fails.
I've also tried with entity.setCustomProperty("num", 2.5); and the relative get function, with same behaviour.

I'm testing with QCAD 3.0 trial.


Any suggestion(s)?

Thnk you
Mario

Re: Scripting question, add custom property

Posted: Thu Dec 27, 2012 4:51 pm
by andrew
Try starting QCAD with the command line switch:

-enable-xdata

For example unter Linux / Mac:
./qcad -enable-xdata

Windows:
qcad.exe -enable-xdata

Custom property (XData) support is disabled by default since there are known problems when loading / saving files with custom data from other applications.

When running QCAD with XData enabled, you can also add and inspect custom properties of entities using the property editor.

Note that this feature is experimental and might be subject to change in future versions of QCAD. It might also be possible to create custom properties that break file compatibility with other products or even to create drawings that cannot be stored as valid DXF / DWG files anymore.

Re: Scripting question, add custom property

Posted: Fri Dec 28, 2012 11:49 am
by mariosboarina
Ok so I'll use it very carefully; better: I'll search an alternative way if possible
what I really need is a little thing, actually: a way to store permanently at least one string (e.g. an external file name), somewhere in the saved drawing;
maybe USERI1, USERI2, etc. of known variables are free to use for general purpose?
any suggestion?
thank you again
Mario