Issue when setting level from level library ...

We have discovered the following problem:

In our environment (Microstation V8i (SELECT Series 3) - Version 08.11.09.459) we have got several VBA programs in place which support the users to create dimensionings of elements.

After starting the first sub the program sets the desired level which should be used for dimensioning (ie. the user selects a level name in a userform and the desired level is set as level within the dimension style).

Here is the code of this selection:

If FrmDeckenbemassung.ob_Bemassung = True Then

  Set lev = ActiveDesignFile.Levels.Find("DECKENELEMENTIERUNG_BEMASSUNG")
  
  If Not lev Is Nothing Then
  
    Set ActiveSettings.DimensionStyle.Level = lev
  
  End If
  
  Set lev = ActiveDesignFile.Levels.Find("DECKENELEMENTIERUNG_BEMASSUNG_LÜFTUNG")

  If Not lev Is Nothing Then lev.IsDisplayedInView(ActiveDesignFile.Views(1)) = False

Else

  Set lev = ActiveDesignFile.Levels.Find("DECKENELEMENTIERUNG_BEMASSUNG_LÜFTUNG")
  
  If Not lev Is Nothing Then
  
    Set ActiveSettings.DimensionStyle.Level = lev
  
  End If
  
  Set lev = ActiveDesignFile.Levels.Find("DECKENELEMENTIERUNG_BEMASSUNG")

  If Not lev Is Nothing Then lev.IsDisplayedInView(ActiveDesignFile.Views(1)) = False

End If


Now - the Levels "DECKENELEMENTIERUNG_BEMASSUNG" and "DECKENELEMENTIERUNG_BEMASSUNG_LÜFTUNG" belong to a level library.

The code works fine as long as the level is already in use within the ActiveDesignFile. If it is not it ends up in a runtime error:

When I now stop the code, and add p.ex. a line element that uses the same level that was selected for the dimensioning and re-run the dimensioning sub again then it works without troubles!


What's the problem with using a level from a level library when it was not used before in the ActiveDesignFile?

Parents
  • Hi,

    Unknown said:
    What's the problem with using a level from a level library when it was not used before in the ActiveDesignFile?

    It's not a problem, but just a feature how MicroStation works ;-)

    If a level comes from a dgnlib, but has not been used yet in the active design file, it's displayed only. Its definition exists only in the dgnlib, but not in active file. When such library is used, the definition is copied automatically from dgnlib to the file.

    Some VBA methods work with all available levels and they don't distnguished between levels in active design file and levels from dgnlib(s). But there are some methods that require the level has to exist in the active file.

    The solution is to use lev.IsFromLevelLibrary property thats is False if the level definition does not exist in the active design file yet.

    With regards,

      Jan

  • Hi Jan,

    thanks for this explanation!

    Unknown said:
    The solution is to use lev.IsFromLevelLibrary property thats is False if the level definition does not exist in the active design file yet.

    But I still don't know how to solve this - how do I react when lev.IsFromLevelLibrary is True?

    How can I achieve that the level definition gets copied to the ActiveDesignFile? ActiveDesignFile.AddNewLevel does not work as the level already exists ...

  • Hi,

    Unknown said:
    How can I achieve that the level definition gets copied to the ActiveDesignFile? ActiveDesignFile.AddNewLevel does not work as the level already exists ...

    Unfortunately I don't know the answer. It can be done manually from Level Manager by "Import" in mouse context menu, but equal key-in does not work fine if there are spaces in the level name. I suppose there is some way how to do it using VBA (and maybe MDL) API only, but it requires some research and testing :-(

    With regards,

      Jan

  • Unknown said:
    But I still don't know how to solve this - how do I react when lev.IsFromLevelLibrary is True?

    Create a temporary element (e.g. a zero-length line) using that level.  Add the element to the active model.  MicroStation copies the level from the DGNLib into the active design file's level table.  Delete the temporary element — the level definition is now in the active DGN file.

    We've even published an example!

     
    Regards, Jon Summers
    LA Solutions

    Answer Verified By: quasi_modo 

  • Unknown said:
    Create a temporary element (e.g. a zero-length line) using that level.  Add the element to the active model.  MicroStation copies the level from the DGNLib into the active design file's level table.  Delete the temporary element — the level definition is now in the active DGN file.

    I have tried that already before I started this thread but it failed.

    Now I found the reason why it failed:

        If lev.IsFromLevelLibrary = True Then
        
          Dim TempLine As LineElement
          Set TempLine = CreateLineElement2(Nothing, Point3dZero, Point3dFromXY(100, 100))
          TempLine.Level = lev
          
          ActiveModelReference.AddElement TempLine
          ActiveModelReference.RemoveElement TempLine
          
          Set lev = ActiveDesignFile.Levels.Find("DECKENELEMENTIERUNG_BEMASSUNG_LÜFTUNG")
            
        End If
      
        Set ActiveSettings.DimensionStyle.Level = lev

    After placing the temporary element it's essential to set the level once again - I did not do this in my first try ...

    Now it works like a charm ...

    Thanks Jan & Jon for your assistance!!

Reply
  • Unknown said:
    Create a temporary element (e.g. a zero-length line) using that level.  Add the element to the active model.  MicroStation copies the level from the DGNLib into the active design file's level table.  Delete the temporary element — the level definition is now in the active DGN file.

    I have tried that already before I started this thread but it failed.

    Now I found the reason why it failed:

        If lev.IsFromLevelLibrary = True Then
        
          Dim TempLine As LineElement
          Set TempLine = CreateLineElement2(Nothing, Point3dZero, Point3dFromXY(100, 100))
          TempLine.Level = lev
          
          ActiveModelReference.AddElement TempLine
          ActiveModelReference.RemoveElement TempLine
          
          Set lev = ActiveDesignFile.Levels.Find("DECKENELEMENTIERUNG_BEMASSUNG_LÜFTUNG")
            
        End If
      
        Set ActiveSettings.DimensionStyle.Level = lev

    After placing the temporary element it's essential to set the level once again - I did not do this in my first try ...

    Now it works like a charm ...

    Thanks Jan & Jon for your assistance!!

Children
No Data