- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is it possible to paint (change colour) of some parts in a drawing using ilogic?
I have a drawing of an assembly, where are many elements.
I would like to automatically paint parts in specific colour (type of colour doesn't matter, can be red, green etc.).
When I paint "Element1" to red, I want all occurrences of "Element1" to be painted (since there are many) and on all views. This is important to me because number of occurrences changes.
How can I do it with ilogic?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous,
Hoping that below forum discussion link may be helpful.
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Discussion from the link is about getting colour from the part and puting it to drawing.
In my case it is impossibile, because many different parts have the same colour (it is connected with material).
I would like to paint a specific part (all occurrences of this part) with some colour (for example red) with no connection to part colour.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous,
Can you please provide sample assembly with drawing to test? Please make sure that files are non confidential.
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ok I put a sample assembly with drawing.
Drawing has 2 sheets. First is balck and white. The second is coloured manually.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous,
Try below iLogic code to color parts in assembly. In this example, there are 3 parts in assembly. So, code works for 3 colors only. It extended for different colors based on situations.
Sub Main()
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim layers As LayersEnumerator
layers = oDoc.StylesManager.Layers
On Error Resume Next
Dim oRed As Layer
oRed = layers.Item("Red")
If Err.Number <> 0 Then
On Error GoTo 0
Dim redColor As Color
redColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
' Copy an arbitrary layer giving it the name
' of the render style.
oRed = layers.Item(1).Copy("Red")
' the attributes of the layer to use the color,
' have a solid line type, and a specific width.
oRed.Color = redColor
oRed.LineType = kContinuousLineType
oRed.LineWeight = 0.02
End If
On Error Resume Next
Dim oGreen As Layer
oGreen = layers.Item("Green")
If Err.Number <> 0 Then
On Error GoTo 0
Dim greenColor As Color
greenColor = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
' Copy an arbitrary layer giving it the name
' of the render style.
oGreen = layers.Item(1).Copy("Green")
' the attributes of the layer to use the color,
' have a solid line type, and a specific width.
oGreen.Color = greenColor
oGreen.LineType = kContinuousLineType
oGreen.LineWeight = 0.02
End If
On Error Resume Next
Dim oBlue As Layer
oBlue = layers.Item("Blue")
If Err.Number <> 0 Then
On Error GoTo 0
Dim blueColor As Color
blueColor = ThisApplication.TransientObjects.CreateColor(0, 0, 255)
' Copy an arbitrary layer giving it the name
' of the render style.
oBlue = layers.Item(1).Copy("Blue")
' the attributes of the layer to use the color,
' have a solid line type, and a specific width.
oBlue.Color = blueColor
oBlue.LineType = kContinuousLineType
oBlue.LineWeight = 0.02
End If
Dim colorColl As ObjectCollection
colorColl = ThisApplication.TransientObjects.CreateObjectCollection
Call colorColl.Add(oRed)
Call colorColl.Add(oBlue)
Call colorColl.Add(oGreen)
Dim oView As DrawingView
For Each oView In oSheet.DrawingViews
Dim oReferDoc As AssemblyDocument
oReferDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oAssyDef As AssemblyComponentDefinition
oAssyDef = oReferDoc.ComponentDefinition
Dim occDoc As Document
Dim cnt As Integer
cnt = 1
For Each occDoc In oReferDoc.AllReferencedDocuments
Dim occ As ComponentOccurrence
For Each occ In oAssyDef.Occurrences
If occ.ReferencedDocumentDescriptor.ReferencedDocument Is occDoc Then
Dim oCurves As DrawingCurvesEnumerator
oCurves = oView.DrawingCurves(occ)
Dim oCurve As DrawingCurve
For Each oCurve In oCurves
Dim oColl As ObjectCollection
oColl = ThisApplication.TransientObjects.CreateObjectCollection
Dim oSegment As DrawingCurveSegment
For Each oSegment In oCurve.Segments
Call oColl.Add(oSegment)
Next
Call oSheet.ChangeLayer(oColl, colorColl.Item(cnt))
Call oDoc.Update
Next
End If
Next
cnt = cnt + 1
Next
Next
End Sub
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It works exactly as You said - three different parts become coloured in three different colours.
But what if I would like to call a specific part by name in order to paint it? For example:
Colour "Element 01" to red (all occurrences).
Colour "Element 02" to green (all occurrences).
Do not colour "Element 03" (not all parts need to be coloured)
Colour "Element 04" to blue (if exists)
This is because number of different elements will change (there may be "Element 04", "Element 05" , "Element 03" may disappear, etc.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@Anonymous,
Try this.
Sub Main()
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim layers As LayersEnumerator
layers = oDoc.StylesManager.Layers
On Error Resume Next
Dim oRed As Layer
oRed = layers.Item("Red")
If Err.Number <> 0 Then
On Error GoTo 0
Dim redColor As Color
redColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
' Copy an arbitrary layer giving it the name
' of the render style.
oRed = layers.Item(1).Copy("Red")
' the attributes of the layer to use the color,
' have a solid line type, and a specific width.
oRed.Color = redColor
oRed.LineType = kContinuousLineType
oRed.LineWeight = 0.02
End If
On Error Resume Next
Dim oGreen As Layer
oGreen = layers.Item("Green")
If Err.Number <> 0 Then
On Error GoTo 0
Dim greenColor As Color
greenColor = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
' Copy an arbitrary layer giving it the name
' of the render style.
oGreen = layers.Item(1).Copy("Green")
' the attributes of the layer to use the color,
' have a solid line type, and a specific width.
oGreen.Color = greenColor
oGreen.LineType = kContinuousLineType
oGreen.LineWeight = 0.02
End If
On Error Resume Next
Dim oBlue As Layer
oBlue = layers.Item("Blue")
If Err.Number <> 0 Then
On Error GoTo 0
Dim blueColor As Color
blueColor = ThisApplication.TransientObjects.CreateColor(0, 0, 255)
' Copy an arbitrary layer giving it the name
' of the render style.
oBlue = layers.Item(1).Copy("Blue")
' the attributes of the layer to use the color,
' have a solid line type, and a specific width.
oBlue.Color = blueColor
oBlue.LineType = kContinuousLineType
oBlue.LineWeight = 0.02
End If
Dim oView As DrawingView
For Each oView In oSheet.DrawingViews
Dim oReferDoc As AssemblyDocument
oReferDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oAssyDef As AssemblyComponentDefinition
oAssyDef = oReferDoc.ComponentDefinition
Dim occ As ComponentOccurrence
For Each occ In oAssyDef.Occurrences
Dim oCurves As DrawingCurvesEnumerator
oCurves = oView.DrawingCurves(occ)
Dim oCurve As DrawingCurve
For Each oCurve In oCurves
Dim oColl As ObjectCollection
oColl = ThisApplication.TransientObjects.CreateObjectCollection
Dim oSegment As DrawingCurveSegment
For Each oSegment In oCurve.Segments
Call oColl.Add(oSegment)
Next
Dim occName As String
occName = occ.Name
If occName.StartsWith("Element 01") = True Then
Call oSheet.ChangeLayer(oColl, oRed)
Else If occName.StartsWith("Element 02") = True Then
Call oSheet.ChangeLayer(oColl, oGreen)
Else If occName.StartsWith("Element 04") = True Then
Call oSheet.ChangeLayer(oColl, oBlue)
End If
Call oDoc.Update
Next
Next
Next
End Sub
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am interested in assigning color to a layer in the drawing:
Color: Dark Brown
I am trying to assign colot to Dark Brown without success. Please help. Thanks.
Sub Main() Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oLayer As Layer ' oLayer = oDrawDoc.StylesManager.Layers.Item(68) oLayer = oDrawDoc.StylesManager.Layers.Item("Title (ISO)") Dim oNewLayer As Layer oNewLayer_Name = "XYZ" Try oNewLayer = oLayer.Copy(oNewLayer_Name) Catch MessageBox.Show("New layer, " & oNewLayer_Name & ": Exists", "Title") End Try ThisDrawing.Document.StylesManager.Layers(oNewLayer_Name).Visible = False ThisDrawing.Document.StylesManager.Layers(oNewLayer_Name).Plot = False End Sub
Need help to assign
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hoping that below iLogic code may be helpful.
Sub Main()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oLayer As Layer
' oLayer = oDrawDoc.StylesManager.Layers.Item(68)
oLayer = oDrawDoc.StylesManager.Layers.Item("Title (ISO)")
Dim oNewLayer As Layer
oNewLayer_Name = "XYZ"
Try
oNewLayer = oLayer.Copy(oNewLayer_Name)
Catch
MessageBox.Show("New layer, " & oNewLayer_Name & ": Exists", "Title")
End Try
ThisDrawing.Document.StylesManager.Layers(oNewLayer_Name).Visible = False
ThisDrawing.Document.StylesManager.Layers(oNewLayer_Name).Plot = False
Dim brownColor As Color
brownColor = ThisApplication.TransientObjects.CreateColor(165, 42, 42)
' the attributes of the layer to use the color,
' have a solid line type, and a specific width.
oNewLayer.Color = brownColor
oNewLayer.LineType = kContinuousLineType
oNewLayer.LineWeight = 0.02
End Sub
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Chandra Shekar;
Thanks a lot for the great help. It is fine. Also, I tailored the rule (see the attached .txt file).
brownColor_1 = ThisApplication.TransientObjects.CreateColor(xxx, xxx, xxx)
brownColor_2 = ThisApplication.TransientObjects.CreateColor(xxx, xxx, xxx)
Could you provide me with the coding for brownColor_1 andbrownColor_2: see the image below.
Could I know the list of TransientObjects.CreateColor for all colors.
Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Refer below images to get RGB values for brown color.
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks a lot for the help.
That is fine.
I am taking sometime off from Inventor customization training (from today till end of Sept) for taking some strenuous self faced training in using SolidWorks 2019.
Planning to take very high skills in Solidworks as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
How do you change the colour of a iPart in Drawing?
That is very importante for me ![]()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
very interesting
is it Posible to change the colour of the Parts in Drawing using custom Properties?
I mean. Some parts have the same custom Property called "Green". Then in Drawing change all this parts in this color (preferably to have a layer with this name "Green" too)