Here is another section of VBA procedures from the help file converted to C#. These examples are related to sheet metal. These examples will be helpful if you are getting started using the Inventor API to work with sheet metal parts and want to use C#. This is the tenth post with converted help samples.
You can find details about how the C# projects can be used in this post. This project has the following functions:
Download InventorHelpExamples_SheetMetal
WriteSheetMetalDXF
EditFlangeWidths
FlangeWidthsCreation
BendExtentEdges
FaceAndFoldFeatureCreation
LoftedFeatureCreation
PunchFeatureReport
PlacePunchFeature
RipFeatureCreation
SheetMetalFeatureDisplay
FaceAndCutFeatureCreation
FaceAndFlangeFeatureCreation
SheetMetalStyleDisplay
SetSheetMetalThickness
CreateSheetMetalStyle
Here is the FaceAndFoldFeatureCreation function:
// Create sheet metal face and fold features
//Description
//This sample demonstrates the creation of
// sheet metal face and fold features.
public void FaceAndFoldFeatureCreation()
{
// Create a new sheet metal document, using the
//default sheet metal template.
PartDocument oSheetMetalDoc =
(PartDocument)ThisApplication.Documents.Add
(DocumentTypeEnum.kPartDocumentObject,
ThisApplication.FileManager.GetTemplateFile
(DocumentTypeEnum.kPartDocumentObject,
SystemOfMeasureEnum.kDefaultSystemOfMeasure,
DraftingStandardEnum.kDefault_DraftingStandard,
"{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"));
// Set a reference to the component definition.
SheetMetalComponentDefinition oCompDef =
(SheetMetalComponentDefinition)oSheetMetalDoc.
ComponentDefinition;
// Set a reference to the sheet
// metal features collection.
SheetMetalFeatures oSheetMetalFeatures =
(SheetMetalFeatures)oCompDef.Features;
// 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 =
(TransientGeometry)ThisApplication.TransientGeometry;
// Draw a 4cm x 3cm rectangle with the
// corner at (0,0)
oSketch.SketchLines.AddAsTwoPointRectangle
(oTransGeom.CreatePoint2d(0, 0),
oTransGeom.CreatePoint2d(4, 3));
// Create a profile.
Profile oProfile =
(Profile)oSketch.Profiles.AddForSolid();
FaceFeatureDefinition oFaceFeatureDefinition =
(FaceFeatureDefinition)oSheetMetalFeatures.
FaceFeatures.CreateFaceFeatureDefinition(oProfile);
// Create a face feature.
FaceFeature oFaceFeature = default(FaceFeature);
oFaceFeature = oSheetMetalFeatures.FaceFeatures.
Add(oFaceFeatureDefinition);
// Get the top face for creating the new sketch.
// assume that the 6th face is the top face.
Face oFrontFace = default(Face);
oFrontFace = oFaceFeature.Faces[6];
// Create a new sketch on the top face.
PlanarSketch oFoldLineSketch =
(PlanarSketch)oCompDef.Sketches.Add(oFrontFace);
// The end points of the sketch line must
//lie on an edge
Inventor.Point oEdge1MidPoint =
(Inventor.Point)oFrontFace.Edges[1].
Geometry.MidPoint;
Point2d oSketchPoint1 =
(Point2d)oFoldLineSketch.
ModelToSketchSpace(oEdge1MidPoint);
Inventor.Point oEdge2MidPoint =
(Inventor.Point)oFrontFace.Edges[3].
Geometry.MidPoint;
Point2d oSketchPoint2 =
(Point2d)oFoldLineSketch.
ModelToSketchSpace(oEdge2MidPoint);
// Create the fold line between the midpoint
// of two opposite edges on the face
SketchLine oFoldLine =
(SketchLine)oFoldLineSketch.SketchLines.
AddByTwoPoints(oSketchPoint1, oSketchPoint2);
FoldDefinition oFoldDefinition =
(FoldDefinition)oSheetMetalFeatures.
FoldFeatures.CreateFoldDefinition
(oFoldLine, "60 deg");
// Create a fold feature
FoldFeature oFoldFeature =
(FoldFeature)oSheetMetalFeatures.
FoldFeatures.Add(oFoldDefinition);
ThisApplication.ActiveView.GoHome();
}
-Wayne


Subscribe