Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Curtis_Waguespack
in reply to: jeyuan

@jeyuan, 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.

 

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.

 

( p.s. thanks to @Stakin who supplied the color picker example recently)

 

 

 

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