Here is the VBA code I use. It creates 4 custm iProperties being OuterPerimeter, InnerPerimeters, TotalPerimeter and Pierces. I didn't write it (I think the author may have passed on) but I use it 100 times a day and it just works. Edit to suit your needs.
Sub GetIntExtPerimeters()
Dim oPartDoc As Document
Set oPartDoc = ThisApplication.ActiveDocument
Dim oFlatPattern As FlatPattern
' Check for a non-part document
If oPartDoc.DocumentType <> kPartDocumentObject Then
MsgBox "The Active document must be a 'Part'!"
Exit Sub
End If
' The Active document must be a Sheet metal Part
If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
MsgBox "The 'Part' must be a Sheet Metal Part!"
Exit Sub
End If
' Check to see if the flat pattern exists.
Set oFlatPattern = oPartDoc.ComponentDefinition.FlatPattern
If oFlatPattern Is Nothing Then
MsgBox "No flat pattern exists for this part!"
Exit Sub
End If
Dim oSheetMetalCompDef As SheetMetalComponentDefinition
Set oSheetMetalCompDef = oPartDoc.ComponentDefinition
' Get the cut length
Dim oFace As Face
Set oFace = oSheetMetalCompDef.FlatPattern.TopFace
' Find the outer loop.
Dim dOuterLength As Double
dOuterLength = 0
Dim oLoop As EdgeLoop
For Each oLoop In oFace.EdgeLoops
If oLoop.IsOuterEdgeLoop Then
Dim oEdge As Edge
For Each oEdge In oLoop.Edges
' Get the length of the current edge.
Dim dMin As Double, dMax As Double
Call oEdge.Evaluator.GetParamExtents(dMin, dMax)
Dim dLength As Double
Call oEdge.Evaluator.GetLengthAtParam(dMin, dMax, dLength)
dOuterLength = dOuterLength + dLength
Next
'MsgBox "Outer Loop is " & FormatNumber(dOuterLength, 1)
Exit For
End If
Next
' Iterate through the inner loops.
Dim iLoopCount As Long
iLoopCount = 0
Dim dTotalLength As Double
For Each oLoop In oFace.EdgeLoops
Dim dLoopLength As Double
dLoopLength = 0
If Not oLoop.IsOuterEdgeLoop Then
For Each oEdge In oLoop.Edges
' Get the length of the current edge.
Call oEdge.Evaluator.GetParamExtents(dMin, dMax)
Call oEdge.Evaluator.GetLengthAtParam(dMin, dMax, dLength)
dLoopLength = dLoopLength + dLength
Next
' Add this loop to the total length.
dTotalLength = dTotalLength + dLoopLength
'MsgBox "Inner Loops are " & FormatNumber(dTotalLength, 1)
End If
Next
'added by BH 13-07-2011-count edges to calculate peirces
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oDef As SheetMetalComponentDefinition
Set oDef = oDoc.ComponentDefinition
Set oFlatPattern = oDef.FlatPattern
Dim oTransaction As Transaction
Set oTransaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "FindArea ")
Dim oSketch As PlanarSketch
Set oSketch = oFlatPattern.Sketches.Add(oFlatPattern.TopFace)
Dim oEdgeLoop As EdgeLoop
numLoops = 1
For Each oEdgeLoop In oFlatPattern.TopFace.EdgeLoops
If oEdgeLoop.IsOuterEdgeLoop = False Then
numLoops = numLoops + 1
End If
Next
TotalPierces = numLoops
For Each oEdgeLoop In oFlatPattern.TopFace.EdgeLoops
If oEdgeLoop.IsOuterEdgeLoop Then
Exit For
End If
Next
For Each oEdge In oEdgeLoop.Edges
Call oSketch.AddByProjectingEntity(oEdge)
Next
Dim oProfile As Profile
Set oProfile = oSketch.Profiles.AddForSolid
oTransaction.Abort
'end
Dim oUOM As UnitsOfMeasure
Set oUOM = oPartDoc.UnitsOfMeasure
outerCutlength = oUOM.GetStringFromValue(dOuterLength, kMillimeterLengthUnits)
innerCutlength = oUOM.GetStringFromValue(dTotalLength, kMillimeterLengthUnits)
TotalCutLength = oUOM.GetStringFromValue(dTotalLength + dOuterLength, kMillimeterLengthUnits)
'Write data to properties, creating or updating (if property exists)
Dim oCustomPropSet As PropertySet
Set oCustomPropSet = oPartDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
On Error Resume Next
oCustomPropSet.Item("OuterPerimeter").Value = outerCutlength
If Err Then
Err.Clear
Call oCustomPropSet.Add(outerCutlength, "OuterPerimeter")
End If
oCustomPropSet.Item("InnerPerimeters").Value = innerCutlength
If Err Then
Err.Clear
Call oCustomPropSet.Add(innerCutlength, "InnerPerimeters")
End If
oCustomPropSet.Item("TotalPerimeter").Value = TotalCutLength
If Err Then
Err.Clear
Call oCustomPropSet.Add(TotalCutLength, "TotalPerimeter")
End If
'added by BH 13-07-2011
oCustomPropSet.Item("Pierces").Value = TotalPierces
If Err Then
Err.Clear
Call oCustomPropSet.Add(TotalPierces, "Pierces")
End If
End
End Sub
Brendan Henderson
CAD Manager

New Blog | Old Blog | Google+ | Twitter
Inventor 2016 PDSU Build 236, Release 2016.2.2, Vault Professional 2016 Update 1, Win 7 64 bit
Please use "Accept as Solution" & give "Kudos" if this response helped you.