Change color of whole part based on Iproperties

Change color of whole part based on Iproperties

jocean_vieiraZ9YQS
Participant Participant
339 Views
2 Replies
Message 1 of 3

Change color of whole part based on Iproperties

jocean_vieiraZ9YQS
Participant
Participant

I have tried to piece a few rules that I saw online together but without luck! 


So I'm trying to get a part, inside an assembly, that has the description "Special" in Iproperties. And subsequently, make it red to create a visual signal that it needs a part number before being released. 

jocean_vieiraZ9YQS_0-1717006894196.png

 

Dim asmDoc As AssemblyDocument
asmDoc = ThisApplication.ActiveDocument

Dim occ As ComponentOccurrence
For Each iProperties.Value("Stock Number") = "Special"
	
	asmDoc.RenderStyles.Item("Red"))
Next

 

0 Likes
Accepted solutions (1)
340 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @jocean_vieiraZ9YQS.  Give this iLogic rule example a try, and see if it works OK for you.  It only works on top level components right now though.

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	If oOccs.Count = 0 Then Return
	For Each oOcc As ComponentOccurrence In oOccs
		Dim sStockNumber As String = iProperties.Value(oOcc.Name, "Project", "Stock Number")
		If sStockNumber = "SPECIAL" Then
			Component.Color(oOcc.Name) = "Red"
		End If
	Next oOcc
	oADoc.Update2(True)
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)

Message 3 of 3

jocean_vieiraZ9YQS
Participant
Participant

Thanks, I ended up just making a few additions and it works perfect for me now.

 Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	If oOccs.Count = 0 Then Return
	For Each oOcc As ComponentOccurrence In oOccs
		Dim sStockNumber As String = iProperties.Value(oOcc.Name, "Project", "Stock Number")
		If TypeOf oOcc.Definition.Document Is PartDocument Then 
			If sStockNumber = "SPECIAL" OrElse sStockNumber = "" Then
				Component.Color(oOcc.Name) = "PINK"
			End If
		End If
	Next oOcc
	oADoc.Update2(True)
End Sub
0 Likes