Disconnecting from PowerMill (API)

Disconnecting from PowerMill (API)

jeff.davis
Participant Participant
716 Views
6 Replies
Message 1 of 7

Disconnecting from PowerMill (API)

jeff.davis
Participant
Participant

Is there a way to terminate the connection to the API?  When I close PowerMill I get a COM error and I believe it's because I'm still connected using this command.

Dim PM As New PMAutomation(Autodesk.ProductInterface.InstanceReuse.UseExistingInstance)
            Dim Session As PMProject = PM.ActiveProject

I want to close Powermill after use so I free up a network license until needed again.

0 Likes
717 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

I haven't tested this, but have you tried

session = Nothing
powermill = Nothing
0 Likes
Message 3 of 7

luke.edwards.autodesk
Community Manager
Community Manager

This sounds odd.  I've never seen an issue like this before where PowerMill gives an issue when it closes.  If the suggestion of setting things to "Nothing" works then please let us know.  Otherwise if you have a small example application with it happening then please provide that and we can happily investigate.

Luke


Luke Edwards
Consulting Services Manager
0 Likes
Message 4 of 7

jeff.davis
Participant
Participant

Adding the code suggested above did not help me.  My test application still locks up after closing PowerMill.

My example:  I started a new VB.net project and added a single button in the GUI.

I did not build the application into an executable, i'm just running this through Visual Studio.  My application locks up after PowerMill closes, so I know there is still an issue with closing PM. 

 

Imports Autodesk.ProductInterface.PowerMILL

Public Class Form1

    Private Sub CmdClosePM_Click(sender As Object, e As EventArgs) Handles CmdClosePM.Click

        'Open Powermill and connect to it.
        Dim PM As New PMAutomation(Autodesk.ProductInterface.InstanceReuse.UseExistingInstance)
        Dim Session As PMProject = PM.ActiveProject

        'Close PowerMill
        PM.DialogsOn()
        PM.Quit()
        Session = Nothing
        PM = Nothing

    End Sub
End Class
0 Likes
Message 5 of 7

Anonymous
Not applicable

OK, i can reproduce the problem and as far as i can see, the "PM.Quit()" command closes PowerMill but doesn't kill the task. And in the API the Quit command waits until the task is killed which ends in an infinite loop.

 

A quick workaround is to use

PM.Execute("EXIT")

instead of "PM.Quit()"

Notice the parameter "NO" closes the project without saving it. So either you save the project before or change the parameter to "YES" if you don't want to lose your progress.

 

0 Likes
Message 6 of 7

jeff.davis
Participant
Participant

Oh no!  That command is an obsolete option from the old days!!  😁

 

Autodesk you better look at this "Quit" command and come up with something.

0 Likes
Message 7 of 7

luke.edwards.autodesk
Community Manager
Community Manager

I couldn't reproduce it but I could see why it might fail so I have modified the logic slightly.

Try it again in the next version to see if just calling Quit works...


Luke Edwards
Consulting Services Manager
0 Likes