Change appearence colors assembly by iproperty value

Change appearence colors assembly by iproperty value

morrenengineering
Contributor Contributor
242 Views
1 Reply
Message 1 of 2

Change appearence colors assembly by iproperty value

morrenengineering
Contributor
Contributor

Hello,

 

In an assembly, I want to run a code, so I can change the appearence colors by an Iproperty value. The code "art" has for example the value "FAS", then the color must be changed in red color. I Made a code, but it has no errors, but also it do not work. Can anyone help me?

 

Sub Main()
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = ThisDoc.FileName(False) 'without extension
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments    
Dim oRefDoc As Document
Dim oPart As ComponentOccurrence
Dim oLib As AssetLibrary
oLib = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")
'work the referenced models
For Each oRefDoc In oRefDocs
	Dim oCurFile As Document
	oCurFile = ThisApplication.Documents.Open(oRefDoc.FullFileName, True)       
    oCurFileName = oCurFile.FullFileName 
    'defines backslash As the subdirectory separator
    Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar
    	Try
			For Each oProp As Inventor.Property In oRefDoc.PropertySets.Item("Inventor User Defined Properties")
				If oProp.Name = "art" And oProp.Expression = "FAS" Then
					Component.Color(oProp.Name) = "Red"
					iLogicVb.UpdateWhenDone = True
				End If 

				If oProp.Name = "art" And oProp.Expression = "PLA" Then
					Component.Color(oProp.Name) = "Blue"
					iLogicVb.UpdateWhenDone = True
				End If				
							
			Next 

			
    	Catch
    	End Try
	oCurFile.Close
	Next

'update all
InventorVb.DocumentUpdate()
End Sub

 

0 Likes
243 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @morrenengineering.  After looking at your comments, then the code you posted, I am still a little confused about the specifics of what you were trying to accomplish.  I assume that you want to change the color of the 'components' in the assembly, without actually changing the colors of the actual part files that they reference, and using a custom iProperty value from each component to decide which color to make each component.  So, I created an alternate iLogic rule for you to try out.  I hope this is what you were trying to do.

Sub Main
	Dim oADoc As AssemblyDocument = ThisAssembly.Document
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	If oOccs.Count = 0 Then Exit Sub
	For Each oOcc As ComponentOccurrence In oOccs
		Dim sArtExp As String = ""
		Try : sArtExp = iProperties.Expression(oOcc.Name, "Custom", "art") : Catch : End Try
		If sArtExp = "" Then
			Continue For 'skip to next component
		ElseIf sArtExp = "FAS" Then
			Component.Color(oOcc.Name) = "Red"
		ElseIf sArtExp = "PLA" Then
			Component.Color(oOcc.Name) = "Blue"
		End If
	Next 'oOcc
	If oADoc.RequiresUpdate Then oADoc.Update
	'If oADoc.Dirty Then oADoc.Save
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes