Learning MicroStation VBA

Working With Selection Sets

Users can select elements in their files through a variety of methods. Once selected, we can make modifications to the selected elements by using the GetSelectedElements method.

Sub <b class="bold">TestSelectionSetA</b>()    Dim myElement As Element    Dim myElemEnum As ElementEnumerator    Set myElemEnum = ActiveModelReference.GetSelectedElements    While myElemEnum.MoveNext        Set myElement = myElemEnum.Current        myElement.Level = ActiveModelReference.Levels( _                   "A-FURN-FREE")    WendEnd Sub<a name="639"></a><a name="beginpage.341FC313-8B8A-4C4E-8603-B2020EB17B3E"></a>

We used the ElementEnumerator in a previous chapter. In this example, we get the selected elements and change the level of each element one-by-one. Let's look carefully at the code. Are we missing anything?

Sub <b class="bold">TestSelectionSetB</b>()    Dim myElement As Element    Dim myElemEnum As ElementEnumerator    Set myElemEnum = ActiveModelReference.GetSelectedElements    While myElemEnum.MoveNext        Set myElement = myElemEnum.Current        myElement.Level = ActiveModelReference.Levels("A-FURN-FREE")<b class="bold">        myElement.Rewrite</b>    WendEnd Sub

If we do not rewrite the element to the design file, element modifications are not persistent. This is critical. You could spend a great deal of time debugging code only to find that changes made to elements are not reflected in your files. Any changes made to elements in files must...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Switching Power Supplies
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.