Scripting question, add custom property

Discussion forum for contributors and developers who are using the QCAD version 3 ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Scripting question, add custom property

Postby hungerburg » Sat Jun 18, 2011 2:39 pm

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);
User avatar
hungerburg
Senior Member
 
Posts: 125
Joined: Fri May 28, 2010 7:35 pm

Re: Scripting question, add custom property

Postby andrew » Sat Jun 18, 2011 2:56 pm

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

Re: Scripting question, add custom property

Postby mariosboarina » Thu Dec 27, 2012 3:49 pm

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
mariosboarina
Junior Member
 
Posts: 19
Joined: Thu Nov 29, 2012 4:28 pm

Re: Scripting question, add custom property

Postby andrew » Thu Dec 27, 2012 4:51 pm

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

Re: Scripting question, add custom property

Postby mariosboarina » Fri Dec 28, 2012 11:49 am

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
mariosboarina
Junior Member
 
Posts: 19
Joined: Thu Nov 29, 2012 4:28 pm


Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: No registered users and 3 guests