Create Level

http://translate.google.it/

I have a macro that reads xls files (A2: A15) and creates layers in dgn.
macro works, I see the layers created. I close and reopen Microstatio and levels have disappeared.
any idea
I enclose , dgn file , xls , macro, movie

to  run the macro change inside the file path xls

layer.zip
  • Hi,

    In microstation vba help: AddNewLevel:

    Remarks

    This method returns the newly-created Level object.

    Subsequently, you should call Levels.Rewrite to make the change permanent.


    Laurent

  • Laurentd is correct, you will need to call Levels.Rewrite.  Try updating your code as follows:

    ...

        For i = 2 To 15               ' righe da file xls
            
             livello.levelname = foglio.Cells(i, 1)
             livello.levelcode = foglio.Cells(i, 2)
            
             If False = LevelExists(livello.levelname, True) Then
                 Application.ActiveDesignFile.AddNewLevel (livello.levelname)
                 Set oLevel = ActiveDesignFile.Levels(livello.levelname)
                 Debug.Print "Level Name Added: " & oLevel.Name
             End If
       
        Next
        ActiveDesignFile.Levels.Rewrite

    ...

    Function LevelExists(sLevelName As String, Optional bExactName As Boolean) As Boolean

        Dim oLevel As MicroStationDGN.Level
        Dim oLevels As MicroStationDGN.Levels
        Dim bLevelInDGNLibrary As Boolean
        Dim sName As String
        sName = sLevelName
       
        ' Validate input
        If sName = "" Then
            Exit Function
        End If

        ' Perform "like" search for name
        If bExactName <> True Then
            sName = "*" + sLevelName + "*"
        End If
       
        ' Locate name
        Set oLevels = ActiveDesignFile.Levels
        Set oLevel = oLevels.Find(sName)
        If oLevel Is Nothing Then
            Debug.Print "Level name not found: " & sName
            Exit Function
        Else
            bLevelInDGNLibrary = oLevel.IsFromLevelLibrary
            Debug.Print "Level Name: " & oLevel.Name & ", Number: " & oLevel.Number & ", ID: " & oLevel.ID & ", InDGNLib: " & CStr(bLevelInDGNLibrary)
        End If
        LevelExists = True
    End Function



    Answer Verified By: Massimo Callegher 

  • it works perfect

    thank you very much

    Massimo Callegher