[CE VBA] Select shared cells on level

Hi,

this is sample of code that I use in v8i for selecting shared cell elements on specified level. I'm trying to migrate code to CE but it seems that all shared cells from all levels are found. Workaround is to test level of every shared cell in file.
Is this some change in VBA or is this a bug? Also, I'm using Map PowerView so I'm not sure if same happens in Microstation.

Sub test()

        ActiveModelReference.UnselectAllElements


        Dim ee As ElementEnumerator

        Dim esk As New ElementScanCriteria
        Set esk = New ElementScanCriteria
        esk.ExcludeAllTypes
        esk.IncludeType msdElementTypeSharedCell
        esk.ExcludeAllLevels
        esk.IncludeLevel ActiveDesignFile.Levels.Item("8_tocke")
        Set ee = ActiveModelReference.Scan(esk)

        Dim num As Long
        num = 0
        ee.Reset

        While ee.MoveNext
        
            If ee.Current.IsSharedCellElement Then
                num = num + 1
                Debug.Print ee.Current.AsSharedCellElement.level.Name
                ActiveModelReference.SelectElement ee.Current
            
            
            End If
        
        Wend
        
        MsgBox num

End Sub

Parents
  • Hi,

    Also, I'm using Map PowerView so I'm not sure if same happens in Microstation.

    Please, respect the best practices and specify a version of the used product exactly. There were many version of MicroStation (as well as OpenCities Map) released, so it's important to know what version is used.

    Also, when you decide to do not ask in Geospatial Programming forum (which is recommended for OCM products), but here in MicroStation one, specify both OCM version and on which PowerPlatform version it's based.

    Is this some change in VBA or is this a bug?

    It looks like bug, because the level is set, but it's ignored in combination with shared cell instances. I recommend to create Service Request for this issue.

    Workaround is to test level of every shared cell in file.

    Yes ... technically it's "to test the level of share cell instance header".

    It's exactly what is done internally (when the scanning works correctly), so I do not see any problem in such solution.

    this is sample of code

    There are some (many?) useless lines, duplicating default functionality and producing worse code:

    • Dim esk As New ElementScanCriteria
      Set esk = New ElementScanCriteria
      ... the 2nd line is useless
    • esk.IncludeLevel ActiveDesignFile.Levels.Item("8_tocke")
      can be shortened to esk.IncludeLevel ActiveDesignFile.Levels("8_tocke")
    • num = 0
      ... the number is always initialized to 0, so useless
    • ee.Reset
      ... is useless, because ElementEnumerator is always returned by Scan in an initial position
    • If ee.Current.IsSharedCellElement Then
      ... no reason to test the element type when it's already controlled by ElementScanCriteria

    Regards,

      Jan

    Answer Verified By: brenks 

  • Thanks Jan,

    It's probably a bug and I created SR alreday. I just wanted to know if anybody encounterd this.

    • ee.Reset
      ... is useless, because ElementEnumerator is always returned by Scan in an initial position

    Thank you for pointing out .We have enumerator resets which will be soon deleted :)

    Other pointed out lines are there for testing purposes.

Reply Children