Page 1 of 1

blockReference permanent identifier

Posted: Mon Jan 21, 2013 6:40 pm
by mariosboarina
Hi,
I can't find a way to permanently identify a blockReferenceEntity. I need it as key to an external xml db.
- I tried both Id and Handle, but they change on save-close-reopen of QCad; Id always changes, Handle changes after modification to other elements of the drawings (adding blocks).
- It's better not to assign permanent custom properties with XData enabled (see other post viewtopic.php?f=30&t=1546).
- Referenced block names are not unique (one block, more blockreferences).
Any suggestions?

Thank you
Ciao
Mario

Re: blockReference permanent identifier

Posted: Mon Jan 28, 2013 11:59 am
by mariosboarina
Ok, I surrender, I think there's no solution, I didn't find any :(
I'll try attaching an XData to interested entities and then query for them on drawing opening, hoping this isn't going to cause compatibility problems. As a consequence I'll have to start QCad within a .bat, with the -enable-xdata option.
Mario

Re: blockReference permanent identifier

Posted: Mon Jan 28, 2013 9:09 pm
by andrew
Yes, XData might be the best way for now. If the XData handing of QCAD changes, there will still be a way to query and adjust existing XData. Just the user interface and API might be different in the future. I would recommend to encapsulate all XData related functionality in some helper functions (e.g. setXData(entity, data...), getXData(entity) to make future updates easier.

Re: blockReference permanent identifier

Posted: Fri Feb 08, 2013 3:59 pm
by mariosboarina
Ok, it is working wothout any problems. :D
I saved and resored after reopening an integer ID for some blockRefs.
I'm testing it since days and non problem outcame.
I've also tried exporting in Autocad, modifing and re-importing it, and all is fine.

Here's the snippet I tried out:

Code: Select all

MyCommand.prototype.setEntityProperty = function(entity, propID, prop) {
	entity.setProperty(propID, prop);
	var di = this.getDocumentInterface();
	var operation = new RAddObjectsOperation(false);
    operation.addObject(entity);
    di.applyOperation(operation);
}


MyCommand.prototype.getEntityProperty = function(entity, propID) {
	var prop =  entity.getProperty(propID);
	return prop[0];
}
Thank you.

Re: blockReference permanent identifier

Posted: Sat Feb 09, 2013 1:01 am
by andrew
Excellent! Thanks for sharing your solution.