Getting Started with VBA in Pythagoras
Think of a macro as a shortcut that saves you from repeating the same clicks and actions over and over. Instead of manually repeating steps, you write a small program (in a simple language called VBA – Visual Basic for Applications) that tells Pythagoras what to do.
Do you always rename objects in a drawing?
Do you often calculate averages or move objects in a certain way?
With a macro, you can automate these tasks. In other words: you teach the computer how to do it for you.
Why Use VBA?
Automate repetitive tasks – no more doing the same clicks 50 times.
Add your own tools – create custom functions that don’t exist in Pythagoras yet.
Save time and reduce errors – let the software do the boring, error-prone work.
VBA in Pythagoras works very similarly to the VBA in Microsoft Office (Excel, Word). If you’ve ever recorded a macro in Excel, the concept is the same, but here it’s applied to CAD drawings.
WORKFLOW
Here’s how to create and run your very first macro inside any open document.
1. Open the Macro Library Manager
Go to Settings → Macro Library Manager… .
The Macro Manager window opens.
2. Create a New Document Library
In the Document Libraries panel (right-hand side), click the green plus button.
Type a name, e.g. MyFirstMacro. Press Enter.
3. Write the macro in the VBA Editor
Open the VBA Editor
- Select your new library under Active Document Library.
With your library selected, click the white paper icon (tooltip: Open VBA editor for active document library).
If Pythagoras asks: Apply changes and open VBA editor? Click Apply.
The VBA Editor will now open.
Write the VBA code, the Macro
Paste this code into the editor:
Sub PM_Greeting() Dim userName As String userName = InputBox("Hi there! What's your name?") If userName = "" Then MsgBox "Hello mysterious stranger! ?" Else MsgBox "Nice to meet you, " & userName & "! ?" End If End Sub
Sub … End Sub
defines your macro.PM_
is important: only macros starting withPM_
appear in the Run Macro menu.Dim userName As String
creates a variable (a kind of storage box) that will hold the name the user types. Since names are text, we tell VBA it’s a String.InputBox
asks the user for input and stores the answer inuserName
.MsgBox
shows a pop-up message with the result.
Compile
In the editor, go to Run > Compile to check your code.
Close the VBA Editor.
4. Run your VBA Code
Back in Pythagoras, go to Tools > Run Macro.
You’ll see your Greeting macro listed. Run it — and a pop-up will appear, greeting you by name (or as a ‘mysterious stranger’)!
The menu label is derived from the procedure name after removing thePM_
prefix.
Example:Sub PM_Greeting()
→ menu shows Greeting.
Congratulations — you’ve just built your first macro!
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article