How is the session of powermill selected when using UseExistingInstance

How is the session of powermill selected when using UseExistingInstance

Anonymous
Not applicable
1,682 Views
6 Replies
Message 1 of 7

How is the session of powermill selected when using UseExistingInstance

Anonymous
Not applicable

When using an existing instance of powermill, how can I ensure that the session I want is selected when multiple sessions of Powermill are currently open?

 

Dim PowerMill as PMAutomation = New PMAutomation(Autodesk.ProductInterface.InstanceReuse.UseExistingInstance)
Dim Session as PMProject = PowerMill.ActiveProject

I have assumed that the code above will link to the Currently active (Has focus) session of Powermill.  However, this doesn't appear to be the case.

 

How is the PMAutomation project selected?  From my testing it appears to be the first created session of powermill?  If so, how do I choose which session is selected?

 

Any help would be much appreciated! 

0 Likes
Accepted solutions (1)
1,683 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Accepted solution

You can use this to choose the instance

Dim instances As List(Of Object) = PMAutomation.GetListOfPmComObjects()
Dim powermill As New PMAutomation(instances(x))

where "x" ist the number of the instance. The first started instance is "0", the second "1" ... and so on

As far as i know this only works with PowerMill 2015 and above.

 

0 Likes
Message 3 of 7

Anonymous
Not applicable

Thanks for the quick reply!

 

I installed the latest open source code so I could use this. 

 

Now I'm having some trouble getting it to work.

I have 3 powermill 2020 sessions open.  When in debug mode I can see 4 instances, the first one (0) being nothing so I did also try my count starting at 1 with the same result. 

 

Trying to loop thru them but I am getting a Member not found error shown in the pic.

 

Member not found.png

 

What am I missing here?

 

Thanks in advance

 

 

0 Likes
Message 4 of 7

Anonymous
Not applicable

Never mind.  I figured out what I had wrong.

 

This fixed the error, however...

        Dim instances As List(Of Object) = PMAutomation.GetListOfPmComObjects()

        For i As Integer = 0 To instances.Count - 1
            Dim TryME As New PMAutomation(instances(i))
Dim p As Process = Process.GetProcessById(TryME.ProcessId) Next

Every loop of this code returns the same process (p) because the process id is always the same. 

It is always the same powermill project that is selected.  So now I am back to square one.

0 Likes
Message 5 of 7

Anonymous
Not applicable

Here is a small VB.net project to demonstrate how it should work. I've only tested this with PowerMill 2018 but it should work with 2020 too.

 

Message 6 of 7

Anonymous
Not applicable

Your project works perfectly.

 

But for some reason it won't work in my project.

 

I am trying to link each instance of powermill to the windows process ID so I can raise events when powermill closes.

 

When I use your project and loop thru the instances to get all the process IDs, everything works perfectly.  When I copy and paste the same code into my project, the process IDs are not correct.  (See pics)

 

I feel like my issue could be with the API I downloaded from Gethub last week?  I need to do some testing..

 

Thanks for the help!

 

My project - Process IDs not goodMy project - Process IDs not goodYour project - Process IDs goodYour project - Process IDs good

0 Likes
Message 7 of 7

Anonymous
Not applicable

Updated to 1.1.3-alpha package and it now works.

 

Thanks for your help Feuerbowle!