<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to auto change part color for a big assembly with sub-assemblies in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12948083#M170456</link>
    <description>&lt;P&gt;A quick update to the previous example, this one only colors components named in a list&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Imports System.ComponentModel
AddReference "System.drawing"
Imports System.Windows.Forms
Imports System.Drawing
Sub Main

	Dim myList As New List(Of String)(New String() {"Foo", "Foo Too" }) 'list with part names

	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	Dim oColor As Asset = GetColor
	Call TraverseAssembly(oOccs, oColor, myList)

End Sub

Sub TraverseAssembly(oOccs As ComponentOccurrences, oColor As Asset, myList As List(Of String))

	Dim oOcc As ComponentOccurrence
	For Each oOcc In oOccs
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			Call TraverseAssembly(oOcc.SubOccurrences, oColor, myList)
		ElseIf oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
			If myList.Contains(oOcc.Name) Then oOcc.Appearance = oColor
		End If
	Next
End Sub


Function GetColor() As Asset

	Dim oClDlg As New System.Windows.Forms.ColorDialog
	Dim oColor As System.drawing.Color
	If oClDlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
		oColor = oClDlg.Color
	End If

	oName = "Paint Color"
	Dim oAppearance As Asset

	Try 	'create new appearance 
		oAppearance = ThisDoc.Document.Assets.Add(AssetTypeEnum.kAssetTypeAppearance, 
			"Generic", "Appearances", oName)
	Catch
		oAppearance = ThisDoc.Document.Assets.item(oName)
	End Try

	'set colors
	Dim oNewColor As ColorAssetValue
	oNewColor = oAppearance.Item("generic_diffuse")
	oNewColor.Value = ThisApplication.TransientObjects.CreateColor(oColor.R, oColor.G, oColor.B)

	Return oAppearance

End Function

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Aug 2024 04:17:45 GMT</pubDate>
    <dc:creator>Curtis_Waguespack</dc:creator>
    <dc:date>2024-08-09T04:17:45Z</dc:date>
    <item>
      <title>How to auto change part color for a big assembly with sub-assemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12947968#M170451</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to write an iLogic code that will do the following actions:&lt;/P&gt;&lt;P&gt;1. I will give a list of part names as input&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. The code will parse through a big assembly file (that contains sub-assemblies) to find the parts, and color all of them to a certain color&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a working version for a code that works for a simple assembly where there's no sub-assembly:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;' iLogic rule To color parts In an assembly Using Partial part names
 
' List of part names (or partial names) to color
Dim partsToColor As String() = {"SAG3YZM5" } ' Add other part names as needed
Dim partsToColorCount As Integer = partsToColor.Length ' Count the number of elements in list so we can set the loop size
Dim colorStyleName As String = "Magenta" ' Replace with desired color style name
 
' Loop through each component in the assembly
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument
 
Dim oCompOccs As ComponentOccurrences
oCompOccs = oAssyDoc.ComponentDefinition.Occurrences
 
For Each oOcc As ComponentOccurrence In oCompOccs
	' Check if the component name contains any of the specified part names
	For Index = 1 To partsToColorCount
		If oOcc.Name.Contains(partsToColor(Index - 1)) Then 'Subtract 1 since the index of the first element in the array is 0
			' Try to set the color of the component
			Try
				Component.Color(oOcc.Name) = colorStyleName
				MessageBox.Show("Colored component: " &amp;amp; oOcc.Name)
			Catch
				MessageBox.Show("Error setting color for component: " &amp;amp; oOcc.Name)
			End Try
		End If
	Next
Next&lt;/LI-CODE&gt;&lt;P&gt;However, when I try to expand this to bigger assemblies, I couldn't get the code to work:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;' iLogic rule To color parts In an assembly Using Partial part names

Sub Main
	' List of part names (or partial names) to color
	Dim partsToColor As String() = {"SAG3YZM5" } ' Add other part names as needed
	Dim partsToColorCount As Integer = partsToColor.Length ' Count the number of elements in list so we can set the loop size
	Dim colorStyleName As String = "Magenta" ' Replace with desired color style name

	' Loop through each component in the assembly
	Dim oAssyDoc As AssemblyDocument
	oAssyDoc = ThisApplication.ActiveDocument
	oAssyDocType = oAssyDoc.DocumentType

	If oAssyDocType &amp;lt;&amp;gt; DocumentTypeEnum.kAssemblyDocumentObject Then
		MessageBox.Show("This process only runs on assemblies.")
		Exit Sub
	Else
		Call ColorAssembly
	End If

	Dim oCompOccs As ComponentOccurrences
	oCompOccs = oAssyDoc.ComponentDefinition.Occurrences

