- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am seeing a huge difference in the performance between VBA and .NET.
A code that executes in under a second in VBA takes more than 65 seconds in .NET![]()
VBA: (<0.5 sec)
Sub testperformance()
Dim ElapsedTime As Long: ElapsedTime = Timer
Dim oPartDoc As PartDocument: Set oPartDoc = ThisApplication.ActiveDocument
Dim oPartDef As PartComponentDefinition: Set oPartDef = oPartDoc.ComponentDefinition
Dim nCylinders As Integer
Dim oSurfBody As SurfaceBody
Dim oFace As Face
For Each oSurfBody In oPartDef.SurfaceBodies
For Each oFace In oSurfBody.faces
If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
nCylinders = nCylinders + 1
End If
Next
Next
MsgBox Timer - ElapsedTime
End Sub
.NET: (> 65 sec)
Sub testperformance()
Dim ThisApplication As Application = GetObject(, "Inventor.application")
Dim start_time As DateTime = Now
Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition
Dim nCylinders As Int16 = 0
For Each oSurfBody As SurfaceBody In oPartDef.SurfaceBodies
For Each oFace As Face In oSurfBody.Faces
If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
nCylinders += 1
End If
Next
Next
Dim elapsed_time As TimeSpan = Now.Subtract(start_time)
MsgBox(elapsed_time.TotalSeconds)
End Sub
End Class
Code is run on a complex part file with approx 10.000 faces.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
One thing that significantly impacts performance is if your program is running inside Inventor or not. When your program is running within Inventor’s process it’s referred to as in-process. When your program is running in another process it referred to as out-of-process. Add-ins and VBA macros, run in-process. Exe’s and programs that run from within other products all run in a process outside of Inventor.
i expect that your .net code is run out of process. If so try to make a addin and retry it.
this page is a great refrence for performance. (especialy have a look at the chapter Running In-Process vs. Out-of-Process)
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Yes, I realize that's the issue.
It just easier to debug, but I will move it to an addin.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I often use a UnitTest to start and debug addin functions out of process. that makes debugging almost as easy as a standalone application (but it's slow) but for the end users there is the speed of an addin.
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com