I am writing a VBA program to get X size of an element. I tried 2 way.
I tried above 2 ways, I would like to use Range3d, but I can't get correct X size. Please tell me the reason why.
Hi Hirotaka,
at first, please read and follow this forum best practices, especially:
Unfortunately without sharing your code it's not quite clear what your issue is. Even a basic information like what is your element are not shared (e.g. element point of circle can be its center).
Be aware there is not such definition that "element point" is equal to the element range:
It means typically the range is slightly bigger (even when the difference is very small, because calculated in UORs, not master units) than the element itself.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Answer Verified By: hirotaka nisimura
Thank you Jan. I understood very much about the way to write when I post.
[V8i SS4 VBA] Why...
I am writing...
Dim ee As ElementEnumerator Set ee = ActiveModelReference.GetSelectedElements Dim elel As LineElement Do While ee.MoveNext Set elel = ee.Current Loop Dim sizeX As Double sizeX = elel.EndPoint.X - elel.StartPoint.X If (elel.Range.High.X - elel.Range.Low.X) = sizeX Then Debug.Print "yes" Else Debug.Print "no" End If
hirotaka nisimura said:I am writing...
Your code has two crucial flaws!
Do While ee.MoveNext Set elel = ee.Current Loop
What is expected this code will do? You iterate all elements in selection set, but that's all. The test is done for the last element only, outside the loop.
If (elel.Range.High.X - elel.Range.Low.X) = sizeX Then
It's not quite clear what do you want to achieve, because the range is not the size. The size of element is something not exactly defined and can have different characteristics (line vs ellipse vs B-spline curve). But if the element range is enough (but as explained by my and illustrated on Jon's picture, it's not exact size), it can be used.
But not in this way!
You never (never never never) can test equality of two numbers represented internally using floating point. It's not possible to test equality of any decimal variable (some exceptions exist in some languages and decimal types).
To understand why requires some math knowledge and long textual description (many of such explanations can be easily found on Internet, often linked article is e.g. this one), but in this case it would be enough to think how you want to check equality of length e.g. 23.29329830483983 (plus the fact that numbers in floating point arithmetic are typically approximated only)?
MicroStation VBA offers methods to compare Poin2d and Point3d for equality using defined tolerance, but I think there is no such method available for a plain double. Often used approach is to "epsilon test", mentioned also in article I linked. It can be expressed like:
ABS(numA - numB) < tolerance
which allows to compare not numbers for equality (because it technically wrong), but to compare inequality (which is fine) between tolerance and the numbers difference.
A solution can also be to transform double into Point2d and to use Point2dEqualTolerance VBA method or to do not test equality but compare size in terms smaller / bigger.