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.

Options

Dividing an edge in featurescript

stefan_nilssonstefan_nilsson Member Posts: 7 ✭✭
edited March 2023 in Community Support
I want to place a specified number of sketch points on even intervals along an edge in featurescript. I have done the slot tutorial but i need more understanding on these subjects:
Determining the length of an edge in featurescript
placing an sketchpoint on the edge in featurescript.

It would be great i i was able to extend this beyond lines to arcs and splines

Answers

  • Options
    MichaelPascoeMichaelPascoe Member Posts: 1,713 PRO
    edited March 2023

    Hi @stefan_nilsson.

    Is there a particular reason you want sketch points? This could also be done with opPoint(). Regardless, here is a workflow that could still be applied:
    • Create variable or constant storing an array with all of the parameter locations you would like. 0 is the start of the edge, 1 is the end. Think of these like percentages along an edge.
    • Use evEdgeTangentLines() to evaluate the edge you choose at the parameter locations specified in the array.
    • Loop through each evaluated line and create a point at the lines origin with opPoint(). Alternatively, you could be creating sketch points here, but if your goal is just points along an edge, then this might be better.
            const pointLocationsArray = [0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1];
    
            const lines = evEdgeTangentLines(context, {
                        "edge" : definition.edge,
                        "parameters" : pointLocationsArray
                    });
    
            for (var i = 0; i < size(lines); i += 1)
            {
                opPoint(context, id + i + "point1", {
                            "point" : lines[i].origin
                        });
            }

    https://cad.onshape.com/documents/cd8ab450b2d559505a8ab7ca/w/7ee16799b54ab47bdbdf00f4/e/2d1b397c1048565b558bde16?renderMode=0&leftPanel=false&uiState=640f0f268382c54ad0a246f0



    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • Options
    Evan_ReeseEvan_Reese Member Posts: 2,064 PRO
    Michael's is exactly what I'd do. A few thoughts:
    1. If you want to easily set the number of points, don't hard code the parameter array. Use range(0,1,definition.myDivisionCount + 2). The +2 is there since you need to account for the endpoints.
    2. If you want to be able to pick multiple edges at once to process, put everything Michael shows except "pointLocationsArray" inside a forEachEntity () function.
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
Sign In or Register to comment.