How to speed up coloring faces?

How to speed up coloring faces?

abdullah_elq
Advocate Advocate
331 Views
2 Replies
Message 1 of 3

How to speed up coloring faces?

abdullah_elq
Advocate
Advocate

Hi,

 

Is there a way for Inventor to quickly apply assets (colors) to faces? The best I can seem to get is 68 faces colored per second. I was hoping that there would be a way to apply the appearances to all the faces in the background, then have Inventor render them all later.

 

Neither of these seems to make the process any faster:

	ThisApplication.ScreenUpdating = False 
	ThisApplication.UserInterfaceManager.UserInteractionDisabled = True

 

Here is the code that I am using. It should work on any part file:

Sub Main()
	Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
	Dim oSB As SurfaceBody = oCompDef.SurfaceBodies(1)
	Dim oFaces As Faces = oSB.Faces
	
	Dim MyShinyRed As Asset = CreateSimpleColorAppearance(oPartDoc)
	
	Dim stopWatch As New Stopwatch()
	stopWatch.Start()
	
''	How can I speed this up?
''	-----------------------------------------------------
	For Each oFace As Face In oFaces
		oFace.Appearance = MyShinyRed
	Next
''	-----------------------------------------------------
	
	stopWatch.Stop()
	Dim ts As TimeSpan = stopWatch.Elapsed
	Dim elapsedTime As String = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)
	MessageBox.Show("RunTime: " & elapsedTime & " over " & oSB.Faces.Count & " faces", Round(oSB.Faces.Count/ts.Seconds) & " Faces/Second")
	
End Sub
Function CreateSimpleColorAppearance(doc As Document) As Asset

    Dim docAssets As Assets = doc.Assets
	Dim appearance As Asset
    
	Try
		appearance = docAssets.Item("My Shiny Red Color")
	Catch
	    ' Create a new appearance asset.
	    appearance = docAssets.Add(kAssetTypeAppearance, "Generic", "MyShinyRed", "My Shiny Red Color")
	    
	    Dim tobjs As TransientObjects = ThisApplication.TransientObjects
	
	    Dim color As ColorAssetValue = appearance.Item("generic_diffuse")
	    color.Value = tobjs.CreateColor(255, 15, 15)
	End Try
	
	CreateSimpleColorAppearance = appearance
End Function
0 Likes
332 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor

You might want to have a look at the article "Improving Your Program’s Performance". I think you might have some success with transactions. (see the bottom of the article)

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.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 3

abdullah_elq
Advocate
Advocate
Thank you. Wrapping the loop in a global transaction did help speed up the program, but not by much.

Do you have any other ideas?
0 Likes