Workshop 11 Notes Macro Programming in Microstation Basic
7 November 2006

  1. In microstation, create program on the fly by capturing the place line command; review contents of macro:
  2. Sub Macro1()

    Dim startPoint As Point3d
    Dim point As Point3d, point2 As Point3d
   
Dim lngTemp As Long

'   Start a command

    CadInputQueue.SendCommand "PLACE SMARTLINE "

'   Coordinates are in master units

    startPoint.X = 6.532417
    
startPoint.Y = 3.611098
    
startPoint.Z = 0.002057

'   Send a data point to the current command

    point.X = startPoint.X
    
point.Y = startPoint.Y
    
point.Z = startPoint.Z
    
CadInputQueue.SendDataPoint point, 3

'   Send a keyin that can be a command string

    CadInputQueue.SendKeyin "AccuDraw Rotate Top"

    point.X = startPoint.X + 18.289707

    point.Y = startPoint.Y

    point.Z = startPoint.Z + 0#

    CadInputQueue.SendDataPoint point, 3

    point.X = startPoint.X + 18.289707

    point.Y = startPoint.Y + 13.20261

    point.Z = startPoint.Z + 0#

    CadInputQueue.SendDataPoint point, 3

    point.X = startPoint.X - 1.345352

    point.Y = startPoint.Y + 13.20261

    point.Z = startPoint.Z + 0#

    CadInputQueue.SendDataPoint point, 3

    point.X = startPoint.X

    point.Y = startPoint.Y

    point.Z = startPoint.Z

    CadInputQueue.SendDataPoint point, 3

'   Send a reset to the current command

    CadInputQueue.SendReset

    CommandState.StartDefaultCommand

End Sub

3. Add structure to program and abstraction/specification

Sub MakeRec()

Dim startPoint As Point3d

Dim length As Double, width As Double

startPoint.X = 0#

startPoint.Y = 0#

startPoint.Z = 0#

length = 10#

width = 20#

Call DrawRectangle(startPoint, length, width)

End Sub

 

Sub DrawRectangle(startPoint As Point3d, length As Double, width As Double)

    Dim point As Point3d, point2 As Point3d

    Dim lngTemp As Long

'   Start a command

    CadInputQueue.SendCommand "PLACE SMARTLINE "

'   Coordinates are in master units

'   Send a data point to the current command

    point.X = startPoint.X

    point.Y = startPoint.Y

    point.Z = startPoint.Z

    CadInputQueue.SendDataPoint point, 3

'   Send a keyin that can be a command string

    CadInputQueue.SendKeyin "AccuDraw Rotate Top"

    point.X = startPoint.X + length

    point.Y = startPoint.Y

    point.Z = startPoint.Z

    CadInputQueue.SendDataPoint point, 3

    point.X = startPoint.X + length

    point.Y = startPoint.Y + width

    point.Z = startPoint.Z

    CadInputQueue.SendDataPoint point, 3

    point.X = startPoint.X

    point.Y = startPoint.Y + width

    point.Z = startPoint.Z

    CadInputQueue.SendDataPoint point, 3

    point.X = startPoint.X

    point.Y = startPoint.Y

    point.Z = startPoint.Z

    CadInputQueue.SendDataPoint point, 3

'   Send a reset to the current command

    CadInputQueue.SendReset

    CommandState.StartDefaultCommand

End Sub

4. Add iterative condition to program

Sub MakeRec()

Dim startPoint As Point3d

Dim length As Double, width As Double

startPoint.X = 0#

startPoint.Y = 0#

startPoint.Z = 0#

length = 10#

width = 20#

While length < 100#

    Call DrawRectangle(startPoint, length, width)

    length = length + 10#

    width = width + 10#

    startPoint.Z = startPoint.Z - 2#

   

Wend

End Sub

Sub DrawRectangle(startPoint As Point3d, length As Double, width As Double)

    Dim point As Point3d, point2 As Point3d

    Dim lngTemp As Long

'   Start a command

   

    CadInputQueue.SendCommand "PLACE SMARTLINE "

'   Coordinates are in master units

'   Send a data point to the current command

    point.X = startPoint.X

    point.Y = startPoint.Y

    point.Z = startPoint.Z

    CadInputQueue.SendDataPoint point, 3

'   Send a keyin that can be a command string

    CadInputQueue.SendKeyin "AccuDraw Rotate Top"

    point.X = startPoint.X + length

    point.Y = startPoint.Y

    point.Z = startPoint.Z

    CadInputQueue.SendDataPoint point, 3

    point.X = startPoint.X + length

    point.Y = startPoint.Y + width

    point.Z = startPoint.Z

    CadInputQueue.SendDataPoint point, 3

    point.X = startPoint.X

    point.Y = startPoint.Y + width

    point.Z = startPoint.Z

    CadInputQueue.SendDataPoint point, 3

    point.X = startPoint.X

    point.Y = startPoint.Y

    point.Z = startPoint.Z

    CadInputQueue.SendDataPoint point, 3

'   Send a reset to the current command

    CadInputQueue.SendReset

    CommandState.StartDefaultCommand

End Sub

5. NOTES ON DIMENSION DRIVEN DESIGN UNDER CONSTRUCTION