Hello, whenever I have a macro with a loop that scans the fence, when the zoom in the drawing is large, the program works slowly and when the zoom is small, the program works quickly?
same task:
time for big zoom
time for small zoom
HI Mateusz,
at first, please read and follow the forum best practices: How an discussion can be started when you do not provide even basic information like used product, its version (build number) and what API / language is used?
Mateusz Czajkowski said:whenever I have a macro with a loop that scans the fence
Nobody can answer your question when the code is not known.
Mateusz Czajkowski said:when the zoom in the drawing is large, the program works slowly and when the zoom is small, the program works quickly?
How the fence is defined? Is is the same in both cases, so in "small zoom" (because this term is not clear, I would prefer to say e.g. "large extent") it's e.g. created from a view and in "large zoom" it's much bigger than the view extent and the view displays only small portion of the fence?
Or the fence is always created e.g. from view?
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
the program gets the vertices from polyline, then the loop sets a fence at each vertex with the code:
Sub setFence(vetex As Point3d, radius As Double) Dim rotation As Matrix3d Dim oText As TextElement Dim oCircle As EllipseElement rotation = Matrix3dFromAxisAndRotationAngle(2, 0) Set oCircle = CreateEllipseElement2(Nothing, vetex, radius, radius, rotation) With ActiveSettings .FenceVoid = False .FenceClip = False .FenceOverlap = True End With Set oView1 = ActiveDesignFile.Views(1) Set oFence = ActiveDesignFile.Fence oFence.DefineFromElement oView1, oCircle End Sub
then it scans the texts from the fence according to the scheme
:
Sub ScanFence() Dim counter As Integer Dim oElement As Element Dim oEnumerator As ElementEnumerator Dim oFence As Fence Set oFence = ActiveDesignFile.Fence If oFence.IsDefined = True Then Set oEnumerator = oFence.GetContents Do While oEnumerator.MoveNext Set oElement = oEnumerator.Current If oElement.Color = 5 Then If oElement.Type = msdElementTypeLine Or oElement.Type = msdElementTypeText Then counter = counter + 1 End If End If Loop MsgBox "The total number of elements scanned for are: " & CStr(counter) Else ShowError "A Fence Has Not Been Defined!" End If End Sub
next program calculate ... and the loop moves to the next vertex ...
Hi Mateusz,
in my opinion the code is fine.
And what about runtime conditions (fence size vs view...) I asked for? It's the only difference between the discussed cases I see now.
I can imagine (but it should be confirmed by Bentley and also tested using some simple test macro) that when the fence is "inside view", it's optimized, because the view processing is optimized as much as possible, whereas when it's "outside view", the processing is slower.
A question is: Has fence to be used? Isn't e.g. scanning using e.g. range enough? To test (real) elements overlap is always slower than (simple) range comparison.
With regards,
Thank you for your response.
I have another question, how can I otherwise select texts within a radius from a given point without using a fence
Mateusz Czajkowski said:I have another question, how can I otherwise select texts within a radius from a given point without using a fence
Following the best practices, it should be posted as a new question, but ... ;-)
It depends what exactly do you mean by "text within a radius". If it's about the text origin, I would try "two steps search":