End Sub

Sub ColorAssembly(AssyDocument As AssemblyDocument, FileList())
	For Each oOcc As ComponentOccurrence In oCompOccs

		If oOcc Is On FileList() Then
			Call ColorPart
		ElseIf oOcc = Assembly
			Call ColorAssembly()
		End If

	Next

End Sub

Sub ColorPart(OccurenceInAssy As Occurrence)

	' Loop through each component in the assembly
	Dim oAssyDoc As AssemblyDocument
	oAssyDoc = ThisApplication.ActiveDocument
	 
	Dim oCompOccs As ComponentOccurrences
	oCompOccs = oAssyDoc.ComponentDefinition.Occurrences
	 
	For Each oOcc As ComponentOccurrence In oCompOccs
		' Check if the component name contains any of the specified part names
		For Index = 1 To partsToColorCount
			If oOcc.Name.Contains(partsToColor(Index - 1)) Then 'Subtract 1 since the index of the first element in the array is 0
				' Try to set the color of the component
				Try
					Component.Color(oOcc.Name) = colorStyleName
					MessageBox.Show("Colored component: " &amp;amp; oOcc.Name)
				Catch
					MessageBox.Show("Error setting color for component: " &amp;amp; oOcc.Name)
				End Try
			End If
		Next
	Next

End Sub&lt;/LI-CODE&gt;&lt;P&gt;Here, the code will:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Check if an occurrence is a part or assembly&lt;/P&gt;&lt;P&gt;2. If it's a part, then execute the ColorPart subroutine; if it's an assembly, call ColorAssembly subroutine, where it goes into the assembly and look for the parts.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I couldn't get the code to work, and I'm fairly new to VBA. Could anyone help me with my issue?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Aug 2024 20:59:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12947968#M170451</guid>
      <dc:creator>jeyuan</dc:creator>
      <dc:date>2024-08-08T20:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to auto change part color for a big assembly with sub-assemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12948058#M170455</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/15897812"&gt;@jeyuan&lt;/a&gt;,&amp;nbsp;here is an ilogic example that changes the color of all the parts in all sub assemblies, but only applies the colors at the top level assembly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;meaning if you open the parts their color are not changed at that level, and if you open the subassemblies the part colors are not changed at that level... but they all get the color override in the top level assembly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;( p.s. thanks to &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/925138"&gt;@Stakin&lt;/a&gt;&amp;nbsp;who supplied the color picker example recently)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Imports System.ComponentModel
AddReference "System.drawing"
Imports System.Windows.Forms
Imports System.Drawing
Sub Main

	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	Dim oColor As Asset = GetColor
	Call TraverseAssembly(oOccs, oColor)

End Sub

Sub TraverseAssembly(oOccs As ComponentOccurrences, oColor As Asset)

	Dim oOcc As ComponentOccurrence
	For Each oOcc In oOccs
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			Call TraverseAssembly(oOcc.SubOccurrences, oColor)
		ElseIf oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
			oOcc.Appearance = oColor
		End If
	Next
End Sub


Function GetColor() As Asset

	Dim oClDlg As New System.Windows.Forms.ColorDialog
	Dim oColor As System.drawing.Color
	If oClDlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
		oColor = oClDlg.Color
	End If

	oName = "Paint Color"
	Dim oAppearance As Asset

	Try 	'create new appearance 
		oAppearance = ThisDoc.Document.Assets.Add(AssetTypeEnum.kAssetTypeAppearance, "Generic", "Appearances", oName)
	Catch
		oAppearance = ThisDoc.Document.Assets.item(oName)
	End Try

	'set colors
	Dim oNewColor As ColorAssetValue
	oNewColor = oAppearance.Item("generic_diffuse")
	oNewColor.Value = ThisApplication.TransientObjects.CreateColor(oColor.R, oColor.G, oColor.B)

	Return oAppearance

