Extrude through the sketch

Extrude through the sketch

supriya_chaugule
Contributor Contributor
315 Views
3 Replies
Message 1 of 4

Extrude through the sketch

supriya_chaugule
Contributor
Contributor

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

supriya_chaugule_0-1686551391252.png

 

 

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

supriya_chaugule_1-1686551801057.png

And I want the output like this

supriya_chaugule_2-1686551941465.png

Can anyone suggest the sample code to do this.

 

0 Likes
316 Views
3 Replies
Replies (3)
Message 2 of 4

talha.tufan523TD
Advocate
Advocate

I think Inventor is not considering the lines for extrusion as closed. Even though it may seem mathematically correct, I believe it leads to an error. I'm not completely sure, but I think adding this line to your code by merging the points might solve the issue. After the sketching process is complete, you can call this function for the lines.

private void MergeSketchPoints(Inventor.SketchPoint sketchPoint1, Inventor.SketchPoint sketchPoint2)
{
    if (!sketchPoint1.Geometry.IsEqualTo(sketchPoint2.Geometry))
    {
        sketchPoint1.Merge(sketchPoint2);
    }
}




0 Likes
Message 3 of 4

NemKumar
Enthusiast
Enthusiast

@talha.tufan523TD  unfortunately it is not working, but is there any way where we check if our sketch is closed loop ? 

0 Likes
Message 4 of 4

talha.tufan523TD
Advocate
Advocate

Yeah, at start forget  to extrude  just draw  sketch with this codes first part then you can try manualy extrude, if the issue is this situatiion. You must use to parametric shape and then push the  parameters  with api. İ just wonderig, what is your main goal? Why are u using api with this part ?  Maybe its easüer with parametric design 

0 Likes