Extrude through the sketch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hii....I have one step file which include cube with hole and I want to modify my hole like the water drop shape.I have tried it through two methods.
Method 1 :
PartDocument part = (PartDocument)mApplication.ActiveDocument;
PartComponentDefinition partDef = part.ComponentDefinition;
SelectSet oSS = part.SelectSet;
oSS.Clear();
HighlightSet oHSet = part.CreateHighlightSet();
Face face = partDef.SurfaceBodies[1].Faces[7];
PlanarSketch sketch = partDef.Sketches.Add(partDef.WorkPlanes[3]);
Inventor.TransientGeometry tg = mApplication.TransientGeometry;
Edge test = face.Edges[1];
Vertex v1 = test.StartVertex;
Cylinder cylinder = face.Geometry as Cylinder;
double radius = cylinder.Radius;
double angle = Math.PI * 50 / 180; //49.52
Point2d p1 = tg.CreatePoint2d(v1.Point.X -radius, v1.Point.Y);
double x1 = p1.X+ radius * Math.Cos((Math.PI / 2) - angle);
double y1 = p1.Y+ radius * Math.Sin((Math.PI / 2) - angle);
double x2 = p1.X+radius * Math.Cos((Math.PI /2)+angle);
double y2 = p1.Y +radius * Math.Sin((Math.PI / 2) + angle);
double distance = radius / (Math.Cos(angle));
double x3 = p1.X;
double y3 = p1.Y + distance ;
Inventor.SketchLines lines = sketch.SketchLines;
Inventor.SketchLine line1 = lines.AddByTwoPoints(tg.CreatePoint2d(x1, y1), tg.CreatePoint2d(x3, y3));
Inventor.SketchLine line2 = lines.AddByTwoPoints(tg.CreatePoint2d(x3, y3), tg.CreatePoint2d(x2, y2));
Inventor.SketchLine line3 = lines.AddByTwoPoints(tg.CreatePoint2d(x2, y2), tg.CreatePoint2d(x1, y1));
Profile profile = sketch.Profiles.AddForSolid();
ExtrudeDefinition extrudeDef = partDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kCutOperation);
extrudeDef.SetDistanceExtent(1, PartFeatureExtentDirectionEnum.kPositiveExtentDirection);
ExtrudeFeature extrude = (ExtrudeFeature)partDef.Features.ExtrudeFeatures.Add(extrudeDef);
Here I got error like this
Method 2:
PartDocument part = (PartDocument)mApplication.ActiveDocument;
PartComponentDefinition partDef = part.ComponentDefinition;
SelectSet oSS = part.SelectSet;
oSS.Clear();
HighlightSet oHSet = part.CreateHighlightSet();
Face face = partDef.SurfaceBodies[1].Faces[7];
PlanarSketch sketch = partDef.Sketches.Add(partDef.WorkPlanes[3]);
Inventor.TransientGeometry tg = mApplication.TransientGeometry;
Edge test = face.Edges[1];
Vertex v1 = test.StartVertex;
Cylinder cylinder = face.Geometry as Cylinder;
double radius = cylinder.Radius;
double angle = Math.PI * 50 / 180; //49.52
Point2d p1 = tg.CreatePoint2d(v1.Point.X -radius, v1.Point.Y);
double x1 = p1.X+ radius * Math.Cos((Math.PI / 2) - angle);
double y1 = p1.Y+ radius * Math.Sin((Math.PI / 2) - angle);
double x2 = p1.X+radius * Math.Cos((Math.PI /2)+angle);
double y2 = p1.Y +radius * Math.Sin((Math.PI / 2) + angle);
double distance = radius / (Math.Cos(angle));
double x3 = p1.X;
double y3 = p1.Y + distance;
Inventor.SketchLines lines = sketch.SketchLines;
Inventor.SketchLine line1 = lines.AddByTwoPoints(tg.CreatePoint2d(x1, y1), tg.CreatePoint2d(x3, y3));
Inventor.SketchLine line2 = lines.AddByTwoPoints(tg.CreatePoint2d(x3, y3), tg.CreatePoint2d(x2, y2));
Inventor.SketchLine line3 = lines.AddByTwoPoints(tg.CreatePoint2d(x2, y2), tg.CreatePoint2d(x1, y1));
ObjectCollection oc = mApplication.TransientObjects.CreateObjectCollection(lines);
Inventor.Path ob = partDef.Features.CreateSpecifiedPath(oc);
SurfaceBody SrfBod = partDef.SurfaceBodies[1];
SplitFeature oSplitFeature = partDef.Features.SplitFeatures.TrimSolid(ob, SrfBod);
Here I got exception like this
And I want the output like this
Can anyone suggest the sample code to do this.