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

  • Ok, so I have studied this code and I am starting to understand some of the commands, especially the CadInputQueue.Sendkeyin. I put this in to a macro I started and ran it on a cel library that is on old numbered levels. What I found is that the macro doesn't go down the list of models in alphabetical order for some reason. It jumps around to random selections but it appears to process all models. The wierd thing I noticed is that at some point, it stopped setting the active level parameters to default, co bylevel, lc bylevel and wt bylevel. It suddenly set the level to 1 and 0 for all other parameters. So I thought to myself, ok, mebbe we need to relocate the section on setting level and other parameters to a spot in the macro after the model is actually opened. So, I changed things to this:

    Sub ChangeDesignModelCells()

       Dim myModel As ModelReference

         ' 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                

                   ' set desired symbology

                     CadInputQueue.SendKeyin "lv=Default"

                     CadinputQueue.SendKeyin "co=Bylevel"

                     CadInputQueue.SendKeyin "lc=Bylevel"

                     CadInputQueue.SendKeyin "wt=Bylevel"

                   ' 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

       ' grab the next model and do it again

        Next  

    End Sub

    This seemed to solve the problem with the macro randomly giving up on changing active parameters to default level and color weight and style to bylevel.

    However......

    As I ran the macro again, and after it went thru all models, I noticed that after a couple of loops it STILL decided to not change the Linestyle to bylevel. It seemed to change everything else in the elements. I am still looking thru the macro and looking at the models within the cel libraries to see what could be causing this. More as it develops.

  • You may need to programmatically save settings.

     
    Regards, Jon Summers
    LA Solutions

  • Save settings works only in the active design model. At least that's how it appears to be behaving.

Reply Children
No Data