01-04-2018
09:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
01-04-2018
09:53 AM
I was running into the same problem. Found this post in the search to resolve my issue and thought I would come back with the solution I found through some trial and error.
In the code below I am iterating through sub assemblies to set the color of parts and it is designed to drill down into the sub assembly. I was trying to use "Component.Color" to change the color of sub parts and ran into a similar problem. Strangely, the part would have the new color associated with it when I examine the part, but it would not update the color on the screen.
When I changed the code to use "SetRenderStyle" the color would update correctly. Hope this helps the next person that comes along with this issue.
Dim asmDoc As AssemblyDocument asmDoc = ThisApplication.ActiveDocument ' set color for the standard screws Call SetColor(asmDoc.ComponentDefinition.Occurrences,"R14400","Zinc")SyntaxEditor Code Snippet
Private Sub SetColor(Occurrences As ComponentOccurrences, SearchName As String, Color As String) ' Iterate through each of the occurrences in the collection provided. Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument Dim occ As ComponentOccurrence For Each occ In Occurrences ' Check to see if the object is active. If Component.IsActive(occ.Name) = True Then ' Check to see if the part number from the iProperties matches the search name. If iProperties.Value(occ.Name, "Project", "Part Number") = SearchName Then ' Set the part color 'Component.Color(occ.Name) = Color Call occ.SetRenderStyle(kOverrideRenderStyle,oAsmDoc.RenderStyles.Item(Color)) End If If occ.DefinitionDocumentType = kAssemblyDocumentObject Then If Component.IsActive(occ.Name) = True Then Call SetColor(occ.SubOccurrences, SearchName, Color) End If End If End If Next End Sub