Inventor Customization

Reply
Active Member
baldur
Posts: 9
Registered: ‎10-19-2006
Message 1 of 6 (419 Views)

Insert part in assembly

419 Views, 5 Replies
10-19-2006 01:52 AM
I am trying to build an assembly from a part using VBA in Inventor 10.0.
My part contains a simple cube. But i think my code is running pretty slow. If I for example try to insert my part 1600 times it will take roughly 3 minutes.

When I insert a part I call a subroutine called "InsertMyPart". In that routine I read in my part from the harddrive and place it in the assembly. So I end up reading the part from the harddrive 1600 times. Does anyone know if this process in someway can be optimized.

I have attached my code


Best regards

Jesper Hansen, Denmark
*Brian Ekins \(Autodesk\)
Message 2 of 6 (419 Views)

Re: Insert part in assembly

10-19-2006 09:52 AM in reply to: baldur
I did some testing and didn't see the times that you reported. I don't have
a fast computer either. Running your code with a simple part I was able to
complete the assembly in about 45 seconds. This was without any changes to
your program. The particular issue that you were worried about with
Inventor reading the file from disk each time is not really a problem.
Inventor is smart enough to see that the filename you specify already exists
in the assembly and just places another instance of that part. It doesn't
re-read it from the disk. When placing a part into an assembly you can be
explicit in specifying a part that has already been loaded by using the
AddByComponentDefinition method. I modified your code to do this and there
isn't any appreciable difference. I don't know what would account for the
difference in times between my tests and yours.

One way to get some performance improvement is to implement this as an
Add-In within a change processor. I did something to roughly simulate this
and the time got down to less than 30 seconds.

-Brian
Active Member
baldur
Posts: 9
Registered: ‎10-19-2006
Message 3 of 6 (419 Views)

Re: Insert part in assembly

10-19-2006 12:31 PM in reply to: baldur
How can I implement this as an Add-in? Do you know a paper describing this?

//Jesper
*Brian Ekins \(Autodesk\)
Message 4 of 6 (419 Views)

Re: Insert part in assembly

10-19-2006 01:49 PM in reply to: baldur
There is a topic on the change processor concept in the programming help.
I've also attached a VB 6 project I wrote a while ago that demonstrates an
implementation of the change processor.

There is another way to get a similar boost in speed. A change processor
should still be slightly faster, but not by much. I was hesitant to mention
this since it's a hidden, unsupported API. The reason that it's hidden is
that it's easy to get environment into a bad state if you don't use this
correctly. This uses transactions. You wrap the set of calls with a
transaction. Instead of using the standard
TransactionManager.CreateTransaction you use the CreateGlobalTransaction
instead. The risk in using this is if you don't do Transaction.End for the
global transaction. This leaves Inventor in a strange state and can lead to
problems later. Here's a version of your program that uses this. Notice
that uses error handling to make sure the transaction is closed even if an
error occurrs. You also want to be careful during development when you're
debugging your program. It's very easy then to have started the transaction
and then stop the execution of the program before the transaction is closed.
Closing and reopening Inventor will reset everything.

Private m_Doc As AssemblyDocument
Private m_TG As TransientGeometry
Private m_CompDef As AssemblyComponentDefinition
Private m_OccMarker As ComponentOccurrence
Private m_oMatrix As Matrix

Public Sub TestInsertPart()
On Error GoTo ErrorFound

Dim i As Integer
Dim j As Integer
Call InitVariables

Dim oTrans As Transaction
Set oTrans =
ThisApplication.TransactionManager.StartGlobalTransaction(m_Doc, "Time
Test")
For i = 0 To 40
For j = 0 To 40
Call InsertMyPart(i * 5, j * 5, 0)
Next
Next
oTrans.End

Exit Sub
ErrorFound:
If Not oTrans Is Nothing Then
oTrans.End
End If
End Sub

Private Sub InsertMyPart(ByVal x As Integer, ByVal y As Integer, ByVal z As
Integer)
Call m_oMatrix.SetTranslation(m_TG.CreateVector(x, y, z), True)
Set m_OccMarker = m_CompDef.Occurrences.Add("C:\Temp\PartR10.ipt",
m_oMatrix)
End Sub

Private Sub InitVariables()
'set a reference to the active document
Set m_Doc = ThisApplication.ActiveDocument

'set a reference to the transient geometry object
Set m_TG = ThisApplication.TransientGeometry

'set a reference to the assembly component definintion
Set m_CompDef = m_Doc.ComponentDefinition

'create an identity matrix (rotation and translation values = 0)
Set m_oMatrix = m_TG.CreateMatrix
End Sub
Active Member
baldur
Posts: 9
Registered: ‎10-19-2006
Message 5 of 6 (419 Views)

Re: Insert part in assembly

10-19-2006 09:21 PM in reply to: baldur
But there is one thing I think is a little strange. When I run TestInsertPart() once i get a time about 25 sec, when I run it twice I get a time about 95 sec and when I run it thrice I get a timne about 235 sec.
In the last test I have expected a time about 75 sec :smileyvery-happy:

I have hoped to have a linear connection between the number of parts to insert and the output time. Do you have an explenation why this is not true
Test 1:
public sub Test1()
call TestInsertPart()
end sub

Test 2:
public sub Test1()
call TestInsertPart()
call TestInsertPart()
end sub

Test3:
public sub Test1()
call TestInsertPart()
call TestInsertPart()
call TestInsertPart()
end sub

//Jesper
*Brian Ekins \(Autodesk\)
Message 6 of 6 (419 Views)

Re: Insert part in assembly

10-20-2006 10:17 AM in reply to: baldur
Are you placing the parts into the same assembly? I suspect so and that's
what's causing the slow down. As the assembly gets larger, the placement of
each part takes longer. This is something that needs to be investigated by
the Inventor team. I don't know of any technique beyond what I've already
suggested to improve the time.
--
Brian Ekins
Autodesk Inventor API

wrote in message news:5368516@discussion.autodesk.com...
But there is one thing I think is a little strange. When I run
TestInsertPart() once i get a time about 25 sec, when I run it twice I get a
time about 95 sec and when I run it thrice I get a timne about 235 sec.
In the last test I have expected a time about 75 sec :smileyvery-happy:

I have hoped to have a linear connection between the number of parts to
insert and the output time. Do you have an explenation why this is not true
Test 1:
public sub Test1()
call TestInsertPart()
end sub

Test 2:
public sub Test1()
call TestInsertPart()
call TestInsertPart()
end sub

Test3:
public sub Test1()
call TestInsertPart()
call TestInsertPart()
call TestInsertPart()
end sub

//Jesper
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.