How do I replicate the Use/Project sketch functionality in FS code?

pmd
pmd Member, Developers Posts: 68 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?
Tagged:

Best Answer

Answers

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,128 image
    Probably the best way to do this would be to extrude the edges as surfaces up to a plane then use the edges created by the surface.
    Senior Director, Technical Services, EMEA
  • pmd
    pmd Member, Developers Posts: 68 PRO
    Still struggling with this. I used suggestion from @NeilCooke to extrude edges as surfaces to the cutting plane and this looks like it will do the projection I want so currently have:


    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.
     
  • pmd
    pmd Member, Developers Posts: 68 PRO
    @Jake_Rosenfeld

    Thanks - that was it. I was searching on "face" rather than "surface"
  • pmd
    pmd Member, Developers Posts: 68 PRO
    I made some progress on this and for simple cases it works fine but need another hint on how to deal with multiple loops since FillSurface returns an error FILL_SURFACE_MULTI_LOOP if feed more than one loop.



    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.