Help with creating a vba macro

I have never created a vba macro in Microstation and I need to make one that will take all design models within a cel library and change the elements in them to default level with weight, linestyle and color all set bylevel. Is there a good source of online help I can read to help me create this?

Parents
  • Changing the symbology of the elements a model can be done via MicroStation key-in commands. The Batch Process utility can be used to process those key-in commands on all models in a dgn file, or cell lib. Since you said you only want to process design models I am assuming that your cell lib has sheet and/or drawing models as well that you want left as-is. In that case Batch Process won't work for you and you will have to go with a VBA.

    Fortunately you can use those same key-in commands in a vba. Sending key-in commands makes developing this vba much less daunting. Look at the sample macro below. Key-in commands are used to set the active symbology attributes, and to change the elements in the active model to the active symbology. The "pure vba" part is iterating through all of the models in the file and determining if it is the correct type.

    Sub ChangeDesignModelCells()
    Dim myModel As ModelReference

    '
    ' set desired symbology
    '
    CadInputQueue.SendKeyin "lv=default"
    CadInputQueue.SendKeyin "co=bylevel"
    CadInputQueue.SendKeyin "lc=bylevel"
    CadInputQueue.SendKeyin "wt=bylevel"

    '
    ' Iterate through all models in the active file
    '
    For Each myModel In ActiveDesignFile.Models
    '
    ' test for design model
    '
    If myModel.Type = msdModelTypeNormal Then
    '
    ' verify that it is a cell
    '
    If myModel.CanBePlacedAsCell Then
    '
    ' make the model active
    '
    myModel.Activate

    '
    ' choose all the elements and change their symbology
    '
    CadInputQueue.SendKeyin "choose all"
    CadInputQueue.SendKeyin "change level"
    CadInputQueue.SendKeyin "change color"
    CadInputQueue.SendKeyin "change linestyle"
    CadInputQueue.SendKeyin "change weight"
    CadInputQueue.SendKeyin "choose none"
    End If
    End If

    Next ' grab the next model and do it again

    End Sub
    
    

    This simple macro should get you started.

    Rod

    Rod Wing
    Senior Systems Analyst

  • Thanks. I started recording a macro to see what code it would spit out and it is exactly like what you showed me. My goal is to just open a cel library file in Microstation and run this macro and have it go thru each model within the cel library file and change the elements in each model.  I think I can take this and run with it, even though my brain is still trying to heal from my years of writing Lisp routines in AutoCad.

Reply
  • Thanks. I started recording a macro to see what code it would spit out and it is exactly like what you showed me. My goal is to just open a cel library file in Microstation and run this macro and have it go thru each model within the cel library file and change the elements in each model.  I think I can take this and run with it, even though my brain is still trying to heal from my years of writing Lisp routines in AutoCad.

Children
  • Once you get the vba to run on one model. Then you could do a batch process for all models in multiple cell libraries. I know you could write this into the vba but, sometimes I find it easier to let the batch process do the work for me.

    VBA novice,

    Roland

    Roland

    V8i SS4 v.08.11.09,829
    AECOsim BD V8i

     

  • Unknown said:
    My goal is to just open a cel library file in MicroStation and run this macro

    A cell is a model; a model is a cell.  A cell library is a DGN file with a .cel extension.

    1. Open the cell library file
    2. Iterate the models in that file
    3. For each model (cell)
    1. Enumerate the model using method ModelReference.Scan
    2. Process each element found by the enumerator

    OpenDesignFile "V:\projects\cell\example.cel"
    Dim oModel As ModelReference
    For Each oModel In ActiveDesignFile.Models
      ProcessModel oModel
    Next oModeln

     
    Regards, Jon Summers
    LA Solutions