Need to create Sketch on a Workplane

Need to create Sketch on a Workplane

RoyWickrama_RWEI
Advisor Advisor
464 Views
3 Replies
Message 1 of 4

Need to create Sketch on a Workplane

RoyWickrama_RWEI
Advisor
Advisor

I am digging to get around creating a sketch on an existing workplane. It is not going through. I request provide me with help.

 

'  a reference to the currently active document.
' This assumes that it is a part document.
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

'  a reference to the component definition.
Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

'  a reference to the transient geometry object.
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

Dim doc = ThisApplication.ActiveDocument




oWP = "WP01"

oSketch = oCompDef.Sketches.Add(oWP)

 

Inventor 2015

0 Likes
465 Views
3 Replies
Replies (3)
Message 2 of 4

Owner2229
Advisor
Advisor

Here you go:

 

' Reference the currently active document.
Dim oDoc As Document = ThisApplication.ActiveDocument

' Parts only. If oDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Exit Sub ' Reference the component definition. Dim oCD As PartComponentDefinition = oDoc.ComponentDefinition ' Reference the workplane called "WP01". Dim oWP As WorkPlane = oCD.WorkPlanes("WP01") ' Add new sketch. Dim oSketch As PlanarSketch = oCD.Sketches.Add(oWP) ' Rename the new sketch (optional). oSketch.Name = "Sketch on WP01"
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 4

RoyWickrama_RWEI
Advisor
Advisor

Thanks. It is really good enough.

However, could you revise the code so that the sketch is active for editing (as shown below):

 

Active Sketch.GIF

 

 

 

 

 

0 Likes
Message 4 of 4

Owner2229
Advisor
Advisor

Here you go.

 

 

' Reference the currently active document.
Dim oDoc As Document = ThisApplication.ActiveDocument

' Parts only. If oDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Exit Sub ' Reference the component definition. Dim oCD As PartComponentDefinition = oDoc.ComponentDefinition ' Reference the workplane called "WP01". Dim oWP As WorkPlane = oCD.WorkPlanes("WP01") ' Add new sketch. Dim oSketch As PlanarSketch = oCD.Sketches.Add(oWP) ' Rename the new sketch (optional). oSketch.Name = "Sketch on WP01"

' Start editing the sketch (optional).
oSketch.Edit()

' Exit the sketch editing (optional).
'oSketch.ExitEdit()
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes