Usage of curve-driven pattern

Hi guys,

does anyone of you has experience in the usage of curve driven pattern?
I am trying to implement this feature but it always returns null. If I use the macro recorder it shows me almost the same code (in VBA) as you can see below - but even that doesn’t work.
Just for further information:
I am selecting 2 edges from a part, converting them into sketch entities with

 Status = SketchManager.SketchUseEdge3(false, false);

and adding a fillet to set them tangent. With this sketch I am trying to patter an extruded cut feature along this (sketch)curve.
As you can see in the code snippet below I am selecting the whole sketch.
The return value of both selection is true.

Do you have any ideas what I am doing wrong? Does I have to select the whole sketch or just an edge@SketchXY?

Thanks in advance!
Marcel

string sketchType = "";
string sketchName = sketchCurve.GetNameForSelection(out sketchType);

bool status = ModelDoc2.Extension.SelectByID2(bohrungPritsche.Name, "BODYFEATURE", 0, 0, 0, true, 4, null, 0);
status = ModelDoc2.Extension.SelectByID2(sketchName, sketchType, 0, 0, 0, true, 1, null, 0);

FeatureManager = ModelDoc2.FeatureManager;
 CurveDrivenPatternFeatureData featData = (CurveDrivenPatternFeatureData)FeatureManager.CreateDefinition((int)swFeatureNameID_e.swFmCurvePattern);
featData.D1AlignmentMethod = (int)swCurveDrivenPatternAlignment_e.swCurvePatternTangentToCurve;
featData.D1IsEqualSpaced = false;
featData.D1ReverseDirection = true;
featData.GeometryPattern = true;
featData.D1CurveMethod = (int)swCurveDrivenPatternCurveMethod_e.swCurvePatternOffsetCurve;
 featData.D1Spacing = 0.075;
featData.D1InstanceCount = 100;
featData.GeometryPattern = true;
Feature featureCurvePattern = FeatureManager.CreateFeature(featData);


@Marcel :

Would be great if you could paste a part here so we can test this?

Unfortunately I am not allowed to post the whole part code here but I’ve set up quick and dirty a small example (usually I am not using hard coding). If you select the via script created curve(sketch) and start the creation of the curve driven pattern manually it works…

    public testPart()
        {
            SldWorks sldWorks = GetSldWorks();
            ModelDoc2 modelDoc2 = (ModelDoc2)sldWorks.NewPart();
            modelDoc2.LengthUnit = (int)swLengthUnit_e.swMM;
            FeatureManager featureManager = (FeatureManager)modelDoc2.FeatureManager;
            SketchManager sketchManager = modelDoc2.SketchManager;
            sketchManager.AddToDB = true;

            bool status = modelDoc2.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0);
            modelDoc2.SketchManager.InsertSketch(true);

            sketchManager.CreateLine(0, 0, 0, 7.8, 0, 0);
            sketchManager.CreateLine(7.8, 0, 0, 7.8, 0.850 / 2, 0);
            sketchManager.CreateLine(7.8, 0.850 / 2, 0, 2.5, 0.85 / 2, 0);
            sketchManager.CreateLine(2.5, 0.85 / 2, 0, 0, 0.6, 0);
            sketchManager.CreateLine(0, 0.6, 0, 0, 0, 0);
            sketchManager.InsertSketch(true);

            Feature sketchFeature = modelDoc2.Extension.GetLastFeatureAdded();
            sketchFeature.Name = "SketchBase";
            modelDoc2.ClearSelection2(true);

            double thickness = 0.008;
            status = modelDoc2.Extension.SelectByID2(sketchFeature.Name, "SKETCH", 0, 0, 0, true, 0, null, 0);
            Feature extrusion = modelDoc2.FeatureManager.FeatureExtrusion3(true, true, false, (int)swEndConditions_e.swEndCondBlind, 0, thickness, 0, false, false, false, false, 0, 0, false, false, false, false, true, true, true, (int)swStartConditions_e.swStartSketchPlane, 0, false);

            extrusion.Name = "Extrusion t=" + (thickness * 1000);
            modelDoc2.ClearSelection2(true);

            status = modelDoc2.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0);
            sketchManager.InsertSketch(true);
            sketchManager.CreateCircleByRadius(0.1, 0.5, 0, 0.0065);
            sketchManager.InsertSketch(true);
            Feature sketch2 = modelDoc2.Extension.GetLastFeatureAdded();
            modelDoc2.ClearSelection2(true);

            status = modelDoc2.Extension.SelectByID2(sketch2.Name, "SKETCH", 0, 0, 0, true, 0, null, 0);
            Feature cut = featureManager.FeatureCut4(false, false, false, (int)swEndConditions_e.swEndCondThroughAll, (int)swEndConditions_e.swEndCondThroughAll, 0, 0, false, false, false, false, 0, 0, false, false, false, false, false, false, true, false, false, false, (int)swStartConditions_e.swStartSketchPlane, 0, false, false);
            cut.Name = "holes platform \u00D8 13";
            modelDoc2.ClearSelection2(true);

            //Creating curve for curve-driven pattern
            status = modelDoc2.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, true, 0, null, 0);
           //    status = modelDoc2.Extension.SelectByID2("Ebene vorne", "PLANE", 0, 0, 0, true, 0, null, 0);
            sketchManager.InsertSketch(true);
            PartDoc part = (PartDoc)modelDoc2;
            object[] bodies = (object[])part.GetBodies2((int)swBodyType_e.swSolidBody, true);
            Body2 body = (Body2)bodies[0];
            object[] edges = (object[])body.GetEdges();
            Curve curve = default;
            Entity entity = default;
            modelDoc2.ClearSelection2(true);
            foreach (Edge item in edges)
            {
                curve = (Curve)item.GetCurve();
                if (curve.IsLine())
                {
                    double[] lineParams = (double[])curve.LineParams;
                    if (lineParams[3] != 0 && lineParams[1] > 0 && lineParams[2] == thickness)
                    {
                        entity = (Entity)item;
                        entity.Select4(true, null);
                    }
                }
            }
            status = sketchManager.SketchUseEdge3(false, false);

            Sketch sketch = sketchManager.ActiveSketch;
            object[] sketchpoints = (object[])sketch.GetSketchPoints2();

            foreach (SketchPoint item in sketchpoints)
            {
                if (item.X == 2.5)
                {
                    item.Select4(true, null);
                    sketchManager.CreateFillet(0.1, (int)swConstrainedCornerAction_e.swConstrainedCornerInteract);
                }
            }
            sketchManager.InsertSketch(true);
            Feature sketchCurve = modelDoc2.Extension.GetLastFeatureAdded();
            sketchCurve.Name = "Curve";

            //Creation of curve driven pattern
            modelDoc2.ClearSelection2(true);
            status = modelDoc2.Extension.SelectByID2(cut.Name, "BODYFEATURE", 0, 0, 0, true, 4, null, 0);
            status = modelDoc2.Extension.SelectByID2(sketchCurve.Name, "SKETCH", 0, 0, 0, true, 1, null, 0);

            CurveDrivenPatternFeatureData featData = (CurveDrivenPatternFeatureData)featureManager.CreateDefinition((int)swFeatureNameID_e.swFmCurvePattern);
            featData.D1AlignmentMethod = (int)swCurveDrivenPatternAlignment_e.swCurvePatternTangentToCurve;
            featData.D1IsEqualSpaced = false;
            featData.D1ReverseDirection = false;
            featData.GeometryPattern = true;
            featData.D1CurveMethod = (int)swCurveDrivenPatternCurveMethod_e.swCurvePatternOffsetCurve;
            featData.D1Spacing = 0.075;
            featData.D1InstanceCount = 100;
            featData.GeometryPattern = true;
            Feature featureCurvePattern = featureManager.CreateFeature(featData);
        }
