Dividing an edge in featurescript
stefan_nilsson
Member Posts: 13 ✭✭
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
Tagged:
0
Answers
-
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
▚▞▚▞▚▞▚▞▚0 -
Michael's is exactly what I'd do. A few thoughts:
- 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.
- If you want to be able to pick multiple edges at once to process, put everything Michael shows except "pointLocationsArray" inside a forEachEntity () function.
0

