5 Replies Latest reply on Oct 6, 2016 6:46 AM by Josef Kvita

    isSheetMetal() for mirrored parts API

    Josef Kvita



      I've written a function to check, if model is sheet metal, or not. The problem is, when the part is a mirror image of sheet metal part, created in the assembly, the code thinks it's not a sheet metal.


      Can you help me please?


      There is the function.


          public bool IsSheetMetal(ModelDoc2 swModel)


                  PartDoc swPart = default(PartDoc);

                  Body2 swBody = default(Body2);

                  object[] arrBody = null;

                  int i = 0;

                  if (swModel.GetType() != (int)swDocumentTypes_e.swDocPART) return false;

                  swPart = (PartDoc)swModel;

                  arrBody = (object[])swPart.GetBodies2((int)swBodyType_e.swSolidBody, false);



                      foreach (object body in arrBody)


                          swBody = (Body2)body;

                          if (swBody.IsSheetMetal() == true) i = i + 1;


                      if (i > 0) return true;

                      else return false;


                  catch { return false; }


        • Re: isSheetMetal() for mirrored parts API
          Steven Barry

          Josef, here's my advice:

          - Add some debugging lines to be 100% sure the code is failing at "if (swBody.IsSheetMetal() ==true) ...".   Try to rule out any other possible errors  (for example, maybe SolidWorks doesn't recognize those mirrored components as having type swDocPart?  I don't really know)


          - If you have verified that it is indeed that last if statement that is failing, perhaps you will need to formulate another way to detect if a part is sheet metal.  You could try stepping through the feature tree of the component and see if it contains a sheet metal or flat pattern feature or something like that.

          • Re: isSheetMetal() for mirrored parts API
            Keith Rice

            This is also an issue with weldment features. I am aware of three ways that you can try to solve this.


            1. Look at the selections of the pattern (e.g., mirror) feature and see if they belong to a sheet metal feature.
              • Drawback: You can have patterns of patterns, therefore you might have to look multiple levels "deep". A recursive function might be appropriate. You'll also need to handle as many different pattern types as can occur in your models. Mirrors, linear patterns, circular patterns, etc all have different feature data interfaces.
            2. Look at the parents of the mirror feature and see if they are sheet metal features.
              • Drawback: Parent-child relationships aren't going to necessarily tell you what the "main" parent feature is. For example, you could have a body that is not a sheet metal feature, but referenced a sheet metal feature in one of its sketches. The sheet metal feature is still going to be considered a parent, therefore, and your function could return a false positive.
            3. Look at the sub-features of the pattern feature. If a pattern of a sheet metal feature with, then you should be able to identify bend features.
              • Drawback: Sheet metal features do not necessarily have bends, therefore this can return a false negative.


            The first option is the safest but it is also the most time consuming to program if you decide to implement recursion and lots of different pattern types. Even given this first option, though, it's still possible to have features created from a merger of 2+ features, not all of which were sheet metal. Would this still be considered a sheet metal feature? Hence the problem becomes subjective at some point.


            In your case, I would recommend #3 if you're certain that all of your sheet metal features have bends in them. Otherwise, #1.



            SolidWorks API Training and Services