VBA Tip: Pick the Right Element

Written by Rod Wing

Anyone who has done any MicroStation VBA programming, or recorded a MicroStation VBA macro, knows about the CADInputQueue class. Many beginning VBA programmers will run into problems using the CADInputQueue.SendDataPoint method. They want to select a particular MicroStation element, but their data point intersects with another element and the macro picks the wrong one.

The CADInputQueue.SendDataPointForLocate method lets you get around this problem. Besides the Point3D data point argument it also takes a MicroStation graphical element type:  CADInputQueue.SendDataPointForLocate (ElementToLocate, DataPoint). This method will select the specified element at the data point provided. 

Below is an example of the CadInputQueue.SendDataPointForLocate method in action. This function extrudes a circle along a line element to create a 3D surface to represent a pipe. Since pipe networks are likely to have line elements with common start/end points it is important we identify the correct line when extruding the surface. The CadInputQueue.SendDataPointForLocate method allows this to happen.

Public Function ExtrudeSurfaceAlongPath(elPath As LineElement, dRadius As Double, KeepPath As Boolean) _
    As Boolean
ExtrudeSurfaceAlongPath = False

 On Error GoTo EXIT_SUB

 ' Start Surface By Extrusion Along tool
 CadInputQueue.SendCommand "CONSTRUCT SURFACE ALONG"

 ' Set tool settings
 ' set Alignment to Normal
 SetCExpressionValue "tcb->ms3DToolSettings.smartSolid.tube.surfaceAlign", 0, "3DMODIFY"

 ' toggle off unneeded checkboxes
 SetCExpressionValue "tcb->ms3DToolSettings.smartSolid.tube.surfaceScale", 0, "3DMODIFY"
 SetCExpressionValue "tcb->ms3DToolSettings.smartSolid.tube.surfaceSpin", 0, "3DMODIFY"
 SetCExpressionValue "tcb->ms3DToolSettings.smartSolid.tube.surfaceLockDir", 0, "3DMODIFY"
 SetCExpressionValue "tcb->ms3DToolSettings.smartSolid.tube.surfaceRepair", 0, "3DMODIFY"
' toggle on Circular and Radius checkboxes
 SetCExpressionValue "tcb->ms3DToolSettings.smartSolid.tube.surfaceMode", 1, "3DMODIFY"
 SetCExpressionValue "tcb->ms3DToolSettings.smartSolid.tube.surfaceRadiusLocked", 1, "3DMODIFY"

 ' set radius value
 SetCExpressionValue "tcb->ms3DToolSettings.tubeSurfRad", _
                        (ActiveModelReference.UORsPerMasterUnit * dRadius), "3DMODIFY"
' set Keep Path toggle
 If KeepPath Then
 SetCExpressionValue "tcb->ms3DToolSettings.smartSolid.tube.surfaceKeepPath", 1, "3DMODIFY"
 SetCExpressionValue "tcb->ms3DToolSettings.smartSolid.tube.surfaceKeepPath", 0, "3DMODIFY"
 End If
 ' Select element and accept
 CadInputQueue.SendDataPointForLocate elPath, elPath.StartPoint
 CadInputQueue.SendDataPoint elPath.StartPoint

 ' Reset to complete

 ' All done so start default command and exit
 ExtrudeSurfaceAlongPath = True
End Function



Last month’s tips:

cache manager      inroads end condition priority   Migrating Data Shortcuts    With Statement
MicroStation: Raster                    InRoads: Modify                 AutoCAD Civil 3D:                            VBA: Using the
    Manager Cache Manager                End Condition …             Migrating Data Shortcuts                  With Statement
Don’t want to miss out on other great information? Subscribe to this blog or our monthly eNewsletter now!
Learn More ◊ Contact us today ◊ Newsletter ◊
EnvisionCAD Group EnvisionCAD YouTube Channel   

Rod Wing

Rod Wing

Rod joined EnvisionCAD in March 2007 and has nearly three decades of experience working in the CADD industry. He led the IT evaluations of Bentley InRoads and AutoDesk Civil 3D at Wisconsin DOT in their overall CAiCE replacement evaluation. He also led the MicroStation V7 to V8 upgrade effort at Wisconsin DOT which included updating not only the CADD standards to accommodate the changes in the file format but also updating legacy MDL and macros to work in the new environment. Rod received a Bachelor of Science degree from the University of Wisconsin in Cartography and a Master of Science in Geographic and Cartographic Sciences from George Mason University. Rod has extensive experience in CADD as well as the areas of GIS, cartography, plotting, scanning, raster editing/manipulation, publishing, and file/data translations. In all of these areas, he has produced custom tools and developed workflows to enhance productivity between diverse sets of applications. He instructs MicroStation classes ranging from fundamentals to advanced applications.


Leave a Reply

Your email address will not be published. Required fields are marked *