C# Help Examples for Features – Part 1

Here is the first group of VBA examples in this section of samples for Features converted to C#.

image

This project has the following functions.

 Download InventorHelpExamples_Features_1

BoundaryPatchFeature
DecalFeature
DrawBlockWithPocket
EditFeatureProfile
ExtrudeSketchText
CreateAllRoundsFillet
CreateFilletComplex
CreateSimpleFillet
HighlightFeatureFaces
ClearHighlight

Here is CreateSimpleFillet

//    Fillet Feature (Simple) API Sample 
//Description 
//This sample demonstrates using the AddSimple method 
//of the FilletFeatures collection
// to create a constant radius fillet.
public void CreateSimpleFillet()
{
    // Create a new Part document.
    PartDocument oPartDoc = default(PartDocument);
    oPartDoc =
     (PartDocument)ThisApplication.Documents.Add
           (DocumentTypeEnum.kPartDocumentObject,
     ThisApplication.FileManager.GetTemplateFile
         (DocumentTypeEnum.kPartDocumentObject));
 
    // Set a reference to the compdef.
    PartComponentDefinition oCompDef =
             default(PartComponentDefinition);
    oCompDef = oPartDoc.ComponentDefinition;
 
    // Create a sketch on the xy work plane.
    PlanarSketch oSketch = default(PlanarSketch);
    oSketch = oCompDef.Sketches.Add
                        (oCompDef.WorkPlanes[3]);
 
    // Draw a rectangle.
    oSketch.SketchLines.AddAsTwoPointRectangle
    (ThisApplication.TransientGeometry.
                           CreatePoint2d(-6, -4),
   ThisApplication.TransientGeometry.
                            CreatePoint2d(6, 4));
 
    Profile oProfile = default(Profile);
    oProfile = oSketch.Profiles.AddForSolid();
 
    // Create an extrusion.
    ExtrudeDefinition oExtrudeDef =
                   default(ExtrudeDefinition);
    oExtrudeDef = oCompDef.Features.
         ExtrudeFeatures.CreateExtrudeDefinition
(oProfile, PartFeatureOperationEnum.kJoinOperation);
 
    oExtrudeDef.SetDistanceExtent
             (5, PartFeatureExtentDirectionEnum.
                      kSymmetricExtentDirection);
 
    ExtrudeFeature oExtrude =
                          default(ExtrudeFeature);
    oExtrude = oCompDef.Features.
                  ExtrudeFeatures.Add(oExtrudeDef);
 
    // Define the set of edges that are for the start 
    //and end faces of the solid.
    EdgeCollection oEdges =
                    default(EdgeCollection);
    oEdges = ThisApplication.TransientObjects.
                             CreateEdgeCollection();
 
    foreach (Edge oEdge in oExtrude.
                               StartFaces[1].Edges)
    {
        oEdges.Add(oEdge);
    }
 
    foreach (Edge oEdge in oExtrude.
                                EndFaces[1].Edges)
    {
        oEdges.Add(oEdge);
    }
 
    // Create the fillet feature.
    FilletFeature oFillet = default(FilletFeature);
    oFillet = oCompDef.Features.FilletFeatures.
                              AddSimple(oEdges, 1);
}
  • Wayne

Comments

One response to “C# Help Examples for Features – Part 1”

  1. Thank you for the post you just help me out a lot with it. I hope I understood it properly I will sent a link to my project. Thanks again
    D

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading