Opening file

Opening file

naresh_kalyan
Advocate Advocate
346 Views
3 Replies
Message 1 of 4

Opening file

naresh_kalyan
Advocate
Advocate
Hi all,
Is it possible to open an existing ipt file thru VB.
I tried somehow, But I am not getting.

Public Class Form1
Dim oApp As Object
Dim oDoc As Object


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

oApp = CreateObject("Inventor.Application")
oDoc = oApp.Documents.Open("d:\1.ipt")


End Sub

End Class
0 Likes
347 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Hi,
Is this a VB or VB.NET, plz clarify.

Is there is any way to work on Inventor other than VBA.
I think VBA is a Inbuilt Application with Inventor. But, I would like to work on Autodesk Inventor, without opening it.

I'm having one Template model which is a simple Extrision.
With this each time I have to create so many Parts. They may vary in Lengh, Width or Thk.
So, I have to open the file and change the existing parameters and SAVEAS a differnet file with different location.

Is this possible ?
For this task I feel there is no need of Skeleton Modeling ?

If I am wrong Plz correct me.

Regards
Veen
0 Likes
Message 3 of 4

Anonymous
Not applicable
I suspect it is actually working it's just that you're not seeing the
results. This is because when you start an application using the
CreateObject function it is started invisibly. Try adding the following
line to your code.

oApp.Visible = True

Another suggestion is to reference the Inventor library into your project.
This will make your code more efficient and will also allow you to take
advantage of Visual Studio's Intellisense while you're coding. One other
thing is that you may want to use a combination of GetObject and
CreateObject in your code. You can first use GetObject to see if Inventor
is already running and use it if it is and then if that fails use
CreateObject to start Inventor.
--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 4 of 4

Anonymous
Not applicable
You can access Inventor's API using languages beside's VBA. Below is some
sample VB.Net code that does what you asked about. It assumes that you've
referenced the Inventor library into your project. This is just a simple
example but hopefully you can see that it demonstrates the basic concepts
needed and is enough for you to get started.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
' Connect to Inventor.
Dim inventorApp As Inventor.Application
Try
' Attempt to connect to a running instance of Inventor.
inventorApp = GetObject(, "Inventor.Application")
Catch ex As Exception
' Failed to connect to a running instance so start Inventor.
Try
inventorApp = CreateObject("Inventor.Application")
Catch ex2 As Exception
MsgBox("Failed to connect to Inventor.")
Exit Sub
End Try

' Make Inventor visible.
inventorApp.Visible = True
End Try

' Open the base document.
Dim baseDoc As Inventor.PartDocument
baseDoc = inventorApp.Documents.Open("C:\Temp\BasePart.ipt", True)

' Get the Parameters collection object.
Dim params As Inventor.Parameters =
baseDoc.ComponentDefinition.Parameters

' Change some parameter values.
' This uses the Value property which is in database units
' (lengths are cm and angles are radians).
params.Item("Length").Value = 3

' This uses the Expression property which is the equivalent of changing
the
' equation of a parameter in the Parameters dialog. It is set using a
string
' and can contain complete expressions, unit definitions, and references
to
' other parameters, i.e. "4 in + d0".
params.Item("Height").Expression = "1.5 in"

' Force the part to update.
baseDoc.Update()

' Save the part with a new name.
baseDoc.SaveAs("C:\Temp\New1.ipt", True)

' Change the parameters to some new values.
params.Item("Length").Value = 4
params.Item("Height").Value = 2

' Update and save the part.
baseDoc.Update()
baseDoc.SaveAs("C:\Temp\New2.ipt", True)

' Close the original file without saving any changes.
baseDoc.Close(True)
End Sub
--
Brian Ekins
Autodesk Inventor API

wrote in message news:5241222@discussion.autodesk.com...
Hi,
Is this a VB or VB.NET, plz clarify.

Is there is any way to work on Inventor other than VBA.
I think VBA is a Inbuilt Application with Inventor. But, I would like to
work on Autodesk Inventor, without opening it.

I'm having one Template model which is a simple Extrision.
With this each time I have to create so many Parts. They may vary in Lengh,
Width or Thk.
So, I have to open the file and change the existing parameters and SAVEAS a
differnet file with different location.

Is this possible ?
For this task I feel there is no need of Skeleton Modeling ?

If I am wrong Plz correct me.

Regards
Veen
0 Likes