im sure this is an easy one...hopefully
but i stored a ModelID as a long. now when i come back at a later time i need to turn that long back into a ModelID. i cant type cast, there is not an argument in the constructor . SO am i really left with looping the models and find the ID?
ElementID take a argument in the constructor to create an ElementID from a stored long.
hopefully someone can help me out here. i really dont want to loop models just to find the one i need when i already have the ID.
i want to use LoadRootModelByID.
Hi John,
John Drsek said:but i stored a ModelID as a long
In my opinion it's wrong implementation. You should store model id as ModelId object (because it's what it is) or, e.g. when stored externally, to store it as int (because internal implementation both in DGN V8 format and ModelId structure is int).
John Drsek said:ElementID take a argument in the constructor to create an ElementID from a stored long.
Yes, because Element ID is ulong (8 byte integer, explicitly System.UInt64), whereas ModelId is int (4 byte integer, explicitly System.Int32).
John Drsek said:i cant type cast, there is not an argument in the constructor
Yes, it's not, because it's not expected to be standard casting: Casting from long to int is not safe (number can be truncated).
John Drsek said:hopefully someone can help me out here
You have to cast long to int explicitly, and int will be casted to ModelId implicitly:
modelIdStruct = (int)modelIdAsLong;
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Answer Verified By: John Drsek
oh okay i just took what i did for elementid not thinking. ill switch it to int. and i would store it as modelid normally but this is being stored externally and read in.
John Drsek said:i just took what i did for elementid not thinking
When it's expected a particular object only encapsulate numeric identification (ElementId and ModelId are the most famous examples), there are more ways how to investigate what type is used internally:
typedef Int32