how can i run macro applying another button into vb.net

how can i run macro applying another button into vb.net

Anonymous
Not applicable
2,155 Views
11 Replies
Message 1 of 12

how can i run macro applying another button into vb.net

Anonymous
Not applicable
help, please 

I have one botton1 to connect the powershape and then I want to run the new macro into the new botton2 without open again
the powershape. I want to work wiht the same file active (botton1)

How can I do this?

I am working in visual studio 2013, language visual basic.Net
i am using windoes forms
I have powershape and powermill 2018

Excuseme my english is not very well. Iam Mexican and want to implement the automation of
powershape and powermill in my work.

Can you give me a tutorial or manually

conecct powershape.png

thanks for you help

ATTE:

Damian Hernandez
 




 


 

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

rafael.sansao
Advisor
Advisor

Paste on button 2:

 

Dim powerSHAPE As New PSAutomation(Autodesk.ProductInterface.Instance.UseExistingInstance)
Dim m as string = "MACRO RUN 'c:\macro.mac'"
powerSHAPE.Execute(m)

or

Dim powerSHAPE As New PSAutomation(Autodesk.ProductInterface.Instance.UseExistingInstance)
Dim m as string = "c:\macro.mac"
powerSHAPE.MacroRun(m)

 

I do not know if the syntax is correct. I use C#.

 

 

Documentation:

https://forums.autodesk.com/t5/powershape-and-powermill-api/getting-started-with-powershape-and-powe...

Rafael Sansão

OptiNC - www.optinc.tech

EESignature

0 Likes
Message 3 of 12

luke.edwards.autodesk
Community Manager
Community Manager

The best solution is to connect to powershape in Button1. Declare the variable of powershape in the scope of the class rather than the method. Then you can just use that instance in Button2. The alternative method posted would work but would have an overhead with connecting twice.


Luke Edwards
Consulting Services Manager
0 Likes
Message 4 of 12

Anonymous
Not applicable

Ok, Thanks

 

but, It doesn't work

0 Likes
Message 5 of 12

Anonymous
Not applicable

Good day luke, thanks for answering

 

One Question:

 

How Can I create a new instance for the button 2?

 

Can you help me?

 

add my program here:

 

Imports Autodesk.ProductInterface.PowerSHAPE
Imports System.Windows.Forms
Imports Autodesk.Geometry
Imports Autodesk.FileSystem


Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

 

'ACTIVAR powerSHAPE

Dim powerSHAPE As New PSAutomation(Autodesk.ProductInterface.InstanceReuse.UseExistingInstance)

 

Dim psModel As PSModel = powerSHAPE.ActiveModel

 

powerSHAPE.FormUpdateOff()
powerSHAPE.RefreshOff()
powerSHAPE.DialogsOff()

 

'Dim ImportFile As Autodesk.FileSystem.File = New Autodesk.FileSystem.File("C:\Users\dhernaal\Documents\69957-O1.igs")
'psModel.Import(ImportFile)


Dim startPoint As Autodesk.Geometry.Point = New Autodesk.Geometry.Point(0, 0, 0)
Dim endPoint As Autodesk.Geometry.Point = New Autodesk.Geometry.Point(10, 5, 0)
Dim myLine As PSLine = psModel.Lines.CreateLine(startPoint, endPoint)

Dim lineLength As Autodesk.Geometry.MM = myLine.Length
Dim inchLength As Inch = CType(lineLength, Inch)

MessageBox.Show("This line is" & lineLength.ToString & " mm")

 


powerSHAPE.FormUpdateOn()
powerSHAPE.RefreshOn()
powerSHAPE.DialogsOn()

 

End Sub

 


Private Sub Button2_Click(sender As Object, e As EventArgs) Handles b1.Click

 

Dim powerSHAPE As New PSAutomation(Autodesk.ProductInterface.InstanceReuse.UseExistingInstance)


Dim psModel As PSModel = powerSHAPE.ActiveModel

 

powerSHAPE.RunMacro(macroFile:=New Autodesk.FileSystem.File("C:\Users\dhernaal\Documents\Damian\RUTINA.mac"))

 

thanks

 

0 Likes
Message 6 of 12

luke.edwards.autodesk
Community Manager
Community Manager

This should work:

Imports Autodesk.ProductInterface.PowerSHAPE
Imports System.Windows.Forms
Imports Autodesk.Geometry
Imports Autodesk.FileSystem


Public Class Form1

Dim powerSHAPE As PSAutomation

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

'ACTIVAR powerSHAPE

