[V8i SELECTseries 3 VBA], Cannot define a levels object with ActiveDesignFile.Levels

Hello, I am having trouble with this code to set my level object (runtime error '5')
I put here a snippet of the code:

Private Function GetFolio(ops As String)
    Dim elEnum As ElementEnumerator
    Dim el As Element
    Dim elScanCriteria As ElementScanCriteria
    Dim elLevel() As Level
    ReDim elLevel(UBound(OptionVB_CadreDecoupe))
    
    For i = 0 To UBound(OptionVB_CadreDecoupe)
        Set elLevel(i) = ActiveDesignFile.Levels(OptionVB_CadreDecoupe(i))
    Next

The error occurs on line 9.

And I put a capture of the spy tools :

any idea what I did wrong?

Parents Reply
  • I try to retrieve a list of element according to the level
    the CADRE_A3 does exist, but not in the active Dgn, the latter is in a Dgn referenced

    If you want to build a list of lines on a particular level in all reference attachments, then you need to enumerate those models.  In each model, search for lines on that level.

    Write a function that creates your scan criteria for a model...

    Function ScanCriteriaForLinesOnLevel (ByVal levelName As String, ByVal oModel As ModelReference) As ScanCriteria
        Dim oLevel As Level
        Set oLevel = oModel.Levels (levelName)
        If oLevel Is Nothing Then
          Debug.Print "Level '" & levelName & "' does not exist in model '" & oModel.Name & "'"
          Exit Function
        End If
        
        Dim oCriteria As New ElementScanCriteria
        oCriteria.ExcludeAllLevels
        oCriteria.IncludeLevel oLevel
        oCriteria.ExcludeAllTypes
        oCriteria.IncludeType msdElementTypeLine
        oCriteria.IncludeType msdElementTypeLineString
        
        Set ScanCriteriaForLinesOnLevel = oCriteria
    End Function
    

    Now get a list of lines from a model...

    Function GetLinesOnLevel (ByVal levelName As String, ByVal oModel As ModelReference) As Element()
        Dim oLines As ElementEnumerator
        Set oLines = oModel.Scan (ScanCriteriaForLinesOnLevel (levelName, oModel)
        GetLinesOnLevel = oLines.BuildArrayFromContents()
    End Function
    

    Now enumerate the active model and its attachments...

    Dim oLines() As Element
    oLines = GetLinesOnLevel (levelName, ActiveModelReference)
    Dim oModel As ModelRefernce
    For Each oModel In ActiveModelReference.Attachments
      oLines = GetLinesOnLevel (levelName, oModel)
    Next oModel
    

     
    Regards, Jon Summers
    LA Solutions

Children
No Data