VB.NET - Check if Inventor is open question

VB.NET - Check if Inventor is open question

Anonymous
Not applicable
700 Views
3 Replies
Message 1 of 4

VB.NET - Check if Inventor is open question

Anonymous
Not applicable
In the code below, I want to check if Inventor is open, if so I will discern
if the part is a part, or referenced from an assembly. Finally, I will do a
save-as to a new filename.

Right now, oApp is nothing, wvwn when I have Inventor open. I believe this
is the problem. In .NET, I cannot use things like ThisApplication or
ThisDocument.

I do have references to Inventor and InventorApprentice in my solution
explorer for VB.NET. Because I am planning on running this code while in an
editable drawing, I believe the Inventor reference is the ont that applies.

Thanks in advance for any answers that can be provided.



Steve Anderson



' Check if Inventor is open, if so define file type in use.

Dim oApp As Inventor.Application

Dim oDoc As Inventor.Document = oApp.ActiveEditObject

oApp.ActiveDocument.Activate()

If oApp.ActiveDocumentType.kPartDocumentObject = True Then

Dim oPart As Inventor.Document = oApp.ActiveDocument

ElseIf oApp.ActiveDocumentType.kAssemblyDocumentObject = True Then

Dim oPart As Inventor.Document = oApp.ActiveEditObject

End If
0 Likes
701 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
So far, I've come up with this:

' Check if Inventor is open, if so define file type in use.

Dim oApp As Inventor.Application = GetObject(, "Inventor.Application")

Dim oDoc As Inventor.Document = oApp.ActiveEditObject

Dim oPart As Inventor.Document

If oApp.ActiveDocumentType.kPartDocumentObject = True Then

oPart = oDoc.ActiveDocument

ElseIf oApp.ActiveDocumentType.kAssemblyDocumentObject = True Then

oPart = oDoc.ActiveEditObject

End If

oPart.SaveAs(PartToSave, False)

"Steve Anderson" wrote in message
news:5013098@discussion.autodesk.com...
In the code below, I want to check if Inventor is open, if so I will discern
if the part is a part, or referenced from an assembly. Finally, I will do a
save-as to a new filename.

Right now, oApp is nothing, wvwn when I have Inventor open. I believe this
is the problem. In .NET, I cannot use things like ThisApplication or
ThisDocument.

I do have references to Inventor and InventorApprentice in my solution
explorer for VB.NET. Because I am planning on running this code while in an
editable drawing, I believe the Inventor reference is the ont that applies.

Thanks in advance for any answers that can be provided.



Steve Anderson



' Check if Inventor is open, if so define file type in use.

Dim oApp As Inventor.Application

Dim oDoc As Inventor.Document = oApp.ActiveEditObject

oApp.ActiveDocument.Activate()

If oApp.ActiveDocumentType.kPartDocumentObject = True Then

Dim oPart As Inventor.Document = oApp.ActiveDocument

ElseIf oApp.ActiveDocumentType.kAssemblyDocumentObject = True Then

Dim oPart As Inventor.Document = oApp.ActiveEditObject

End If
0 Likes
Message 3 of 4

Anonymous
Not applicable
I was able to answer my own last question. It seems now the part is not
being defined (oPart). I wonder how this works if I have multiple sessions
runnng. Is there a way to count the sessions? If one session is running,
the program could run - otherwise it would need to be halted. And, how do I
define the oPart variable?

Thanks in advance

Steve Anderson

' Check if Inventor is open, if so define file type in use.

Dim oApp As Inventor.Application = GetObject(, "Inventor.Application")

Dim oDoc As Inventor.Document = oApp.ActiveEditObject

Dim oPart As Inventor.Document

If oApp.ActiveDocumentType.kPartDocumentObject = True Then

oPart = oDoc.ActiveDocument

ElseIf oApp.ActiveDocumentType.kAssemblyDocumentObject = True Then

oPart = oDoc.ActiveEditObject

End If

oPart.SaveAs(PartToSave, False)



"Steve Anderson" wrote in message
news:5013098@discussion.autodesk.com...
In the code below, I want to check if Inventor is open, if so I will discern
if the part is a part, or referenced from an assembly. Finally, I will do a
save-as to a new filename.

Right now, oApp is nothing, wvwn when I have Inventor open. I believe this
is the problem. In .NET, I cannot use things like ThisApplication or
ThisDocument.

I do have references to Inventor and InventorApprentice in my solution
explorer for VB.NET. Because I am planning on running this code while in an
editable drawing, I believe the Inventor reference is the ont that applies.

Thanks in advance for any answers that can be provided.



Steve Anderson



' Check if Inventor is open, if so define file type in use.

Dim oApp As Inventor.Application

Dim oDoc As Inventor.Document = oApp.ActiveEditObject

oApp.ActiveDocument.Activate()

If oApp.ActiveDocumentType.kPartDocumentObject = True Then

Dim oPart As Inventor.Document = oApp.ActiveDocument

ElseIf oApp.ActiveDocumentType.kAssemblyDocumentObject = True Then

Dim oPart As Inventor.Document = oApp.ActiveEditObject

End If
0 Likes
Message 4 of 4

Anonymous
Not applicable
Steve,

Read your VBA tutorials, you MUST remember to Set any object otherwise you have an error. So your code would look like

Public Sub FooBar()

' get the app
Dim oApp As Inventor.Application
Set oApp = GetObject(, "Inventor.Application")
If oApp is Nothing Then Exit Sub

' you can also get the app like this (from inside a IV macro)
' Set oApp = ThisApplication

Dim oPart As Inventor.PartDocument
Dim oAsm As Inventor.AssemblyDocument

If oApp.ActiveDocumentType.kPartDocumentObject = True Then

Set oPart = oDoc.ActiveDocument

ElseIf oApp.ActiveDocumentType.kAssemblyDocumentObject = True Then

Set oAsm = oDoc.ActiveDocument

End If

End Sub
0 Likes