Scroll through named fences in a Design file

Good day,

I was wondering what kind of code I would need to access MicroStation named fences.

I have created a program that counts cells in a particular active cell.

I have saved a number of named fences in my drawing, and would like to apply the same program to them, without having to manually select and activate a fence from the named fences.

What i would like to do would be something like this:

For Each mfence As Fence In ActiveModelReference.NamedFences  scanFence() 'already existing functionNext

the above code assumes that i can access the NamedFences as a collection, or array.

I found that the Fence object in MVBA has a ActiveDesignFile.Fence.GetFenceNames as a member, but i could only get a handle of the names, 

and could not actually get the fence object itself in order to perform the scan.

What is the proper way to do this.

Thanks in advance

Regards, 

Am using Windows 7, 64 bit. MicroStation V8i Select Series 3

  • Hi,

    I hope it will be more clear how to work with Named Fences from VBA (not sure if it's the best approach, but it should work ;-).

    Named fence is stored as hidden shape file in a model, the only available information is it's a shape defining a fence and its name. It means to use Name Fence, you have to receive the fence name, to receive defining element (closed shape), use the element to create active fence and after it you can receive element enumerator.

    Sub NamedFence()
        ' Obtain an array of fences' names
        Dim fences() As String
        fences = ActiveDesignFile.fence.GetFenceNames

        ' Go through the receive array of fence names
        Dim highBound As Integer
        highBound = UBound(fences)

        Dim counter As Integer
        For counter = 0 To highBound
            ProcessFence (fences(counter))
        Next
    End Sub

    Sub ProcessFence(fenceName As String)
        ' Receive element, which belongs to the named fence
        Dim fenceElement As Element
        Set fenceElement = ActiveDesignFile.fence.GetElementFromName(fenceName)

        ' Create the active fence from the element
        Dim lastView As View
        Set lastView = CommandState.lastView

        ActiveDesignFile.fence.DefineFromElement lastView, fenceElement

        ' Set fence mode here
        ActiveSettings.FenceClip = True

        ' Receive fence content
        Dim enumerator As ElementEnumerator
        Set enumerator = ActiveDesignFile.fence.GetContents

        ' Enumerate fence content and do what you need
        Do While enumerator.MoveNext
            enumerator.Current.IsHighlighted = True
        Loop
    End Sub

    With regards,

      Jan

    Answer Verified By: theGreg