powerSHAPE = New PSAutomation(Autodesk.ProductInterface.InstanceReuse.UseExistingInstance)

Dim psModel As PSModel = powerSHAPE.ActiveModel


powerSHAPE.FormUpdateOff()
powerSHAPE.RefreshOff()
powerSHAPE.DialogsOff()

 

'Dim ImportFile As Autodesk.FileSystem.File = New Autodesk.FileSystem.File("C:\Users\dhernaal\Documents\69957-O1.igs")
'psModel.Import(ImportFile)


Dim startPoint As Autodesk.Geometry.Point = New Autodesk.Geometry.Point(0, 0, 0)
Dim endPoint As Autodesk.Geometry.Point = New Autodesk.Geometry.Point(10, 5, 0)
Dim myLine As PSLine = psModel.Lines.CreateLine(startPoint, endPoint)

Dim lineLength As Autodesk.Geometry.MM = myLine.Length
Dim inchLength As Inch = CType(lineLength, Inch)

MessageBox.Show("This line is" & lineLength.ToString & " mm")

 


powerSHAPE.FormUpdateOn()
powerSHAPE.RefreshOn()
powerSHAPE.DialogsOn()

 

End Sub

 


Private Sub Button2_Click(sender As Object, e As EventArgs) Handles b1.Click

 

Dim psModel As PSModel = powerSHAPE.ActiveModel

 

powerSHAPE.RunMacro(macroFile:=New Autodesk.FileSystem.File("C:\Users\dhernaal\Documents\Damian\RUTINA.mac"))

Luke Edwards
Consulting Services Manager
0 Likes
Message 7 of 12

Anonymous
Not applicable

I´m so sorry. But, now I have other error

 

please, see image  below

 

BUTTON 2 no declarado.png

0 Likes
Message 8 of 12

luke.edwards.autodesk
Community Manager
Community Manager
Can you post your code, something must be wrong in it?

Luke Edwards
Consulting Services Manager
0 Likes
Message 9 of 12

luke.edwards.autodesk
Community Manager
Community Manager

Were you able to resolve this?


Luke Edwards
Consulting Services Manager
0 Likes
Message 10 of 12

Anonymous
Not applicable

Good day Luke.

 

Not, yet  and if I can post my code, I dont know what Iam doing wrong.

 

How do you make another button perform an action without it opening the powershape again?

 

Can you show me an example?

 

 

 My second button can do it other action, but this open the powershape again. I dont understand

 

thanks for you help and exuse me my english is not very well. I am Mexican.

 

Regards

0 Likes
Message 11 of 12

luke.edwards.autodesk
Community Manager
Community Manager
Accepted solution

I have extended your original example here... This should work...

 

Imports Autodesk.ProductInterface.PowerSHAPE
Imports System.Windows.Forms
Imports Autodesk.Geometry
Imports Autodesk.FileSystem

Public Class Form1

  Dim powerSHAPE As PSAutomation
  Dim model As PSModel

  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    'ACTIVAR powerSHAPE

    powerSHAPE = New PSAutomation(Autodesk.ProductInterface.InstanceReuse.UseExistingInstance)

    model = powerSHAPE.ActiveModel
    powerSHAPE.FormUpdateOff()
    powerSHAPE.RefreshOff()
    powerSHAPE.DialogsOff()

    Dim startPoint As Autodesk.Geometry.Point = New Autodesk.Geometry.Point(0, 0, 0)
    Dim endPoint As Autodesk.Geometry.Point = New Autodesk.Geometry.Point(10, 5, 0)
    Dim myLine As PSLine = psModel.Lines.CreateLine(startPoint, endPoint)

    Dim lineLength As Autodesk.Geometry.MM = myLine.Length
    Dim inchLength As Inch = CType(lineLength, Inch)

    MessageBox.Show("This line is" & lineLength.ToString & " mm")

    powerSHAPE.FormUpdateOn()
    powerSHAPE.RefreshOn()
    powerSHAPE.DialogsOn()

  End Sub

  Private Sub Button2_Click(sender As Object, e As EventArgs) Handles b1.Click

    powerSHAPE.RunMacro(macroFile:=New Autodesk.FileSystem.File("C:\Users\dhernaal\Documents\Damian\RUTINA.mac"))

  End Sub

End Class

Luke Edwards
Consulting Services Manager
0 Likes
Message 12 of 12

Anonymous
Not applicable

This is correct.

 

Thanks for you help.

 

I had an error but with you help this work very well.

 

0 Likes