Colour Coding Parts by Length in Drawings

Colour Coding Parts by Length in Drawings

BasVermeer
Contributor Contributor
108 Views
2 Replies
Message 1 of 3

Colour Coding Parts by Length in Drawings

BasVermeer
Contributor
Contributor

Hi everyone,

I have a large number of drawings that include standard-sized tubes and profiles. The team on the shop floor has asked if it's possible to apply colour coding based on the length of each part — for example:

  • 1200mm = blue

  • 1100mm = red

  • 1000mm = yellow
    ...and so on.

I know that in assemblies, it's possible to assign different display colours to unique parts using the "Display Separate Colours" option. However, these colours don't carry over to the drawing environment, as also discussed in this thread: https://forums.autodesk.com/t5/inventor-ideas/2025-view-tab-display-seperate-colours-propagate-throu... 

 

My question is:
What is the best way to achieve colour coding of parts in a drawing based on their length, without having to manually overlay and fill sketch geometry on each view?

Is there a workflow, automation, or add-in that could help streamline this?

 

Thanks in advance!

0 Likes
109 Views
2 Replies
Replies (2)
Message 2 of 3

andrewiv
Advisor
Advisor

You will probably have to make a design view in your parts and/or in the assembly to make them the right color and then you can show your drawing view as shaded to display the color on the drawing.  This could probably be done with an iLogic rule.

Andrew In’t Veld
Designer / CAD Administrator

Message 3 of 3

marcin_otręba
Advisor
Advisor

hi,

 

what kind of drawings we are talking about ? assmbly or part drawings ? you want to have colors in shaded view or you want to make part lines colored?

there is many ways to do it but i could suggest to start from coding each part by color , check ilogic below it will create new view repr in each part and change color to definied one - it will work both from part and from assembly:

it gets length from custom iproperty, but it can be adjusted, also i do not use "standard" colors names because inventor sometimes change it to language specific ones..

Sub main
	On Error Resume Next
	Dim view_repr_name = "color_coding"
	Dim  custom_iproperty_name As String ="s_length"
	Dim color_dictionary As New Dictionary(Of String, String) From {
 {"1000 mm",  "xYellow;255;255;0"},
 {"1100 mm",  "xRed;255;0;0"},
 {"1200 mm", "xBlue;0;0;255" }}
 If ThisApplication.ActiveDocumentType =DocumentTypeEnum.kPartDocumentObject Then
	Dim pdoc As PartDocument = ThisDoc.Document
	If color_dictionary.ContainsKey(pdoc.PropertySets(4)(custom_iproperty_name).Value) Then
		Dim name As String=""
		Dim  R, G, B  As Integer
		name = Split(color_dictionary(pdoc.PropertySets(4)(custom_iproperty_name).Value), ";")(0)
		R = Split(color_dictionary(pdoc.PropertySets(4)(custom_iproperty_name).Value), ";")(1)
		G = Split(color_dictionary(pdoc.PropertySets(4)(custom_iproperty_name).Value), ";")(2)
		B = Split(color_dictionary(pdoc.PropertySets(4)(custom_iproperty_name).Value),";")(3)
		Call GetColorAsset(pdoc,view_repr_name, name, R, G, B)
	End If
ElseIf ThisApplication.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim ass As AssemblyDocument =ThisApplication.ActiveDocument
	Dim check As String = ""
		check=ass.ComponentDefinition.RepresentationsManager.DesignViewRepresentations(view_repr_name).Name 
		If check = view_repr_name Then
			ass.ComponentDefinition.RepresentationsManager.DesignViewRepresentations(view_repr_name).Activate 
		Else
			ass.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Add(view_repr_name).Activate 
		End If
		For Each occ As ComponentOccurrence In ass.ComponentDefinition.Occurrences
			If occ.DefinitionDocumentType<>DocumentTypeEnum.kPartDocumentObject Then Continue For
			Dim pdoc As PartDocument = occ.Definition.Document
			If color_dictionary.ContainsKey(pdoc.PropertySets(4)(custom_iproperty_name).Value) Then
				Dim name As String
				Dim  R, G, B  As Integer
				name = Split(color_dictionary(pdoc.PropertySets(4)(custom_iproperty_name).Value), ";")(0)
				R = Split(color_dictionary(pdoc.PropertySets(4)(custom_iproperty_name).Value), ";")(1)
				G = Split(color_dictionary(pdoc.PropertySets(4)(custom_iproperty_name).Value), ";")(2)
				B = Split(color_dictionary(pdoc.PropertySets(4)(custom_iproperty_name).Value),";")(3)
				Call GetColorAsset(pdoc,view_repr_name, name, R, G, B)
				occ.SetDesignViewRepresentation(view_repr_name,, True)
			End If
			
		Next
End If

End Sub
 Function GetColorAsset(doc As PartDocument,view_repr_name As String, name As String, R As Integer, G As Integer, B As Integer) As Asset
Dim Asset As Asset=Nothing
	Try
		Asset = doc.Assets.Add(AssetTypeEnum.kAssetTypeAppearance, "Generic", , name)

	Catch ex As Exception
		Try
			Asset = doc.Assets.Item(name)
		Catch ex1 As Exception
			doc.Rebuild()
			doc.Update()
			Try
				Asset = doc.Assets.Add(AssetTypeEnum.kAssetTypeAppearance, "Generic", , name)
			Catch ex2 As Exception
			End Try
		End Try
	End Try
Dim uColor As ColorAssetValue = Asset.Item("generic_diffuse")
Dim clr As Inventor.Color = ThisApplication.TransientObjects.CreateColor(R, G, B)
uColor.Value = clr
check  = ""
Try
check = doc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations(view_repr_name).Name 
Catch ex As Exception
End Try
If check = view_repr_name Then
	doc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations(view_repr_name).Activate 
Else
	doc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Add(view_repr_name).Activate 
End If
Try
doc.ActiveAppearance = Asset
Catch ex As Exception
End Try
doc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations(1).Activate
doc.Save		
End Function

 

marcin_otrba_0-1757665676921.png

 

then you can place shaded view into your drawings... if you want to make lines colored then give me know, if you will fail with code, maybe you could share you sample file...

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes