Getting sheet metal folder of parts

I have two extension methods to return sheet metal folder of a part. The problem is that for some files it does not find the sheet metal folder but for some parts it works. I know that the parts that don’t get the same results were made with solidworks 2018 originally.Processing: Part12.SLDPRT…
part12.sldprt
Handle.sldprd

**//-----------These do not yield the same for the Handle.sldprt. 
//--------------But works for Part12.sldprt**
        /// <summary>
        /// Get flat patterns of the part document if there is any
        /// </summary>
        /// <param name="part">the sheet metal modelDoc2 object</param>
        /// <returns>an array of objects castable to <see cref="Feature"/> </returns>
        public static object[] GetFlatPatterns(this PartDoc part)
        {
            ModelDoc2 model = part as ModelDoc2;
            if (model == null)
                return null;
            var featureMgr = model.FeatureManager;
            var flatPatternFolder = (FlatPatternFolder)featureMgr.GetFlatPatternFolder();
            if (flatPatternFolder == null) return null;
            object[] flatPatterns = (object[])flatPatternFolder.GetFlatPatterns();
            return flatPatterns;
        }

        /// <summary>
        /// gets the sheetMetal Features of this part document fi there is any
        /// </summary>
        /// <param name="part">the sheet metal modelDoc2 or PartDoc object</param>
        /// <returns>an array of objects castable to <see cref="Feature"/></returns>
        public static object[] GetSheetMetals(this PartDoc part)
        {
            ModelDoc2 model = part as ModelDoc2;
            if (model == null)
                return null;
            var featureMgr = model.FeatureManager;
            SheetMetalFolder sheetMetalFolder = featureMgr.GetSheetMetalFolder() as SheetMetalFolder;
            if (sheetMetalFolder == null) 
                return null;
            return (object[])sheetMetalFolder.GetSheetMetals();
        }

You found another great example of the docs not explaining what a particular object actually is.

The docs for both interfaces mention multibody parts and it looks like multibody parts get this Shee-Metal folder:
image

Whereas the single-body part only has a sheet metal feature, no sheet metal folder:
image

I guess that is the real difference? I would use the flat pattern folder if I were you, that thing is always there :slight_smile:

1 Like

What are you ultimately needing with the sheet metal folder or items within? Perhaps there’s a different way to access what you’re looking for that is more reliable.

I was hoping to simply detect if a part is made with sheet metal or not. Which I managed to do by calling ‘ IBody2.ISheetMetal’ instead. But accessing these folder inside the part design tree is necessary to read some of the sheet metal feature data.
I Peter explained what the problem is, so I’ll look into it later today then update this thread

You check whether the part is a sheet metal part or not using IModelDoc2::GetBendState method.

2 Likes

That’s a neat workaround, I hadn’t thought to use that. Thanks for the tip!

Thanks @nilesh I think this is the fastest way to check if a part is sheet metal.

1 Like

Yes you’re right this is the root cause of the problem. I managed to get the “SheetMetal” feature of both files.

Interesting, I always did it via the body method Hamed mentioned as well.

1 Like

@nilesh is the boss :sunglasses:

1 Like

:rofl: :rofl: :rofl:

Thanks mate…!