End Function

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2024 04:18:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12948058#M170455</guid>
      <dc:creator>Curtis_Waguespack</dc:creator>
      <dc:date>2024-08-09T04:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to auto change part color for a big assembly with sub-assemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12948083#M170456</link>
      <description>&lt;P&gt;A quick update to the previous example, this one only colors components named in a list&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Imports System.ComponentModel
AddReference "System.drawing"
Imports System.Windows.Forms
Imports System.Drawing
Sub Main

	Dim myList As New List(Of String)(New String() {"Foo", "Foo Too" }) 'list with part names

	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	Dim oColor As Asset = GetColor
	Call TraverseAssembly(oOccs, oColor, myList)

End Sub

Sub TraverseAssembly(oOccs As ComponentOccurrences, oColor As Asset, myList As List(Of String))

	Dim oOcc As ComponentOccurrence
	For Each oOcc In oOccs
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			Call TraverseAssembly(oOcc.SubOccurrences, oColor, myList)
		ElseIf oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
			If myList.Contains(oOcc.Name) Then oOcc.Appearance = oColor
		End If
	Next
End Sub


Function GetColor() As Asset

	Dim oClDlg As New System.Windows.Forms.ColorDialog
	Dim oColor As System.drawing.Color
	If oClDlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
		oColor = oClDlg.Color
	End If

	oName = "Paint Color"
	Dim oAppearance As Asset

	Try 	'create new appearance 
		oAppearance = ThisDoc.Document.Assets.Add(AssetTypeEnum.kAssetTypeAppearance, 
			"Generic", "Appearances", oName)
	Catch
		oAppearance = ThisDoc.Document.Assets.item(oName)
	End Try

	'set colors
	Dim oNewColor As ColorAssetValue
	oNewColor = oAppearance.Item("generic_diffuse")
	oNewColor.Value = ThisApplication.TransientObjects.CreateColor(oColor.R, oColor.G, oColor.B)

	Return oAppearance

End Function

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2024 04:17:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12948083#M170456</guid>
      <dc:creator>Curtis_Waguespack</dc:creator>
      <dc:date>2024-08-09T04:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to auto change part color for a big assembly with sub-assemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12956303#M170632</link>
      <description>&lt;P&gt;Hi Curtis,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much! The code works very well. Now I'm trying to improve the code where the user does not need to supply a list of part names as strings separated by comma, because usually an assembly has too many parts that needs to be colored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm adding the functionality where instead of MyList, the code will parse through the assembly, read the iProperty information, and color the part where "CompliantWithMachine" = No.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The "Compliant with Machine" is a custom iProperty, the type is Yes or No. I'm trying to make the code do three things:&lt;/P&gt;&lt;P&gt;1. If&amp;nbsp;Compliant with Machine = No, color the part&lt;/P&gt;&lt;P&gt;2. If&amp;nbsp;Compliant with Machine = Yes, don't color the part&lt;/P&gt;&lt;P&gt;3. If&amp;nbsp;Compliant with Machine doesn't exist for a part, don't color the part.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;My current code is below:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Imports System.ComponentModel
AddReference "System.drawing"
Imports System.Windows.Forms
Imports System.Drawing
Sub Main
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	Dim oColor As Asset = GetColor()

	' Ensure that a color has been selected
	If oColor Is Nothing Then
		MessageBox.Show("No color selected. Exiting the script.")
		Exit Sub
	End If

	' Traverse the assembly and color parts where CompliantWithMachine is False
	Call TraverseAssembly(oOccs, oColor)

	' Show completion message
	MessageBox.Show("Coloring successfully completed.")
End Sub

Sub TraverseAssembly(oOccs As ComponentOccurrences, oColor As Asset)
	Dim oOcc As ComponentOccurrence
	For Each oOcc In oOccs
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			Call TraverseAssembly(oOcc.SubOccurrences, oColor)
		ElseIf oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
			Try
				' Get the "CompliantWithMachine" property value as a Boolean
				Dim CompliantWithMachine As Boolean = False ' Default to False in case of any issues
				CompliantWithMachine = oOcc.Definition.PropertySets("Inventor User Defined Properties")("CompliantWithMachine").Value
				' Check the property value
				If Not CompliantWithMachine Then
					' If property = False (equivalent to "No"), color the part
					oOcc.Appearance = oColor
				Else

				End If

			Catch
				' If the property is missing or an error occurs, do not color the part
			End Try
		End If
	Next
