Message 1 of 3
How to speed up coloring faces?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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