SectionTwistSweep C# API

SectionTwistSweep C# API

Anonymous
Not applicable
471 Views
1 Reply
Message 1 of 2

SectionTwistSweep C# API

Anonymous
Not applicable

Hello.

I am trying to make sweep function with section twisted sweep. (like Helical Gear)

I made below codes but got runtime error at last line.

(Commented lines are my challenges but not worked)

I attach twisted sweep feature result by manual operation.

 

Sketch3D oSketch3D = oPartDoc.ComponentDefinition.Sketches3D.Add();
Point stPoint = oTransGeom.CreatePoint(0, 0, 0);
Point endPoint = oTransGeom.CreatePoint(0, 0, 10);
SketchLine3D oLine = oSketch3D.SketchLines3D.AddByTwoPoints(stPoint, endPoint);
Path oPath = oCompDef.Features.CreatePath(oLine);
PlanarSketch oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[3]);
SketchEntitiesEnumerator oRectangle = oSketch.SketchLines.AddAsTwoPointRectangle(oTransGeom.CreatePoint2d(1, 1), oTransGeom.CreatePoint2d(4, 3));

Profile oProfile = oSketch.Profiles.AddForSolid();

SweepDefinition sweepDef = oCompDef.Features.SweepFeatures.CreateSweepDefinition(SweepTypeEnum.kPathAndSectionTwistSweepType, oProfile, oPath, PartFeatureOperationEnum.kJoinOperation);

sweepDef.TwistAngle = Math.PI / 2.0;
//ObjectCollection oCollectionPt = ThisApplication.TransientObjects.CreateObjectCollection();
//oCollectionPt.Add(stPoint);
//ObjectCollection oCollectionVec = ThisApplication.TransientObjects.CreateObjectCollection();
//UnitVector dirVec = oTransGeom.CreateUnitVector(0, 0, 1);
//oCollectionVec.Add(dirVec);
//sweepDef.SetSectionTwists(oCollectionPt, oCollectionVec);
oCompDef.Features.SweepFeatures.Add(sweepDef);

 

Is there anybody have solution?

 

0 Likes
Accepted solutions (1)
472 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

So I found a couple things. 

 

 

oCompDef.Features.SweepFeatures.CreateSweepDefinition(SweepTypeEnum.kPathAndSectionTwistSweepType, oProfile, oPath, PartFeatureOperationEnum.kJoinOperation);

 

 

I changed PartFeatureOperationEnum.kJoinOperation to PartFeatureOperationEnum.kNewBodyOperation, because I assume you are trying to make new solid with this.

Also changed SweepTypeEnum.kPathAndSectionTwistSweepType to SweepTypeEnum.kPathSweepType, because in the API documents it says sweepDef.TwistAngle is only applicable when using kPathSweepType.

 

I completely removed where you were creating object collections to add to sweepDef.SetSectionTwists(oCollectionPt, oCollectionVec) because the API docs say sweepDef.SetSectionTwists is only applicable when using kPathAndSectionTwistSweepType.

 

 I used a website to convert your code to VB.NET and back to C# so let me know if there are problems

 

 

 

PartDocument oPartDoc = ThisDoc.Document;
    ComponentDefinition oCompDef = oPartDoc.ComponentDefinition;
    TransientGeometry oTransGeom = ThisApplication.TransientGeometry;


    Sketch3D oSketch3D = oPartDoc.ComponentDefinition.Sketches3D.Add();
    Point stPoint = oTransGeom.CreatePoint(0, 0, 0);
    Point endPoint = oTransGeom.CreatePoint(0, 0, 10);
    SketchLine3D oLine = oSketch3D.SketchLines3D.AddByTwoPoints(stPoint, endPoint);
    Path oPath = oCompDef.Features.CreatePath(oLine);
    PlanarSketch oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3));
    SketchEntitiesEnumerator oRectangle = oSketch.SketchLines.AddAsTwoPointRectangle(oTransGeom.CreatePoint2d(1, 1), oTransGeom.CreatePoint2d(4, 3));
    Profile oProfile = oSketch.Profiles.AddForSolid();
    SweepDefinition sweepDef = oCompDef.Features.SweepFeatures.CreateSweepDefinition(SweepTypeEnum.kPathSweepType, oProfile, oPath, PartFeatureOperationEnum.kNewBodyOperation);
    sweepDef.TwistAngle = Math.PI / 2.0;

    oCompDef.Features.SweepFeatures.Add(sweepDef);

 

 

 

0 Likes