QCAD.org Forum

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).

Hi,please I would like to know which are the best strategies to identify the elements of the drawing in a unique way and retrieve them subsequently.I need to retrieve, after save operations, some elements of the drawing like layers and entities.Reading the forum I understand that the id could change after drawing modifications and save operations.For this reason I have decide to set a custom property with a unique key in the entities that I need to retrieve.Please I would like to know which are the best strategies to find them after a save operation.Further I need to know if also the layer id can change after modifications or save operation. I mean the id I get from entity.getLayerId.I suppose that if I know the layer where is located the entity I'm looking for my search could be faster. Am I correct ?For this reason I would like to incorporate the layer id in my unique key.Thank you very muchsramp

sramp wrote:I suppose that if I know the layer where is located the entity I'm looking for my search could be faster. Am I correct ?

No. Entities are not in a any way ordered by layer. The layer is just an attribute.Some optimizations exist for looking up entities by block.

sramp wrote:For this reason I would like to incorporate the layer id in my unique key.

This would be difficult to maintain. Imagine the user changes the layer an entity is on. The unique ID stored as custom property would have to be adjusted at that point.

Another thing to keep in mind is that entities can be copied. If a line entity with a custom property "MyID" set to 7 is copied, the copy will also have a custom property "MyID" which is also set to 7. I.e. the ID is no longer unique.

I've had a brief look again at object handles which are actually supposed to be persistent between save / open operations.

It looks like due to a bug in the importer code, object handles are imported but then overwritten with new ones.

This problem should be fixed for the next release. This means that you can simply use object handles to uniquely identify entities, layers, etc.This should also eliminate the problem with double IDs after copying entities, etc.

Andrew,thank you very much for your very useful answers.Thank you again to have put in evidence the problems about entities duplicates.It is a real issue and could create some problems.I'm glad to know about the object handles, this will simplify a lot my script.Bestsramp

sramp: QCAD 3.4.6 is now available with persistent object handles. An example script which selects an entity based on a handle entered as hexadecimal number is available in:scripts/Misc/MiscSelect/SelectByHandle