Archive | February 2011

VBA Shortcut Methods

Bentley Systems does a great job of making MicroStation VBA easy. With each new release of the object model there are new objects, methods, and properties.Most support new functionality, but in some cases these additions help improve readability. For example,

GetLastValidGraphicalElement is a shortcut for GraphicalElementCache.GetLastValidElement

I recommend checking the Remarks section of the help documentation and the version for the methods you use. Especially if you are writting VBAs for older V8 releases. You may have to use the long form instead of the shortcut if you are writting a macro for an older version of MicroStation. I’ve also noticed that the documents don’t provide the precise release versions. So even though the new method was implemented in V8 2004, it may not have been added until a later release of V8 2004. In this case replace the shortcut with the long form of the method.

Straighten Line

I received an email recently from a reader who asked how to straighten lines? Given a bunch of lines placed at different angles to one another how would you make them parrallel and all the same length? Something like this.

straighten lines

The interesting bit here isn't how do you straighten the lines (just match end points, remove the original and draw a new line) but how do you determine which line is the template?

From a developer's point of view these are design objectives and not programming issues. In the example I created I decided to use the first line found in the selection set or fence. In reality the designer might need to use any number of lines as the template. In this case you will need to first identify the template line before running the processor. I would call this a business rule, or design rule and it creates a requirement that removes autonomy from the program. In my program I ask, am I processing the first line. If yes, then I save the end points and if no, it means I already have the end points so just process.  In MicroStation VBA (a good way to prototype) it might look like this…

Complete code can be downloaded from the cadgurus page. Filter by MVBA and look for xy_change_vert (

Easy. This means the program is deciding which line to use for me. Notice that this program also provides an option so that the designer can decide which line should be the template. It says if the use first element option is turned off then the program expects to find coordinate values in the form. Another approach might be to build a locate command. In fact this might prove to be better since you won't need to validate the form controls (ie make sure points have been defined).

Homework: Find the source file in the cadgurus archive. Study the locate command and figure out how to eliminate the form. Advanced: Can you validate that the element selected is a line element?

Getting Started

I was working my way (hacking) through a new, well at least new to me, programming language when it occurred to me that the information I was finding didn’t start from scratch. It made me think, “if I were a CAD Manager who needed to automate something, and had never coded, where would I start?”

Those of us trained as designers, engineers, and architects versus computer programmers probably started with some example code. Nope, back further, we probably wondered what to do with this cryptic file of instructions. I know I can edit this in notepad, but then what?  How do I run it? Stepwise instruction often assumes you know the basics.

So, newbies, now that I got you all interested I’m going to tell you that we’re probably not going to resolve that – at least not in one post.  What I can offer is a link to an old article I wrote many years ago – to get you started – “The Five Minute VBA“. It’s still relevant and can help you get started if you are a new CAD manager and/or are new to CAD development.

Managing the Noise

I'm amazed by CAD managers. They are most often the hardest working team members. The environments they manage are increasingly complex. Except in the largest organizations these guys are also responsible all software and hardware. In many cases managing all IT assets from soup to nuts. You can imagine that with the addition of each software, new design office, new workstation config that chaos is not far off.

It's our mission to help you simplify. Cut through the noise, so to speak. Help you find the means, the resources to make even a small part of your design automation easier to manage. We are CADmanage. We specialize in software and services that will help you simplify and control your CAD environment.

One of the ways we will do that is to provide social tools that will let you learn and interact with others in the same position. We'll offer our own suggestions from time to time and offer some free resources when we can.

Our team has integrated the archives into our website, and we hope you find it useful. As we evolve we will provide tips and script snippets to help you out. And, of course for more complex issues we're available with software a services to help you get to the next level in performance, stability, and simplicity.