Issue
I need to create a workplane that is parallel to a line in an existing sketch and rotated a certain angle off of that sketch. Is there an example showing how to do this?
The following example will add a new work plane. Before running this example select a line in a sketch. When the code completes a new workplane will be created. The workplane will be parallel to the line and rotated 45 degrees off the sketch plane.
VBA code:
Private Sub testAddWorkPlane()
' Set a reference to the select set of the active document.
Dim oSelectSet As SelectSet
Set oSelectSet = ThisApplication.ActiveDocument.SelectSet
If oSelectSet.Count = 1 Then
If TypeOf oSelectSet.Item(1) Is SketchLine Then
Dim oPartCompDef As PartComponentDefinition
Set oPartCompDef = ThisApplication _
.ActiveDocument.ComponentDefinition
Dim oSketchLine As SketchLine
Set oSketchLine = oSelectSet.Item(1)
Dim oSketch As Sketch
Set oSketch = oSketchLine.Parent
Debug.Print oSketch.Name
Dim oWrkPlane As WorkPlane
Set oWrkPlane = oPartCompDef.WorkPlanes _
.AddByLinePlaneAndAngle(oSketchLine, oSketch, 45#)
End If
End If
End Sub
VB.NET code:
Public Sub AddWorkPlane()
' Set a reference to the select set of the active document.
Dim oSelectSet As SelectSet
oSelectSet = m_inventorApp.ActiveDocument.SelectSet
If oSelectSet.Count = 1 Then
If TypeOf oSelectSet.Item(1) Is SketchLine Then
Dim oPartCompDef As PartComponentDefinition _
= m_inventorApp.ActiveDocument.ComponentDefinition
Dim oSketchLine As SketchLine = oSelectSet.Item(1)
Dim oSketch As Sketch = oSketchLine.Parent
Debug.Print(oSketch.Name)
Dim oWrkPlane As WorkPlane = oPartCompDef _
.WorkPlanes.AddByLinePlaneAndAngle( _
oSketchLine, oSketch, 45.0#)
End If
End If
End Sub