Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Query a face created by opExtrude

ben_harkinben_harkin Member Posts: 8 EDU
I'm new to featurescript and I'm making a feature that creates standard metal extrusions. Which should look like this as a final product:

I want to query a face which is created from a sketch by opExtrude:

The sketch is built from 3 rectangles and 4 elliptical arcs which connect their ends:

I want to create rounded-corner square holes through the highlighted face. I was going to query the face to use as a sketch plane, then build the holes from 4 lines and 4 corner arcs, but I my attempts at making a query for this have failed.
I saw a potential solution on the forums using tracking queries and I tried something like this:
...

skSolve(profileSketch);

var fromTrackingLine = startTracking(context, id + "profileSketch", "faceTrackLine");
opExtrude(context, id + "baseExtrude", {...});

debug(context, evaluateQuery(context, fromTrackingLine), DebugCOlor.RED);

...
faceTrackLine is a line I added on the sketch which should correspond to the face:

However, the debug always returns an empty array. I was going to try enabling trackPartialDependency for startTracking but there is no example for that form of startTracking so I was stumped.
My featurescript source is available here in the Simplified Metal Gen feature studio.

Comments

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,683
    That should work, looks like the example from the help https://cad.onshape.com/FsDoc/library.html#startTracking-Context-map

    Could it be that you spelt DebugColor wrong?
    Senior Director, Technical Services, EMEAI
  • ben_harkinben_harkin Member Posts: 8 EDU
    Unfortunately, that was just an error when I was copying over my code to the post. Maybe it doesn't work because I created the rectangle first with skRectangle, then added a line to track with skLine?
    This is the function which I'm calling to do this, note that some regions are commented out
    function genCChannel(context is Context, id is Id, thickness is ValueWithUnits, width is number, length is number)
    precondition
    {
        isInteger(width, POSITIVE_COUNT_BOUNDS);
        thickness > 0;
        isReal(length, HOLE_REAL_BOUNDS);
    }
    {
        var profileSketch = newSketch(context, id + "profileSketch", {
                "sketchPlane" : qCreatedBy(makeId("Front"), EntityType.FACE)
            });
    
        var baseSegmentLength is ValueWithUnits = (0.5 * width - 0.318 + 0.065 * 2) * inch;
        var innerRadius is ValueWithUnits = 0.032 * inch;
        var outerRadius is ValueWithUnits = 0.094 * inch;
        var flangeSize is ValueWithUnits = 0.456 * inch;
    
        skRectangle(profileSketch, "baseRectangle", {
                    "firstCorner" : vector(-baseSegmentLength / 2, 0 * inch),
                    "secondCorner" : vector(baseSegmentLength / 2, thickness)
                });
        skLineSegment(profileSketch, "faceTrackLine", {
                    "start" : vector(-baseSegmentLength / 2, thickness),
                    "end" : vector(baseSegmentLength / 2, thickness)
                });
        skEllipticalArc(profileSketch, "innnerArcL", {
                    "center" : vector(-baseSegmentLength / 2, thickness + innerRadius),
                    "majorAxis" : normalize(vector(0, 1)),
                    "minorRadius" : innerRadius,
                    "majorRadius" : innerRadius,
                    "startParameter" : 0.25,
                    "endParameter" : 0.5
                });
        skEllipticalArc(profileSketch, "outerArcL", {
                    "center" : vector(-baseSegmentLength / 2, outerRadius),
                    "majorAxis" : normalize(vector(0, 1)),
                    "minorRadius" : outerRadius,
                    "majorRadius" : outerRadius,
                    "startParameter" : 0.25,
                    "endParameter" : 0.5
                });
        skEllipticalArc(profileSketch, "innnerArcR", {
                    "center" : vector(baseSegmentLength / 2, thickness + innerRadius),
                    "majorAxis" : normalize(vector(0, 1)),
                    "minorRadius" : innerRadius,
                    "majorRadius" : innerRadius,
                    "startParameter" : 0.5,
                    "endParameter" : 0.75
                });
        skEllipticalArc(profileSketch, "outerArcR", {
                    "center" : vector(baseSegmentLength / 2, outerRadius),
                    "majorAxis" : normalize(vector(0, 1)),
                    "minorRadius" : outerRadius,
                    "majorRadius" : outerRadius,
                    "startParameter" : 0.5,
                    "endParameter" : 0.75
                });
        skRectangle(profileSketch, "flangeRectangleL", {
                    "firstCorner" : vector(-baseSegmentLength / 2 - outerRadius, outerRadius),
                    "secondCorner" : vector(-baseSegmentLength / 2 - outerRadius + thickness, flangeSize)
                });
        skRectangle(profileSketch, "flangeRectangleR", {
                    "firstCorner" : vector(baseSegmentLength / 2 + outerRadius, outerRadius),
                    "secondCorner" : vector(baseSegmentLength / 2 + outerRadius - thickness, flangeSize)
                });
        skSolve(profileSketch);
    
        var fromTrackingLine = startTracking(context, id + "profileSketch", "faceTrackLine");
        /*opExtrude(context, id + "baseExtrude", {
           "entities" : qSketchRegion(id + "profileSketch"),
           "direction" : evOwnerSketchPlane(context, {"entity" : qSketchRegion(id + "profileSketch")}).normal,
           "endBound" : BoundingType.BLIND,
           "endDepth" : length * 0.5 * inch
           });*/
    
        /*
           opDeleteBodies(context, id + "deleteProfileSketch", {
           "entities" : qCreatedBy(id + "profileSketch", EntityType.BODY)
           });*/
           
        debug(context, evaluateQuery(context, fromTrackingLine), DebugColor.RED);
        /*var holeSketch = newSketch(context, id + "holeSketch", {
           "sketchPlane" : evaluateQuery(context, fromTrackingLine)
           });
           skEllipticalArc(holeSketch, "cornerArc1", {
           "center" : vector(-baseSegmentLength / 2 + 0.065 * inch, 0.159 * inch),
           "majorAxis" : normalize(vector(0, 1)),
           "minorRadius" : 1 * inch,
           "majorRadius" : 2 * inch,
           "startParameter" : 0,
           "endParameter" : 0.25
           });*/
    
    }

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,683
    Well, yes. The extrude uses the region which belongs to the skRectangle. You know, programatically, where the line is, so save yourself some effort and just use qContainsPoint with qNonCapEntity.
    Senior Director, Technical Services, EMEAI
  • ben_harkinben_harkin Member Posts: 8 EDU
    I did that and now it works. I was able to make my sketch plane. However, nothing shows via debug (the face doesn't turn red).
    debug(context, evaluateQuery(context, qNonCapEntity(id + "baseExtrude", EntityType.FACE)->qContainsPoint(vector(0 * meter, 0 * meter, thickness))), DebugColor.RED);
    
    The query is correct, but no highlighting.
  • ben_harkinben_harkin Member Posts: 8 EDU
    I removed the evaluateQuery from debug and now the face is highlighting properly.
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,683
    I removed the evaluateQuery from debug and now the face is highlighting properly.
    Excellent! There's always a way...
    Senior Director, Technical Services, EMEAI
  • Alex_KempenAlex_Kempen Member Posts: 248 EDU
    Hello,
    I personally happen to have a few solutions for VEX C-channel which are both in active development and which I've employed in the past.
    Here's a (somewhat old) feature I wrote which allows us to quickly derive VEX C channel along sketch edges. It might be easier to use (and more feature complete) than writing your own.
    https://cad.onshape.com/documents/6a4c34c32c5e682a7255943c/w/b0d6114e5fd1de57c398df5f/e/729d68c86586f8f213b69b4b

    I'm also currently working on a new version of my channel generator which will be more performant and support surface representations.

    The current version pulls the c-channel from my team's vex library, which can be found here:

    If your team would like to adopt our CAD library, we'd be happy to work with you to add whatever is needed to it/collaborate and make it better - it's exciting to know other VEX teams are also considering using Onshape for their designs.

    Thanks,
    Alex Kempen







    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



Sign In or Register to comment.