By Barbara Han
Issue
How to set the tangent vector (curvature) of a spline at a specific FitPoint through API?
Solution
The following code sample illustrates how to get and modify the tangent vector of a spline at a specific FitPoint.
In this sample:
1. User should firstly select a spline's FitPoint through UI
2. Use API to get the tangent vector at the selected point by SketchSplineHandle.
3. Change the vector. i.e. offset it by (0.2, 0.2)
Note: The "SketchSplineHandle" object has been introduced in the 2008 API, so this code is only supported by Inventor versions from 2008 on.
Public Sub SetSplineCurvature()
'First select the FitPoint of interest through the UI
Dim oFitPoint As SketchPoint
Set oFitPoint = ThisApplication.ActiveDocument.SelectSet.item(1)
'First constraint of the point is always the 'SplineFitPointConstraint'
Dim oConstraint As SplineFitPointConstraint
Set oConstraint = oFitPoint.Constraints.item(1)
'Retrieves spline from the constraint
Dim oSpline As SketchSpline
Set oSpline = oConstraint.Spline
'Creates handle
Call oSpline.SetHandleStatus(oFitPoint, True)
'Gets handle
Dim oSplineHandle As SketchSplineHandle
Set oSplineHandle = oSpline.GetHandle(oFitPoint)
'Gets tangent vector
Dim oTangent As UnitVector2d
Set oTangent = oSplineHandle.Tangent
'Sets tangent vector with new value
oSplineHandle.Tangent = ThisApplication.TransientGeometry.CreateUnitVector2d(oTangent.x + 0.2, oTangent.y + 0.2)
End Sub
VB .NET version:
public static void SetSplineCurvature()
{
try
{
Inventor.Application app = (Inventor.Application)System.
Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
SketchPoint oFitPoint = app.ActiveDocument.SelectSet[1] as SketchPoint;
SplineFitPointConstraint oConstraint = oFitPoint.Constraints[1] as SplineFitPointConstraint;
//Retrieves spline from the constraint
SketchSpline oSpline = oConstraint.Spline;
//Creates handle
oSpline.SetHandleStatus(oFitPoint, true);
//Gets handle
SketchSplineHandle oSplineHandle = oSpline.GetHandle(oFitPoint);
//Gets tangent vector
UnitVector2d oTangent = oSplineHandle.Tangent;
//Sets tangent vector with new value
oSplineHandle.Tangent = app.TransientGeometry.CreateUnitVector2d(oTangent.X + 0.2, oTangent.Y + 0.2);
}
catch
{
}
}