6 Replies Latest reply on Aug 5, 2015 2:09 AM by Neil Jackson

    Silhouette of a solid body projected on a face

    Brandon Massoni

      How to select a body and have it's silhouette (outline) projected onto a face or plane as a sketch? This discussion was previously in a non-API forum, but I'd like to take a crack at the API code. Here is the original discussion <https://forum.solidworks.com/message/424740#424740>. The best idea the discussion had was to use parting surfaces, but you have to select all the parting line loops manually.


      My idea is this:

      1. Create sketch on plane

      2. Select all edges

      3. Use convert entities to convert all the edges to sketch lines

      4. Extrude, selecting all the closed loops in the sketch

      5. Create a second sketch on plane

      6. Use convert entities to convert the largest face of the new extrusion to sketch lines -> This is the silhouette!


      My first coding attempt is pretty broken (attached):

      1. Not all the edges can be converted using "swSketchMgr.SketchUseEdge False", since some of the edges are normal to the plane

      2. I tried to use "swSketch.GetSketchContours" to select all the contours in the sketch, but this does not work.

      3. I tried to set the body from the extrusion (which was not merged)  "swBody = swFeat.GetBody", but this also does not work.


      I will update as I progress, but in advance, thanks to those of you who help.



      PS. if you'd like SolidWorks to do this in new versions, please vote on: SPR 627869: Ability to select a body and have it's shadow (silhouette) projected onto a face or plane (reference, outline, split line, new sketch)

        • Re: Silhouette of a solid body projected on a face
          Brandon Massoni

          Turns out SolidWorks help actually has a really good example. With a little editing, the attached code now draws an outline of the body(s) on either the X,Y, or Z plane. The sketch plane is dependent on the normal of the face you've selected. But I doubt this will capture curved surfaces if drawn at an off-axis plane. The next step is to figure out how to sketch the outline on a user created plane.

            • Re: Silhouette of a solid body projected on a face
              Keith Parker

              Thanks for putting the work in Brandon ...  I'll give this macro a go as soon as I can.  One thing that this may help with as well is the ability to select all edges of a face to use as a sketch; normal operation of the Convert Entities function only converts the 'outside' edges (I know you can Cntrl-select other regions), not all edges.


              Cheers, Keith

                • Re: Silhouette of a solid body projected on a face
                  Brandon Massoni

                  Ok, I modified the code from "API help" to now sketch the outline on either a face or plane that is selected. I think it works for silhouette edges as well, but I'm curious if anyone has a part it won't work on.

                    • Re: Silhouette of a solid body projected on a face
                      Brandon Massoni

                      The GetBodyOutline2.swp file may work for simpler shapes, but it created an absolutely terrible sketch when I tried a shape with cavities in the direction normal to the plane.  The "IModeler::GetBodyOutline2" method selects curves, extracts the endpoints, and draws a line between the points (therefore converting circular edges into straight lines). I am going back to my other method (based on converting all edges onto a sketch), which is a bit further along now (attached). It's issues are currently:


                      1. How to add relevant silhouette edges to selection

                      2. How to extrude after all regions are selected OR BETTER how to remove all the inner lines from the sketch


                      Thanks in advance,


                        • Re: Silhouette of a solid body projected on a face
                          Simon Turner

                          I had a need for something similar, so I finished off this macro.

                          It really only needed the sketch regions selected with zero as a mark.

                          I have left the extrusion as using the entire collection of sketch regions rather than getting the resulting face, deleting the extrusion and re-extruding the outer boundary. It seems to work OK as it is.

                          I changed it to use a reference plane rather than a face, and have made it extrude to the extents of the model (+1mm in the first direction, because that is what I needed).



                  • Re: Silhouette of a solid body projected on a face
                    Neil Jackson

                    Very clever solution!  This certainly works for any solid for which each face is planar, and even for a great many solids that have some non-planar faces.   However, this method fails to extract the edges of the shadow cast by certain rounded faces.  For instance, this method would have trouble finding the outline of the shadow of a sphere.


                    One way to work-around this limitation (admittedly a bit of a hack) would be to convert the surface into a triangular mesh (as if you had exported the solid to an stl file and then imported the stl file as a solid body (the solidworks API may offer a more straightforward to do such a conversion)), and then apply the technique to the triangular mesh.


                    I reckon that the curves generated by the SldWorks.Modeler.GetBodyOutline2() function are very nearly what your technique would produce if you were to triangularize the solid before applying your technique.