VBA Change Sketch Color

SW 2022. I’m trying to change the color of a sketch with a particular name “Mid1” in multiple part templates. I want to change to color of this particular named sketch in all these files from Green (0,255,0) to Blue (0,0,255). But I’m having trouble Finding a VBA command that will do the actual color assignment.

Anyone have any ideas what I should be looking for. Thanks!

Check the SetLineColor method. Make sure that the sketch is selected before using this method.

3 Likes

Thank you @gupta9665 !
I’ll check it out.

M

Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim color As Long

Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
color = RGB(0, 0, 255) ' Blue
boolstatus = Part.Extension.SelectByID2("Mid1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
If boolstatus Then Part.SetLineColor color
End Sub
2 Likes

Wow, just saw this. I’ll give this a try!
Thank you @mihkov!

1 Like

Works great. Thank you @mihkov!

1 Like