Having trouble setting Sketch Color in a part

Having trouble setting Sketch Color in a part

neodd70
Enthusiast Enthusiast
864 Views
3 Replies
Message 1 of 4

Having trouble setting Sketch Color in a part

neodd70
Enthusiast
Enthusiast

I have tried setting the sketch color of a part but I keep getting errors and I'm not sure what I'm doing wrong. I want to be able to have different sketches have different colors, this is in a part document not a drawing document. Everywhere I have looked talks about drawing documents but nothing about part documents.

Dim ThisDoc As PartDocument = ThisApplication.ActiveDocument
Dim CompDef As PartComponentDefinition = ThisDoc.ComponentDefinition
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face")
Dim oSketch As PlanarSketch = CompDef.Sketches.Add(oFace)
oSketch.Color.SetColor(0, 255, 0)

Could someone point me in the right direction

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

JelteDeJong
Mentor
Mentor

The problem here is that you try to change the color but by default a sketch does not have a color. therfor you need to give it a color. for example this will make your first skecth in your part red.

Dim doc As PartDocument = ThisDoc.Document
Dim red As Color = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
doc.ComponentDefinition.Sketches.Item(1).Color = red
' you need to update before the change get visable
doc.Update()

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 4

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @neodd70 ,

 

In addition to JelteDeJong's observation, the other thing that I noticed, is that it seems that maybe the sketch needs to have at least one entity before the color can be applied? maybe?

 

I was able to get this example to work, if I set the option to project the face into the sketch to True

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim ThisDoc As PartDocument = ThisApplication.ActiveDocument
Dim CompDef As PartComponentDefinition = ThisDoc.ComponentDefinition
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face")
Dim oSketch As Sketch = CompDef.Sketches.Add(oFace, True)

Dim oColor As Inventor.Color
oColor = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
oSketch.Color = oColor
ThisDoc.Update

EESignature

Message 4 of 4

neodd70
Enthusiast
Enthusiast

@JelteDeJong @ & @ @Curtis_Waguespack Thank you both for your quick responses. That is exactly what I was looking for. FYI Curtis you are correct, if the sketch is empty then it throws an error but if you project the EdgeLoop on sketch creation then when you set the color it's fine. Thank you guys very much.  

0 Likes