Recording Macros


 

The Bentley Macro Recorder is a powerful tool designed for non-programmers to easily record and play back macros. It also offers basic macro editing features, making it accessible for users of all skill levels.

 

Recording Macros

Recording macros with the Bentley Macro Recorder (BMR) is straightforward. Users can record BMR macros just as they have done in the past. Once recorded, the macro is saved as a .BMR file and stored in the location specified by the MS_MACRONEWFILEDIRECTORY configuration variable.

Similar to MicroStation VBA macros, users can record macros using Bentley Macro. After recording, you can promote the macro to Python by selecting it in the Macros dialog and clicking  "Promote macro to Python." This action creates a .PY file, which is stored in the same location as the .BMR file. This process of recording and promoting macros to Python provides a quick way to reference syntax.

 

Example: Recording and Converting a Macro

In this example, we recorded a macro to set the Active Color, Weight and Place a Line by points. After recording, we converted the macro to a Python script.

Here is the complete script.

from MSPyBentley import *
from MSPyBentleyGeom import *
from MSPyECObjects import *
from MSPyDgnPlatform import *
from MSPyMstnPlatform import *

startPoint = DPoint3d(0.0, 0.0, 0.0)
point = DPoint3d(0.0, 0.0, 0.0)

PyCadInputQueue.SendKeyin("ACTIVE COLOR 2")
PyCadInputQueue.SendKeyin("ACTIVE WEIGHT 2")
PyCadInputQueue.SendKeyin("PLACE SMARTLINE")

startPoint.x = 338.43796934778367813124
startPoint.y = -0.03587736574420705149
startPoint.z = 0.0

point.x = startPoint.x
point.y = startPoint.y
point.z = startPoint.z
PyCadInputQueue.SendDataPoint(point, 1)

point.x = startPoint.x + 147.79040078169970229283
point.y = startPoint.y + 147.86937275158311422274
point.z = startPoint.z
PyCadInputQueue.SendDataPoint(point, 1)

PyCadInputQueue.SendReset()
PyCommandState.StartDefaultCommand()

 

 

Additional Resources

For more details, refer to the following links:

 

Other Language Format 

Italian

 

 

Python: Documentation | API Presentations | FAQs | GitHub | Samples | Wikis | Blogs