Inventor 2014 new API for sketch creation

There are four new API enhancements for sketches. Three of them create sketch curves that could be created from the UI in previous releases. One of the enhancements is new in the UI too.

Slots

In the 2014 release you can now easily create slots.

image 

Creating slots in the API is accomplished by calling one of these Add methods that are on several different sketch objects:

AddArcSlotByCenterPointArc
AddArcSlotByThreePointArc
AddStraightSlotByCenterToCenter
AddStraightSlotByOverall

Here is the signature for AddArcSlotByCenterPointArc:

Sketch.AddArcSlotByCenterPointArc( CenterPoint As Object, StartPoint As Object, SweepAngle As Double, Width As Double )

Equation curves

Inventor 2013 added the ability to create sketch curves using equations. Now you can create curves using equations with the API. The SketchEquationCurve object represents an equation curve within a sketch. Different sketch objects have a SketchEquationCurves collection and you use the Add method to create a SketchEquationCurve. If you have not used equation curves before I would suggest looking at the Inventor help file to see how to create these from the UI. Once you understand how these curves are created in the user interface the arguments in the SketchEquationCurves.Add method will be easier to understand. Here is the signature :

SketchEquationCurves.Add( EquationType As CurveEquationTypeEnum, CoordinateSystemType As CoordinateSystemTypeEnum, XValueOrRadius As String, YValueOrTheta As String, MinValue As Variant, MaxValue As Variant )

Intersection Curves

This is another API enhancement that is catching up to the UI. The IntersectionCurve object represents the results of creating an intersection between different types of geometry. The Sketch3d and Sketch3dProxy now have an IntersectionCurves collection. You use the Add method to create an IntersectionCurve.  Here is the signature:

IntersectionCurves.Add( EntityOne As Object, EntityTwo As Object )

Control point splines

Inventor 2013 introduced the ability to create splines using control points. The 2014 API can now create this type of spline. Both 2D and 3D sketch objects have a SketchControlPointSplines collection. (SketchControlPointSplines3D) Use the Add method to create these splines. Here is the signature:

SketchControlPointSplines.Add( ControlPoints As ObjectCollection )

C# example:

Below is one of the functions from this C# project which was translated from the VBA example in the help file. The c# project also has a CreateSlots() function that creates sketch curves by calling the four different methods for creating slots.

  Download Inventor_2014_Sketch_Examples

SketchCurves does the following:

  1. Creates a sketch and adds a SketchControlPointSpline

  2. Creates another sketch and adds a SketchEquationCurve

  3. Creates a Sketch3D and adds a SketchControlPointSpline3D

  4. Adds a SketchEquationCurve3D to the Sketch3D

  5. Adds a surface feature using a profile created using the SketchControlPointSpline from sketch. (step 1)

  6. Adds a surface feature using a profile created using the SketchEquationCurve from sketch2. (step 2)

  7. Creates another Sketch3D named interSketch, This sketch uses IntersectionCurves.Add

image

After running the code a new part is created with the geometry

 