End Sub

Function GetColor() As Asset
	Dim oClDlg As New System.Windows.Forms.ColorDialog
	Dim oColor As System.Drawing.Color
	If oClDlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
		oColor = oClDlg.Color
	Else
		Return Nothing
	End If

	Dim oName As String = "Paint Color"
	Dim oAppearance As Asset

	Try 'create new appearance 
		oAppearance = ThisDoc.Document.Assets.Add(AssetTypeEnum.kAssetTypeAppearance,
		"Generic", "Appearances", oName)
	Catch
		oAppearance = ThisDoc.Document.Assets.Item(oName)
	End Try

	'set colors
	Dim oNewColor As ColorAssetValue
	oNewColor = oAppearance.Item("generic_diffuse")
	oNewColor.Value = ThisApplication.TransientObjects.CreateColor(oColor.R, oColor.G, oColor.B)

	Return oAppearance
End Function&lt;/LI-CODE&gt;&lt;P&gt;When I run the code, no parts are colored.&amp;nbsp;&lt;BR /&gt;When I add debugging messages, it shows that all parts are identified as the property doesn't exist, which is not true.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Could you help me with this issue? Thank you so much!&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 16:05:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12956303#M170632</guid>
      <dc:creator>jeyuan</dc:creator>
      <dc:date>2024-08-13T16:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to auto change part color for a big assembly with sub-assemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12956388#M170635</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/15897812"&gt;@jeyuan&lt;/a&gt;&amp;nbsp;, give this version a try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Imports System.ComponentModel
AddReference "System.drawing"
Imports System.Windows.Forms
Imports System.Drawing
Sub Main
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	Dim oColor As Asset = GetColor()

	' Ensure that a color has been selected
	If oColor Is Nothing Then
		MessageBox.Show("No color selected. Exiting the script.")
		Exit Sub
	End If

	' Traverse the assembly and color parts where CompliantWithMachine is False
	Call TraverseAssembly(oOccs, oColor)

	' Show completion message
	MessageBox.Show("Coloring successfully completed.")
End Sub

Sub TraverseAssembly(oOccs As ComponentOccurrences, oColor As Asset)
	Dim oOcc As ComponentOccurrence
	For Each oOcc In oOccs
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			Call TraverseAssembly(oOcc.SubOccurrences, oColor)
		ElseIf oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then

			'set default 
			isCompliant = True

			Try
				isCompliant = iProperties.Value(oOcc.Name, "Custom", "CompliantWithMachine")
			Catch
				' If the property is missing or an error occurs, do not color the part
			End Try
			
			If isCompliant = False Then oOcc.Appearance = oColor

		End If
	Next
End Sub

Function GetColor() As Asset
	Dim oClDlg As New System.Windows.Forms.ColorDialog
	Dim oColor As System.Drawing.Color
	If oClDlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
		oColor = oClDlg.Color
	Else
		Return Nothing
	End If

	Dim oName As String = "Paint Color"
	Dim oAppearance As Asset

	Try 'create new appearance 
		oAppearance = ThisDoc.Document.Assets.Add(AssetTypeEnum.kAssetTypeAppearance,
		"Generic", "Appearances", oName)
	Catch
		oAppearance = ThisDoc.Document.Assets.Item(oName)
	End Try

	'set colors
	Dim oNewColor As ColorAssetValue
	oNewColor = oAppearance.Item("generic_diffuse")
	oNewColor.Value = ThisApplication.TransientObjects.CreateColor(oColor.R, oColor.G, oColor.B)

	Return oAppearance
End Function&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 16:59:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12956388#M170635</guid>
      <dc:creator>Curtis_Waguespack</dc:creator>
      <dc:date>2024-08-13T16:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to auto change part color for a big assembly with sub-assemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12956399#M170636</link>
      <description>&lt;P&gt;Also, here is a version that uses a preset/hardcoded color, in case that is preferred over the color picker.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just change the hardcoded R, G, B values in bold to change the color&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can look up RGB values for colors here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.rapidtables.com/web/color/RGB_Color.html" target="_blank" rel="noopener"&gt;https://www.rapidtables.com/web/color/RGB_Color.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;Sub&lt;/SPAN&gt; &lt;SPAN&gt;Main&lt;/SPAN&gt;
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oADoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;AssemblyDocument&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;ActiveDocument&lt;/SPAN&gt;
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oOccs&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ComponentOccurrences&lt;/SPAN&gt; = &lt;SPAN&gt;oADoc&lt;/SPAN&gt;.&lt;SPAN&gt;ComponentDefinition&lt;/SPAN&gt;.&lt;SPAN&gt;Occurrences&lt;/SPAN&gt;
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oColor&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Asset&lt;/SPAN&gt; = &lt;SPAN&gt;GetColor&lt;/SPAN&gt;()

	&lt;SPAN&gt;' Ensure that a color has been selected&lt;/SPAN&gt;
	&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oColor&lt;/SPAN&gt; &lt;SPAN&gt;Is&lt;/SPAN&gt; &lt;SPAN&gt;Nothing&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
		&lt;SPAN&gt;MessageBox&lt;/SPAN&gt;.&lt;SPAN&gt;Show&lt;/SPAN&gt;(&lt;SPAN&gt;"No color selected. Exiting the script."&lt;/SPAN&gt;)
		&lt;SPAN&gt;Exit&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;
	&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;

	&lt;SPAN&gt;' Traverse the assembly and color parts where CompliantWithMachine is False&lt;/SPAN&gt;
	&lt;SPAN&gt;Call&lt;/SPAN&gt; &lt;SPAN&gt;TraverseAssembly&lt;/SPAN&gt;(&lt;SPAN&gt;oOccs&lt;/SPAN&gt;, &lt;SPAN&gt;oColor&lt;/SPAN&gt;)

	&lt;SPAN&gt;' Show completion message&lt;/SPAN&gt;
	&lt;SPAN&gt;MessageBox&lt;/SPAN&gt;.&lt;SPAN&gt;Show&lt;/SPAN&gt;(&lt;SPAN&gt;"Coloring successfully completed."&lt;/SPAN&gt;)
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;

&lt;SPAN&gt;Sub&lt;/SPAN&gt; &lt;SPAN&gt;TraverseAssembly&lt;/SPAN&gt;(&lt;SPAN&gt;oOccs&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ComponentOccurrences&lt;/SPAN&gt;, &lt;SPAN&gt;oColor&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Asset&lt;/SPAN&gt;)
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oOcc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ComponentOccurrence&lt;/SPAN&gt;
	&lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;Each&lt;/SPAN&gt; &lt;SPAN&gt;oOcc&lt;/SPAN&gt; &lt;SPAN&gt;In&lt;/SPAN&gt; &lt;SPAN&gt;oOccs&lt;/SPAN&gt;
		&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oOcc&lt;/SPAN&gt;.&lt;SPAN&gt;DefinitionDocumentType&lt;/SPAN&gt; = &lt;SPAN&gt;DocumentTypeEnum&lt;/SPAN&gt;.&lt;SPAN&gt;kAssemblyDocumentObject&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
			&lt;SPAN&gt;Call&lt;/SPAN&gt; &lt;SPAN&gt;TraverseAssembly&lt;/SPAN&gt;(&lt;SPAN&gt;oOcc&lt;/SPAN&gt;.&lt;SPAN&gt;SubOccurrences&lt;/SPAN&gt;, &lt;SPAN&gt;oColor&lt;/SPAN&gt;)
		&lt;SPAN&gt;ElseIf&lt;/SPAN&gt; &lt;SPAN&gt;oOcc&lt;/SPAN&gt;.&lt;SPAN&gt;DefinitionDocumentType&lt;/SPAN&gt; = &lt;SPAN&gt;DocumentTypeEnum&lt;/SPAN&gt;.&lt;SPAN&gt;kPartDocumentObject&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;

			&lt;SPAN&gt;'set default &lt;/SPAN&gt;
			&lt;SPAN&gt;isCompliant&lt;/SPAN&gt; = &lt;SPAN&gt;True&lt;/SPAN&gt;

			&lt;SPAN&gt;Try&lt;/SPAN&gt;
				&lt;SPAN&gt;isCompliant&lt;/SPAN&gt; = &lt;SPAN&gt;iProperties&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt;(&lt;SPAN&gt;oOcc&lt;/SPAN&gt;.&lt;SPAN&gt;Name&lt;/SPAN&gt;, &lt;SPAN&gt;"Custom"&lt;/SPAN&gt;, &lt;SPAN&gt;"CompliantWithMachine"&lt;/SPAN&gt;)
			&lt;SPAN&gt;Catch&lt;/SPAN&gt;
				&lt;SPAN&gt;' If the property is missing or an error occurs, do not color the part&lt;/SPAN&gt;
			&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Try&lt;/SPAN&gt;

			&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;isCompliant&lt;/SPAN&gt; = &lt;SPAN&gt;False&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt; &lt;SPAN&gt;oOcc&lt;/SPAN&gt;.&lt;SPAN&gt;Appearance&lt;/SPAN&gt; = &lt;SPAN&gt;oColor&lt;/SPAN&gt;

		&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
	&lt;SPAN&gt;Next&lt;/SPAN&gt;
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;