2 Likes

Give me a couple of days to get this.

Sure - take your time!

1 Like

Sorry for not getting back quick enough. I’m still on this.

Let’s see some of the other smart people here can help you out. @BigCrazyAl @artem @slohmann @Eddy @bnemec @Gupta9665 @Jacob
I will buy someone coffee if this gets answered!

1 Like

@AmenJlili & @Marcel

I tried to get this worked out this morning but stumbled into the limitation for my installation of 2018. It looks like pre-selection and creation of the curve driven pattern wasn’t added until 2020 to the API documentation. This leads me to believe that it will only work for 2020 or later but I am unable to verify that without access to a 2020 install at this time.

I played around with the pre-selection and marks and determined that setting the direction 1 mark to 0 rather than 1 allowed me to manually click on curve-driven-pattern and it accepted the parts that were selected. Setting them as 1 & 4 per the documentation did not work, there was an error indicating that my curve selection was invalid. Please take this with a grain of salt since I’m on 2018 so this may not even apply to you.

From what I can see, you have it set up in a way that makes sense. Perhaps someone with an updated install can get this further along.

1 Like

@BigCrazyAl : I have SW 2020 on my VM if you want to try things over there.

1 Like

Hi Marcel,

The above code is the culprit. But you did what would be expected like @BigCrazyAl mentioned before.

This is one of those cases where the API doesn’t do the same as a manual action. Selecting a sketch manually works for creating the pattern. But not through code.

What you could do is letting the user select an edge, get the tangent edges selected also and then generate the pattern. I tried this approach, but the pattern gets the direction of the last selected edge as can be seen in the next image.
image

The conclusion is that we really need the sketch approach to be able to use curve driven pattern.

So I think we are out of luck and I would suggest to contact your reseller and create an SPR for this. If you do so please post the SPR number back here so we can vote for it and get more attention from SolidWorks.

Unless someone else can solve this :wink:

Eddy

PS : as Alex suggested : using mark 0 instead of 1 didn’t work for me.

Thanks for your support @BigCrazyAl, @Eddy, @AmenJlili.
I’ve promoted the topic to Solidworks and I’m still waiting for their reply.
I will let you know when I have further information…

Hi Marcel,

Thanks for the status update.
Once you have the SPR number, let us know…we will back you up.

Eddy

1 Like

Any updates @Marcel?

not really… Last week I received a message from the API support, with the info that they are working on it, but so far no more…

Hello everyone,
now I’ve got feedback from SW:
They registered a SPR:
SPR 1225611: Feature:: CreateFeature(ICurveDrivenPatternFeatureData) failed to create feature.

If you could vote for it to get more attention from SW would be very nice :wink:

2 Likes