Hi,
I am working on a VS project. We need to pass a unique ID of an entity, which was imported via step from a known file to another app at runtime.
Passing the data is not a problem. I just need a unique id. Is there any way for doing this?
Thanks in advance.
John
Id field for an entity
-
Mike Zubovic
- Posts: 55
- Joined: Mon Jul 15, 2024 5:20 am
Re: Id field for an entity
Hello
You could use entity > IObject_DG > GetHash(), which would produce a unique 32 bit integer. But the hash has lifetime of the application and the same entity loaded in different apps simultaneously would have different values.
A reliable way would have a data structure which contains the entity path as returned by IModel_DG.GetEntityPath(IEntity_DG entity) and hash it to the required size using a general algorithm of your environment. Ask MS Copilot about the specifics. You could also add the model file name or full path before hashing.
For completeness: If you just need to assign an id to the entity and pass it around within the same app, that is a little easier. Have a look at the IUserData_DG. But generally, we have found it is better to avoid this as there may be several algorithms using this field for different purposes. It is better to construct a map IEntity_DG to the id instead.
Regards
You could use entity > IObject_DG > GetHash(), which would produce a unique 32 bit integer. But the hash has lifetime of the application and the same entity loaded in different apps simultaneously would have different values.
A reliable way would have a data structure which contains the entity path as returned by IModel_DG.GetEntityPath(IEntity_DG entity) and hash it to the required size using a general algorithm of your environment. Ask MS Copilot about the specifics. You could also add the model file name or full path before hashing.
For completeness: If you just need to assign an id to the entity and pass it around within the same app, that is a little easier. Have a look at the IUserData_DG. But generally, we have found it is better to avoid this as there may be several algorithms using this field for different purposes. It is better to construct a map IEntity_DG to the id instead.
Regards