Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

Optimising VBA code that copies element multiple times

$
0
0

Hi, I'm writing the code that copies cells multiple times.The simplified example code below. It copies selected element 10 times.

Sub copySelectedElement()
    Dim el As Element, ee As ElementEnumerator, newEl As Element, mr As ModelReference
    Dim offset As Point3d
    Set mr = ActiveModelReference
    Set ee = mr.GetSelectedElements
    If ee.MoveNext Then
        Set el = ee.Current
    Else
        Exit Sub
    End If
    For i = 1 To 10
        offset.X = i
        Set newEl = mr.CopyElement(el)
        newEl.Move offset
        newEl.Rewrite
    Next
End Sub

I find this code super slow, as the lines 13 and 15 in the code make the changes in the model that are seen on the screen which I think slows down the whole code. Is there a way to do same thing without showing each step on the screen and just update model view in the end of the code?


Viewing all articles
Browse latest Browse all 7260

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>