I believe that those two iLogic snippets for getting flat pattern size target the 'active' document, which in this case would be the main assembly, and they don't appear to have an option that would allow you to specify a different component name or document name for them to target. So, the next path to get those numbers is by stepping down through the normal Inventor API objects until we get to them. They are two of the properties of the actual FlatPattern object, which is under the special SheetMetalComponentDefinition object, and acts like its own special type of ComponentDefinition.
Here is an alternate iLogic rule you can use. You may, or may not have to convert the units of the resulting values returned, depending on your needs.
Sub main
Dim oAssDoc As AssemblyDocument = ThisDoc.Document
Dim oDoc As Document
Dim BoxLength, BoxWidth As Double
For Each oDoc In oAssDoc.AllReferencedDocuments
If oDoc.DocumentType = kPartDocumentObject And oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'sheet metal part'
Dim oPDoc As PartDocument = oDoc
Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
Dim oFP As FlatPattern
If Not oSMDef.HasFlatPattern Then
Try
'tries to generate a FlatPattern
oSMDef.Unfold
Catch
End Try
End If
If Not oSMDef.HasFlatPattern Then Continue For 'skip to next oDoc
oFP = oSMDef.FlatPattern
Dim dir1 As Double = oFP.Length
Dim dir2 As Double = oFP.Width
Dim lengths As New List(Of Double) From {dir1, dir2}
lengths.Sort
BoxWidth = lengths(0)
BoxLength = lengths(1)
Trace.Write("oDoc: " & oDoc.DisplayName)
Trace.Write("BoxWidth: " & BoxWidth)
Trace.Write("BoxLength: " & BoxLength)
End If
Next
End Sub
Oops...I didn't see that earlier response when posting this, that contains similar code. Oh well. My version contains a few extra checks in there to help avoid potential errors that you might like.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)