Here is the second group of VBA examples in this section of samples for features converted to C#. The project with the first set of converted samples for features is here.
This project has the following functions.
Download InventorHelpExamples_Features_2
HoleFeatureLinearPlacement
StitchFeatureCreate
CreateNonPlanarSectionLoft
EditExtrudeFeature
SweepFeature
TrueSweepLength
ThreadSample
EditThread
test_threadinfo
Here is HoleFeatureLinearPlacement function:
// Hole feature linear placement API Sample
//Description
//This sample demonstrates the creation of a
//hole feature using the linear placement type.
public void HoleFeatureLinearPlacement()
{
// Create a new part document, using the
//default part template.
PartDocument oPartDoc = default(PartDocument);
oPartDoc = (PartDocument)ThisApplication.
Documents.Add
(DocumentTypeEnum.kPartDocumentObject,
ThisApplication.FileManager.GetTemplateFile
(DocumentTypeEnum.kPartDocumentObject));
// Set a reference to the component definition.
PartComponentDefinition oCompDef =
default(PartComponentDefinition);
oCompDef = oPartDoc.ComponentDefinition;
// Create a new sketch on the X-Y work plane.
PlanarSketch oSketch = default(PlanarSketch);
oSketch = oCompDef.Sketches.Add
(oCompDef.WorkPlanes[3]);
// Set a reference to the
//transient geometry object.
TransientGeometry oTransGeom =
default(TransientGeometry);
oTransGeom = ThisApplication.TransientGeometry;
// Create a square on the sketch.
oSketch.SketchLines.AddAsTwoPointRectangle
(oTransGeom.CreatePoint2d(0, 0),
oTransGeom.CreatePoint2d(6, 6));
// Create the profile.
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("2 cm",
PartFeatureExtentDirectionEnum.
kNegativeExtentDirection);
ExtrudeFeature oExtrude =
default(ExtrudeFeature);
oExtrude = oCompDef.Features.ExtrudeFeatures.
Add(oExtrudeDef);
// Get the start face of the extrude.
Face oFace = default(Face);
oFace = oExtrude.StartFaces[1];
// Get two adjacent edges on the start face.
Edge oEdge1 = default(Edge);
Edge oEdge2 = default(Edge);
oEdge1 = oFace.Edges[1];
oEdge2 = oFace.Edges[2];
// Create a bias point for hole placement to
//place it at the expected location. This is
//the model point corresponding to the center
//of the square in the sketch.
Inventor.Point oBiasPoint =
default(Inventor.Point);
oBiasPoint = oSketch.SketchToModelSpace
(oTransGeom.CreatePoint2d(1.5, 1.5));
// Create the hole feature placement definition.
LinearHolePlacementDefinition oLinearPlacementDef
= default(LinearHolePlacementDefinition);
oLinearPlacementDef = oCompDef.Features.
HoleFeatures.CreateLinearPlacementDefinition
(oFace, oEdge1, "2 cm",
oEdge2, "2 cm", oBiasPoint);
// Create the hole feature.
oCompDef.Features.HoleFeatures.
AddDrilledByThroughAllExtent
(oLinearPlacementDef, "1 cm",
PartFeatureExtentDirectionEnum.
kPositiveExtentDirection);
}


Leave a Reply