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"
 Else
 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
 '
 CadInputQueue.SendReset

 '
 ' All done so start default command and exit
 '
 CommandState.StartDefaultCommand
 ExtrudeSurfaceAlongPath = True
EXIT_SUB:
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 is the Senior Systems Analyst at EnvisionCAD and has extensive experience in GIS, cartography, plotting, scanning, raster editing/manipulation, publishing, and file/data translations. He instructs MicroStation classes ranging from fundamentals to advanced.

Tags:

Leave a Reply

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