public void SketchCurves()
{
    // Create a new part.
    PartDocument partDoc =
        (PartDocument)ThisApplication.Documents.Add
             (DocumentTypeEnum.kPartDocumentObject,
       ThisApplication.FileManager.GetTemplateFile
             (DocumentTypeEnum.kPartDocumentObject));
 
    PartComponentDefinition partDef =
(PartComponentDefinition)partDoc.ComponentDefinition;
 
    // Create a 2D sketch on the X-Y plane.
    PlanarSketch sketch1 =
                (PlanarSketch)partDef.Sketches.Add
                             (partDef.WorkPlanes[3]);
 
    TransientGeometry tg =
(TransientGeometry)ThisApplication.TransientGeometry;
 
    // Create a spline based on control points.
    ObjectCollection pnts =
    (ObjectCollection)ThisApplication.
        TransientObjects.CreateObjectCollection();
 
    pnts.Add(tg.CreatePoint2d(2, 0));
    pnts.Add(tg.CreatePoint2d(4, 1));
    pnts.Add(tg.CreatePoint2d(4, 2));
    pnts.Add(tg.CreatePoint2d(6, 3));
    pnts.Add(tg.CreatePoint2d(8, 1));
    SketchControlPointSpline controlPointSpline =
                 (SketchControlPointSpline)sketch1.
               SketchControlPointSplines.Add(pnts);
 
    // Create a 2D sketch on the Y-Z plane.
    PlanarSketch sketch2 =
        (PlanarSketch)partDef.Sketches.Add
                         (partDef.WorkPlanes[1]);
 
    // Create a spline based on an equation.
    SketchEquationCurve equationCurve =
(SketchEquationCurve)sketch2.SketchEquationCurves.
            Add(CurveEquationTypeEnum.kParametric,
              CoordinateSystemTypeEnum.kCartesian,
             ".001*t * cos(t)", ".001*t * sin(t)",
                                     0.1, 360 * 3);
 
    // Create a 3D sketch.
    Sketch3D sketch3 =
            (Sketch3D)partDef.Sketches3D.Add();
 
    // Create a 3D spline based on control points.
    pnts = ThisApplication.TransientObjects.
                         CreateObjectCollection();
    pnts.Add(tg.CreatePoint(10, 0, 0));
    pnts.Add(tg.CreatePoint(12, 1, 3));
    pnts.Add(tg.CreatePoint(12, 2, -5));
    pnts.Add(tg.CreatePoint(14, 3, 2));
    pnts.Add(tg.CreatePoint(16, 1, -3));
 SketchControlPointSpline3D controlPointSpline2 =
             (SketchControlPointSpline3D)sketch3.
           SketchControlPointSplines3D.Add(pnts);
 
    // Create a 3D spline based on an equation.
    SketchEquationCurve3D equationCurve2 =
        (SketchEquationCurve3D)sketch3.
           SketchEquationCurves3D.Add
           (CoordinateSystemTypeEnum.kCartesian,
       ".001*t * cos(t) + 8", ".001*t * sin(t)",
                         "0.002*t", 0, 360 * 3);
 
    ThisApplication.ActiveView.Fit();
 
    // Extrude the 2d curves.
    Profile prof = default(Profile);
    prof = sketch1.Profiles.AddForSurface
                        (controlPointSpline);
    ExtrudeDefinition extrudeDef =
        (ExtrudeDefinition)partDef.Features.
        ExtrudeFeatures.CreateExtrudeDefinition
(prof, PartFeatureOperationEnum.kSurfaceOperation);
 
    extrudeDef.SetDistanceExtent(6,
                  PartFeatureExtentDirectionEnum.
                        kSymmetricExtentDirection);
 
    ExtrudeFeature extrude1 =
                     (ExtrudeFeature)partDef.
          Features.ExtrudeFeatures.Add(extrudeDef);
 
    // Change the work surface to 
    // not be transparent.
    WorkSurface surf = default(WorkSurface);
    surf = extrude1.SurfaceBodies[1].Parent;
    surf.Translucent = false;
 
    prof = sketch2.Profiles.
                   AddForSurface(equationCurve);
 
    extrudeDef = partDef.Features.ExtrudeFeatures.
        CreateExtrudeDefinition
(prof, PartFeatureOperationEnum.kSurfaceOperation);
    extrudeDef.SetDistanceExtent(9,
        PartFeatureExtentDirectionEnum.
                          kPositiveExtentDirection);
    ExtrudeFeature extrude2 =
        (ExtrudeFeature)partDef.Features.
                    ExtrudeFeatures.Add(extrudeDef);
 
    // Create a new sketch and an 
    //intersection curve.
    Sketch3D interSketch =
        (Sketch3D)partDef.Sketches3D.Add();
 
    interSketch.IntersectionCurves.Add
              (extrude1.SurfaceBodies[1],
                  extrude2.SurfaceBodies[1]);
}

-Wayne


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading