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?
Welcome to MicroStation VBA!
dgbitts said:Is there a good source of online help I can read to help me create this?
The documentation provided with VBA is good, and contains examples. VBA help
There are some additional information & examples on our website.
Unsurprisingly, there's no example that does exactly what you want.
Regards, Jon Summers LA Solutions
Regards, Jon Summers LA Solutions
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
This simple macro should get you started.
Rod WingSenior 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.
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.
V8i SS4 v.08.11.09,829AECOsim BD V8i
dgbitts 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.
OpenDesignFile "V:\projects\cell\example.cel" Dim oModel As ModelReference For Each oModel In ActiveDesignFile.Models ProcessModel oModel Next oModeln
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:
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
' set desired symbology
' 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"
' grab the next model and do it again
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.
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.
Save settings works only in the active design model. At least that's how it appears to be behaving.