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.

Repeat the function's action for each selection of the UI

ben_partouchben_partouch Member, csevp Posts: 152 PRO
edited February 18 in FeatureScript

I have a simple function to split face using a text. I want to be able to select multiple faces and have the function executed for all of them.

How do I go about it?

Thank you

    // Define the function's action


    var center = evPlane(context, {
            "face" : definition.faceToSplit
        });


    debug(context, center, DebugColor.RED);



    var sketch2 = newSketchOnPlane(context, id + "sketch2", {
            "sketchPlane" : center
        });


    var text = skText(sketch2, "text1", {
            "text" : definition.text,
            "fontName" : "Poppins-Regular.ttf",
            "firstCorner" : vector(0, 0) * inch,
            "secondCorner" : vector((1 * inch), definition.fontSize)
        });

    skSolve(sketch2);

    var textEdges = qSketchRegion(id + "sketch2");
    var loop = qLoopEdges(textEdges);

    debug(context, loop, DebugColor.GREEN);



    opSplitFace(context, id + "splitFace1", {
                "faceTargets" : definition.faceToSplit,
                "edgeTools" : loop

            });



    opDeleteBodies(context, id + "deleteBodies2", {
                "entities" : qCreatedBy(id + "sketch2", EntityType.EDGE)
            });

Comments

  • Jed_YeiserJed_Yeiser Member Posts: 45 PRO
    edited February 18

    I'd recommend looking into using a for loop here - though you may run into challenges for any non-planar face as your code requires a planar face to create a plane which you then sketch on. I'd imagine that WHERE you want to split each face is a fairly specific location and that simply solving for 'a plane' on that face does not get you the resolution you're looking for. I'd recommend something similar to what follows:

    1. Create a Mate connector somewhere (the origin? why not. Doing so makes things easy).
    2. Figure out how many faces you have
    3. For each face:
      1. create a mate connector on the face at the location you'd like to move the sketch edges to
      2. (copy?) transform the of the reference sketch to the new location defined by the mate connector.
      3. split the face as you've done.

    Cheers,

    -j

  • jelte_steur814jelte_steur814 Member Posts: 302 PRO

    try putting the above in a 'forEachEntity'

    https://cad.onshape.com/documents/37fa98fdc1a0b9ce78ff38bb/w/257085d868fb32e6998b6a89/e/11361fdeab998371aea29978

Sign In or Register to comment.