By Barbara Han
Issue
I need to offset a WorkPlane in a Part Document that is not driven by a model parameter. How can I do it so other work features based on it are offset as well?
Solution
The following example offsets a selected WorkPlane. After the WorkPlane has been offset it will be driven by a model parameter.
VBA sample:
Public Function OffsetPartWorkPlane(oWorkPlane As WorkPlane, Offset As Double)
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
Dim oWorkPlanes As WorkPlanes
Set oWorkPlanes = oPartDoc.ComponentDefinition.WorkPlanes
Dim oConstrucWorkPoint As WorkPoint
Set oConstrucWorkPoint = oPartDoc.ComponentDefinition.WorkPoints.AddFixed(oWorkPlane.Plane.RootPoint)
Dim oConstrucWorkAxis As WorkAxis
Set oConstrucWorkAxis = oPartDoc.ComponentDefinition.WorkAxes.AddFixed(oWorkPlane.Plane.RootPoint, oWorkPlane.Plane.Normal)
Dim oConstrucWorkPlane As WorkPlane
Set oConstrucWorkPlane = oWorkPlanes.AddByNormalToCurve(oConstrucWorkAxis, oConstrucWorkPoint)
Call oWorkPlane.SetByPlaneAndOffset(oConstrucWorkPlane, Offset)
oConstrucWorkPoint.Visible = False
oConstrucWorkAxis.Visible = False
oConstrucWorkPlane.Visible = False
End Function
'Select a WorkPlane and offset it
Public Sub TestOffsetPlane()
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
Dim oWorkPlane As WorkPlane
Set oWorkPlane = oPartDoc.SelectSet.Item(1)
Call OffsetPartWorkPlane(oWorkPlane, 5)
End SubVB.NET sample:
Public Sub OffsetPartWorkPlane()
Dim m_inventorApp As Inventor.Application = Nothing
Dim m_quitInventor As Boolean = False
' Try to get an active instance of Inventor
Try
m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
Catch ex As Exception
End Try
' If not active, create a new Inventor session
If m_inventorApp Is Nothing Then
Dim inventorAppType As Type = System.Type.GetTypeFromProgID("Inventor.Application")
m_inventorApp = System.Activator.CreateInstance(inventorAppType)
m_quitInventor = True
End If
Dim oPartDoc As PartDocument
oPartDoc = m_inventorApp.ActiveDocument
Dim oWorkPlane As WorkPlane
oWorkPlane = oPartDoc.SelectSet.Item(1)
Dim oWorkPlanes As WorkPlanes
oWorkPlanes = oPartDoc.ComponentDefinition.WorkPlanes
Dim oConstrucWorkPoint As WorkPoint
oConstrucWorkPoint = oPartDoc.ComponentDefinition.WorkPoints.AddFixed(oWorkPlane.Plane.RootPoint)
Dim oConstrucWorkAxis As WorkAxis
oConstrucWorkAxis = oPartDoc.ComponentDefinition.WorkAxes.AddFixed(oWorkPlane.Plane.RootPoint, oWorkPlane.Plane.Normal)
Dim oConstrucWorkPlane As WorkPlane
oConstrucWorkPlane = oWorkPlanes.AddByNormalToCurve(oConstrucWorkAxis, oConstrucWorkPoint)
oWorkPlane.SetByPlaneAndOffset(oConstrucWorkPlane, 5)
oConstrucWorkPoint.Visible = False
oConstrucWorkAxis.Visible = False
oConstrucWorkPlane.Visible = False
End Sub