&lt;SPAN&gt;Function&lt;/SPAN&gt; &lt;SPAN&gt;GetColor&lt;/SPAN&gt;() &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Asset&lt;/SPAN&gt;

&lt;STRONG&gt;	'hard coded color values
	'https://www.rapidtables.com/web/color/RGB_Color.html
	oRed = 255
	oGreen = 0
	oBlue = 0&lt;/STRONG&gt;

	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oName&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt; = &lt;SPAN&gt;"Paint Color"&lt;/SPAN&gt;
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oAppearance&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Asset&lt;/SPAN&gt;

	&lt;SPAN&gt;Try&lt;/SPAN&gt; &lt;SPAN&gt;'create new appearance &lt;/SPAN&gt;
		&lt;SPAN&gt;oAppearance&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Document&lt;/SPAN&gt;.&lt;SPAN&gt;Assets&lt;/SPAN&gt;.&lt;SPAN&gt;Add&lt;/SPAN&gt;(&lt;SPAN&gt;AssetTypeEnum&lt;/SPAN&gt;.&lt;SPAN&gt;kAssetTypeAppearance&lt;/SPAN&gt;,
		&lt;SPAN&gt;"Generic"&lt;/SPAN&gt;, &lt;SPAN&gt;"Appearances"&lt;/SPAN&gt;, &lt;SPAN&gt;oName&lt;/SPAN&gt;)
	&lt;SPAN&gt;Catch&lt;/SPAN&gt;
		&lt;SPAN&gt;oAppearance&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Document&lt;/SPAN&gt;.&lt;SPAN&gt;Assets&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;oName&lt;/SPAN&gt;)
	&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Try&lt;/SPAN&gt;

	&lt;SPAN&gt;'set colors&lt;/SPAN&gt;
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oNewColor&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;ColorAssetValue&lt;/SPAN&gt;
	&lt;SPAN&gt;oNewColor&lt;/SPAN&gt; = &lt;SPAN&gt;oAppearance&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"generic_diffuse"&lt;/SPAN&gt;)
	&lt;SPAN&gt;oNewColor&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;TransientObjects&lt;/SPAN&gt;.&lt;SPAN&gt;CreateColor&lt;/SPAN&gt;(&lt;SPAN&gt;oRed&lt;/SPAN&gt;, &lt;SPAN&gt;oGreen&lt;/SPAN&gt;, &lt;SPAN&gt;oBlue&lt;/SPAN&gt;)

	&lt;SPAN&gt;Return&lt;/SPAN&gt; &lt;SPAN&gt;oAppearance&lt;/SPAN&gt;
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Function&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 17:15:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12956399#M170636</guid>
      <dc:creator>Curtis_Waguespack</dc:creator>
      <dc:date>2024-08-13T17:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to auto change part color for a big assembly with sub-assemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12956634#M170645</link>
      <description>&lt;P&gt;That works very well for me! Thank you for your help!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 19:20:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-to-auto-change-part-color-for-a-big-assembly-with-sub/m-p/12956634#M170645</guid>
      <dc:creator>jeyuan</dc:creator>
      <dc:date>2024-08-13T19:20:34Z</dc:date>
    </item>
  </channel>
</rss>

