Run Macros with Visual Basic or With Windows via .Bat File

Run Macros with Visual Basic or With Windows via .Bat File

HMC400
Advocate Advocate
2,001 Views
11 Replies
Message 1 of 12

Run Macros with Visual Basic or With Windows via .Bat File

HMC400
Advocate
Advocate

Hi Guys, there is a way to run a macro from an application created with Visual Basic, where I press a button and run a macro.
Or run a macro from Windows with a .bat file?

0 Likes
Accepted solutions (1)
2,002 Views
11 Replies
Replies (11)
Message 2 of 12

TK.421
Advisor
Advisor

you can use the PowerMill API or make a plugin to run macros from a button. The API can be worked into a VB application that runs outside powermill, but is limited to the first open session of powermill, meaning if you have three pmill sessions open, the API will only execute commands in the first one (unless they've updated it). By using a plugin, you can use that plugin in each open session. A plugin is a little more work on the front end, but it's worth it if you run multiple sessions in powermill. 

 

What is the scope of your VB app?


the numbers never lie
0 Likes
Message 3 of 12

HMC400
Advocate
Advocate

Unfortunately, I don't know where to create a plugin. I state that I usually only work with an open Powermill session.
I have several macros and I wanted to create a menu with buttons where each button corresponds to a macro. in VB it's easy to create a button but I can't write the correct code. If you can also help me with a plugin I would be grateful.

0 Likes
Message 4 of 12

TK.421
Advisor
Advisor

if you only use one powermill session at a time, then the API would be a better tool to use. You can find the documentation on the Powermill/Powershape API forum, this post in particular. If you have an existing Visual Studio project, it is easy to add the necessary code to connect to powermill.  The documentation in the linked post is easy enough to read that even a feeble-minded person like myself was able to make sense and use of it.

 

Feel free to post on that forum with API questions. As for plugins, they've made it clear that those questions belong on this forum. 

 

There's plugin documentation located here: C:\Program Files\Autodesk\PowerMill 21.0.30\file\plugins\documentation

 

Plugins are a bit more work up front, but worth the effort. If you choose to go this route, pm me and I can help you a bit more. 


the numbers never lie
0 Likes
Message 5 of 12

HMC400
Advocate
Advocate

OK thanks.

0 Likes
Message 6 of 12

ChristopherMarion
Advisor
Advisor

@HMC400 

 

Have you looked into a Explorer user menu for this?

 

2020-06-15_1228.png

 

You can create a XML file that will store commands and macro's in a RMB menu from the Explorer.  The only thing is, you cannot add icons to this menu....just text.

Christopher Marion
Technical Specialist - CAM
SolidCAD - Canada





0 Likes
Message 7 of 12

HMC400
Advocate
Advocate

Thanks for the reply. Yes I know him.
User_menu.xlm, I also know Explorer.ppm and Default.ppm. It seemed like a nice alternative to try.

0 Likes
Message 8 of 12

HMC400
Advocate
Advocate

Hi I wanted to ask you for more information as you understand it. I managed to do what I wanted or create a drop-down interface where when I press it executes the macro but I would like to put the macros inside RESOURCES to be able to create an exe with everything inside without needing external files. I use VB.net and this is the button:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim macro = powerMill.LoadMacro(New Autodesk.FileSystem.File("C:\Program Files\Autodesk\pmill4\Macro\Crea Icona Anteprima Powermill_Moo0Converter.mac"))
macro.RunComplete()
End Sub

0 Likes
Message 9 of 12

TK.421
Advisor
Advisor

this is what I do for my plugins:

 

add the folder containing your macros to your visual studio project:

Capture.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Then select all the macros in that folder and change the

Build Action to 'Content', and Copy to Output Directory to 'Copy Always'

Capture.PNG


the numbers never lie
0 Likes
Message 10 of 12

HMC400
Advocate
Advocate

Thanks for the reply. Ok I think I understand but then when you call the macro you always use the same instruction?

Dim macro = powerMill.LoadMacro(New Autodesk.FileSystem.File("C:\Program Files\Autodesk\pmill4\Macro\Crea Icona Anteprima Powermill_Moo0Converter.mac"))
macro.RunComplete()

0 Likes
Message 11 of 12

TK.421
Advisor
Advisor
Accepted solution

yes, to run a macro you always use the same commands. you could create a class to help simplify that a little, but in the end, it is always that code that will call and run the macro in powermill.

 

if you're using a plugin rather than the API the code is only one line; and even what I have here can be simplified, but I am a hack programmer not a professional. I find something that works and then move on.  @Sean570 really knows this stuff better.
 m_services.DoCommand(m_token, "MACRO 'C:/macro_path.mac'");


the numbers never lie
0 Likes
Message 12 of 12

HMC400
Advocate
Advocate

Thank you so much

0 Likes