I vaguely remember now seeing this before, but could not recall it when someone asked about it the other day, that Inventor can generate flat pattern for any folded sheet metal model, without having to first create all the related sheet metal features (bend, flange, etc) by hand.
In this case I started with opening a STEP file of the 3D folded sheet metal. When I select "Convert To Sheet Metal" then I need to select the base face for the sheet metal, and then the thickness will be automatically populated with the correct value.
There is no dedicated function in the Inventor API for that very last part about finding out the thickness.
However, we can use things like FindUsingRay() to find the face opposite the one we want to use as the base, and then check the distance between them
There are two ways to open a non-Inventor file: simply use the Documents.Open() function, in which case the file will be converted, or through ComponentDefinition.ImportedComponents, in which case you can also decide to reference the file - see Import AnyCAD documents associatively
When doing this whole thing through the API, then you have to find a way to figure out which face should be used as base. One option could be looking for the largest planar face.
Once you have that you need to find the face opposite that and check the distance between them. That should provide the thickness of the sheet metal.
Here is a VBA sample showing this:
Function GetThickness(sb As SurfaceBody) As Double ' Find biggest face Dim f As Face Dim bf As Face Dim area As Double For Each f In sb.Faces ' Only care about planar faces If TypeOf f.Geometry Is Plane And f.Evaluator.area > area Then Set bf = f area = f.Evaluator.area End If Next ' Find the opposite face Dim p As Plane Set p = bf.Geometry Dim pt1 As Point Set pt1 = bf.PointOnFace Dim tr As TransientGeometry Set tr = ThisApplication.TransientGeometry Dim objs As ObjectsEnumerator Dim pts As ObjectsEnumerator Dim n As UnitVector ' We have to search in the opposite direction ' of the face's normal vector If bf.IsParamReversed Then
Set n = p.Normal
Else
Set n = tr.CreateUnitVector( _
-p.Normal.x, -p.Normal.y, -p.Normal.z)
End If ' objs(2) should be the opposite face ' but we do not need it, the intersection point ' is enough, i.e. pts(2) Call sb.FindUsingRay(pt1, n, 0, objs, pts) ' The first point found will be on the same face ' The second one will be on the face opposite Dim pt2 As Point Set pt2 = pts(2) GetThickness = pt1.DistanceTo(pt2) End Function Sub ConvertToSheetMetal() Dim path As String: path = "C:\Temp\SheetMetal_0.05in.stp" Dim doc As PartDocument Set doc = ThisApplication.Documents.Open(path) ' Turn it into a sheet metal part doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Dim cd As SheetMetalComponentDefinition Set cd = doc.ComponentDefinition cd.UseSheetMetalStyleThickness = False cd.Thickness.Value = GetThickness(cd.SurfaceBodies(1)) Call cd.Unfold End Sub
And the result:
If the part is not really a folded sheet metal, then though the Unfold "succeeds", the body of the "Folded Model" and the "Flat Pattern" will be the same.
You can test this by comparing the bodies:
Sub TestFlatPattern() Dim doc As PartDocument Set doc = ThisApplication.ActiveDocument Dim cd As SheetMetalComponentDefinition Set cd = doc.ComponentDefinition Dim tr As TransientBRep Set tr = ThisApplication.TransientBRep Dim objs As ObjectCollection Set objs = ThisApplication.TransientObjects.CreateObjectCollection Call objs.Add(cd.SurfaceBodies(1)) Call objs.Add(cd.FlatPattern.SurfaceBodies(1)) Set objs = tr.GetIdenticalBodies(objs) If objs.Count > 0 Then MsgBox ("The flat pattern body is the same as the original body") End If End Sub
-Adam