Hi community,
we're upgrading C# code for OPM V8 SS5 edition to OPM CE (upgrade 9). The IBMECObject.GetDoubleValue method is no longer available and there are some others the gets values in specific unit (ie GetDoubleValueInMM, GetDoubleValueInUors, GetDoubleValueInDegrees and so on). Because our software works in millimeter I thought that the right choose was GetDoubleValueInMM but these methods doesn't always work, i.e. return 0 even if the property has another value or the property does not exist in the EC class but 0 is a valid value in some context yet. I've also tried GetUnitlessDoubleValue and works better than GetDoubleValueInMM but not well yet. After further searches I found an indexer method in IECInstance.this[string property.] By it all seems to work well and so the question is: is it valid use the indexer instead of the GetDoubleValueXXX method ?
Here an example:// Old code: // var val = _bmECObject.GetDoubleValue("EC class property name"); // New code var val = _bmECObject.Instance["EC class property name"].DoubleValue
// Old code: // var val = _bmECObject.GetDoubleValue("EC class property name"); // New code var val = _bmECObject.Instance["EC class property name"].DoubleValue
More over the indexer throw an exception if the EC class has not the property and this is better than a 0 value. Another point is, does anyone can explain me the logic behind the GetDoubleValueXXX methods ?
Thank you all in advance,
Regards,
Simone
Hi Simone,Thankyou for posting your query on Bentley Technical Forum.We will take this up internally and will be updating you.RegardsAshutosh Patil
Hi Simone,
I have no experience with OPM and it's API, so I can add some comments (only) from EC API, as delivered with MicroStation, perspective.
Simone Padovan said:Because our software works in millimeter I thought that the right choose was GetDoubleValueInMM but these methods doesn't always work
I recommend to check what units are used by the object itself. I think, if EC instance is a representation of MicroStation element, the units are UORs. And when obtained, it's simple to convert them to master/sub units or any other units.
Simone Padovan said:After further searches I found an indexer method in IECInstance.this[string property.]
See EObjects API documentation, delivered with MicroStation SDK. IECInstance interface is described there in detail.
Also, many EC assemblies, like Bentley.ECObjects3.dll (where IECInstance is defined) are installed with xml documentation, so tools like Visual Studio or .NET Reflector are able to display the documentation in dev environment automatically.
Simone Padovan said:By it all seems to work well and so the question is: is it valid use the indexer instead of the GetDoubleValueXXX method ?
There are several ways how to obtain property value from the instance. It's not "better or worse", they only have different features and behaviors.
Simone Padovan said:Another point is, does anyone can explain me the logic behind the GetDoubleValueXXX methods ?
I have no idea, because I do not know this API, but I can guess :-)
The methods like GetPropertyValue or using indexer do not return value (primitive type), but IECPropertyValue object. For developers, less skilled in EC concepts, it can be not intuitive to distinguish between value (as displayed) and IECProperty. So (maybe) the methods you mentioned are wrappers around basic EC API, offering some extra functionality (to obtain double value and convert it to defined units) that is expected to be used more often.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Jan,
first of all thank you for the answer. Just a note. I've compared the GetDoubleValueXXX and item[accessor].DoubleValue on EC object where I was sure that it has a valid value. The indexer returns the correct value while GetDoubleValueXXX doesn't. Maybe the right choose is the indexer.
Thank you.