blockReference permanent identifier

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

blockReference permanent identifier

Post by mariosboarina » Mon Jan 21, 2013 6:40 pm

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

mariosboarina
Junior Member
Posts: 19
Joined: Thu Nov 29, 2012 4:28 pm

Re: blockReference permanent identifier

Post by mariosboarina » Mon Jan 28, 2013 11:59 am

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

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

Re: blockReference permanent identifier

Post by andrew » Mon Jan 28, 2013 9:09 pm

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.

mariosboarina
Junior Member
Posts: 19
Joined: Thu Nov 29, 2012 4:28 pm

Re: blockReference permanent identifier

Post by mariosboarina » Fri Feb 08, 2013 3:59 pm

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.

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

Re: blockReference permanent identifier

Post by andrew » Sat Feb 09, 2013 1:01 am

Excellent! Thanks for sharing your solution.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”