i'm building a DXF generator, and succeeded
the problem i now have that is always targerts the first inventor instance
i've been able to count the number of inventors running but i need to be able to choose the right one
so i made a list box where all the inventors are displayed and it returns the value of the one i selected
the get active object targets the first one, so i need to use something else or make the selected inventor the first one
i'm using inventor 2014 and visual basic 2010 express
any help would be appreciated
Björn
here's my code so far:
InitializeComponent()
Dim myProcesses() AsProcess
myProcesses = Process.GetProcessesByName("Inventor")
Dim invcounter AsInteger = 0
Dim oProcess AsProcess
ForEach oProcess In myProcesses
invcounter = invcounter + 1
Next
SelectCase invcounter
CaseIs = 0
MessageBox.Show("Open Inventor")
Me.Close()
CaseIs = 1
Try
m_InvApp = Marshal.GetActiveObject("Inventor.Application")
Catch ex AsException
MsgBox("Unable to get Inventor")
Return
EndTry
CaseIs > 1
Form2.invsel = Nothing
Me.Visible = False
Dim invpro AsProcess
ForEach invpro In myProcesses
Form2.ListBox1.Items.Add(invpro.MainWindowTitle)
Next
Form2.ShowDialog()
ForEach invpro In myProcesses
If invpro.MainWindowTitle = Form2.invsel.ToString Then
'need to do something here so vb.net targets the right inventor
Try
m_InvApp = Marshal.GetActiveObject("Inventor.Application")
MsgBox(m_InvApp.Caption.ToString)
Catch ex AsException
MsgBox("Unable to get Inventor 2")
Return
EndTry
Exit For
EndIf
Next
Hi Björn,
You cannot make the selected instance the first one - in the sence that GetActiveObject() would return it.
The function always returns the oldest instance of the product. It's nothing Inventor specific - you'll find the same in case of other products as well: AutoCAD, MS Excel, Word, etc
You might be able to get back the object of a specific instance through the Running Objects Table (ROT), but I don't have much experience with that, and looking around it seems you might run into issue with that:
Maybe you could do what you want inside a temporary Inventor instance, or depending what exactly you are trying to export to DXF, from Inventor Apprentice as well.
Cheers,