Generating a sheet metal part from a sketch with multiple profiles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a layout of parts that I want to generate a list of parts from (warning, some will be adjacent so at some point I need to figure out a way to tell inventor to differentiate the profile between two profiles that share a dividing line). The goal is at the end that I will be able to layout an unknown number of parts in an autocad layout with an unknown number of cuts and that I will be able to separate the part boundaries and the cut boundaries by layer, go through and generate each individual part and put the appropriate cuts into it, then place each one in the appropriate place in an assembly.
The part boundaries may not be polylines, so going in, the program will have no idea where each individual boundary is.
I have three issues so far.
1. These profiles are not always rectangular. I need to be able to derive them from individual lines, which apparently throws my program a problem if I add sketch lines by two points instead of adding a rectangle.
2. I need to define which of the profiles I want to use. All of the codes I've seen thus far call to set the profile to default, but if I do that it selects all profiles. I've attempted indexing it every way I know how (Index at 0, 1, Count, or Count -1) but it throws an error each time.
3. The warning earlier where sometimes two profiles may share a dividing line. In the past when I've defined a face with two separate areas that share a border between them rather than having a border for each one, it will ignore the dividing line and count the entire thing as one face.
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Editor Ed = acDoc.Editor; // Starting transaction using (Autodesk.AutoCAD.DatabaseServices.Transaction trans = acCurDb.TransactionManager.StartTransaction()) { Inventor.Application iApp = (Inventor.Application)Program_Functions.Application_Controls.LaunchInventor(); PartDocument oPartDoc = (PartDocument)iApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, "C:\\Work\\Designs\\Templates\\2013\\Inventor Templates\\Imperial\\Sheet Metal Part (Imperial).ipt", true); SheetMetalComponentDefinition oCompDef = (SheetMetalComponentDefinition)oPartDoc.ComponentDefinition; SheetMetalFeatures oSheetFeatures = (SheetMetalFeatures)oCompDef.Features; oPartDoc.Save(); oPartDoc.Activate(); //Figure out which command is Iprops! //iApp.CommandManager.ControlDefinitions["C:IPROP_START"].Execute(); Inventor.PropertySet DocProps = oPartDoc.PropertySets["Inventor User Defined Properties"]; DocProps.Add("0.250A36", "Material Code", 38); DocProps.Add("PLATE ASTM A36 0.250 IN. 10.21 LB/FT", "Raw Material Description", 39); oCompDef.ActiveSheetMetalStyle.Name.Equals("PLATE ASTM A36 0.250 IN. 10.21 LB/FT"); PlanarSketch oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[3]); List<Inventor.Point2d> PlateBoundaries1 = new List<Inventor.Point2d>(); List<Inventor.Point2d> PlateBoundaries2 = new List<Inventor.Point2d>(); PlateBoundaries1.Add(iApp.TransientGeometry.CreatePoint2d(0, 0)); PlateBoundaries1.Add(iApp.TransientGeometry.CreatePoint2d(5, 0)); PlateBoundaries1.Add(iApp.TransientGeometry.CreatePoint2d(5, 5)); PlateBoundaries1.Add(iApp.TransientGeometry.CreatePoint2d(0, 5)); PlateBoundaries2.Add(iApp.TransientGeometry.CreatePoint2d(10, 0)); PlateBoundaries2.Add(iApp.TransientGeometry.CreatePoint2d(15, 0)); PlateBoundaries2.Add(iApp.TransientGeometry.CreatePoint2d(15, 5)); PlateBoundaries2.Add(iApp.TransientGeometry.CreatePoint2d(10, 5)); int ProfileTotal = 0; for (int i = 0; i <= PlateBoundaries1.Count-1; i++) { int j = i + 1; if (j == PlateBoundaries1.Count) { j = 0; } oSketch.SketchLines.AddByTwoPoints(PlateBoundaries1[i], PlateBoundaries1[j]); } for (int i = 0; i <= PlateBoundaries2.Count - 1; i++) { int j = i + 1; if (j == PlateBoundaries2.Count) { j = 0; } oSketch.SketchLines.AddByTwoPoints(PlateBoundaries2[i], PlateBoundaries2[j]); } Profile PlateProfile = oSketch.Profiles[oSketch.Profiles.Count]; PlateProfile = oSketch.Profiles.AddForSolid(); FaceFeatureDefinition oFaceFeatureDefinition = (FaceFeatureDefinition)oSheetFeatures.FaceFeatures.CreateFaceFeatureDefinition(PlateProfile); FaceFeature oFaceFeature = (FaceFeature)oSheetFeatures.FaceFeatures.Add(oFaceFeatureDefinition);
}