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

Reply
  • 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

Children