- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@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.