Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
How do I replicate the Use/Project sketch functionality in FS code?
pmd
Member, Developers Posts: 63 PRO
I am trying to write some FS code to flatten sloping faces as part of the cleanup of a 3D model to make it 2.5D for our router. For our purposes we just want pockets with all edges at 90 degrees so if we had a 45degree slope we would just "press it down" until it was flat. The perimeter of the pockets can be any profile (concave or convex).
My current code is here: https://cad.onshape.com/documents/5c235881abd08b64e0f3ebbf/w/7de1890964778476c2f32190/e/1d4ef221139f383005cc307c
It takes a face as input, finds the bounding edges and attempts to construct a sketch on a plane passing through the lowest point on the sketch which is then used for extrude tool followed by boolean subtract.
The problem is I could not work out how to project arbitrary edges down onto a plane - the code only works if all the edges are lines. Put in non-lines like arcs and it breaks - see the last feature call to FlattenSlope2 using the arcs-only sketch.
ilya_baran seemed to say that there was no such functionality:
https://forum.onshape.com/discussion/comment/23557#Comment_23557 but I was hoping this may have changed since then.
I feel that there must be a simple way to do this but have failed to find it.
Any ideas?
My current code is here: https://cad.onshape.com/documents/5c235881abd08b64e0f3ebbf/w/7de1890964778476c2f32190/e/1d4ef221139f383005cc307c
It takes a face as input, finds the bounding edges and attempts to construct a sketch on a plane passing through the lowest point on the sketch which is then used for extrude tool followed by boolean subtract.
The problem is I could not work out how to project arbitrary edges down onto a plane - the code only works if all the edges are lines. Put in non-lines like arcs and it breaks - see the last feature call to FlattenSlope2 using the arcs-only sketch.
ilya_baran seemed to say that there was no such functionality:
https://forum.onshape.com/discussion/comment/23557#Comment_23557 but I was hoping this may have changed since then.
I feel that there must be a simple way to do this but have failed to find it.
Any ideas?
Tagged:
0
Best Answer
-
Jake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646@pmd
Try opFillSurface with all of those boundary edges as "edgesG0"
https://cad.onshape.com/FsDoc/library.html#opFillSurface-Context-Id-map
Jake Rosenfeld - Modeling Team5
Answers
but next question is how do I convert these edges to a solid I can extrude up and then boolean subtract?
https://cad.onshape.com/documents/5c235881abd08b64e0f3ebbf/w/2fa5b31ddd77d8a4ed2bc093/e/1d4ef221139f383005cc307c
I am using qCoincidesWithPlane(extruded_surface_edges, cutting_plane) to extract the 'projected' boundary I want but this query just contains edges and vertices so when extruded I just get surfaces. I have searched for a way to convert edges to faces so I can extrude a solid but not found anything yet.
Try opFillSurface with all of those boundary edges as "edgesG0"
https://cad.onshape.com/FsDoc/library.html#opFillSurface-Context-Id-map
Thanks - that was it. I was searching on "face" rather than "surface"
The red lines are the edges being fed into opFillSurface.
Latest code is:
https://cad.onshape.com/documents/5c235881abd08b64e0f3ebbf/w/2fa5b31ddd77d8a4ed2bc093/e/1ee3512e4a426a5d4b3faf21
I did try looping over each surface created when projecting down to the cutting plane but this does not work since order dependent - in the above case I end up with a circle and and square which then cuts away too much - I really want a square donut shape and the collection of edges I have seems to have no inner/outer structure I could use to order things.