sheet metal flat pattern total loop length

sheet metal flat pattern total loop length

Anonymous
Not applicable
3,098 Views
17 Replies
Message 1 of 18

sheet metal flat pattern total loop length

Anonymous
Not applicable

Is there anyway to return this value using Ilogic or other non manual method? I can do it manually with the measure tool but ideally would like it to appear in the BOM.

0 Likes
Accepted solutions (1)
3,099 Views
17 Replies
Replies (17)
Message 2 of 18

WCrihfield
Mentor
Mentor

To clarify...you are wanting the total perimeter length of the outside edges of the flat pattern, right? (not including any interior holes or cutouts?)

The Flat Pattern Width, Flat Pattern Length, and Flat Pattern Area (items 44,45, & 46) are all available in the iProperties, under the "Design Tracking Properties" set. But I don't think there is a pre-existing iProperty for the Perimeter.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 18

Anonymous
Not applicable
Hi. No, all internal profiles also.

When you flat pattern a part and select measure, when you then click the
face it gives a Total Loop Length. It's this I want to read.

Thanks

0 Likes
Message 4 of 18

WCrihfield
Mentor
Mentor

Here's some iLogic code you can use.  In the MsgBox, I'm dividing by 2.54 to convert centimeters to inches.

To just get the Perimeter, you can change the loop, to simply checking if the oEdgeLoop.IsOuterEdgeLoop, then use that one in your MsgBox.  You could also put checks at the top to check DocumentTypeEnum and SubType, if you wanted.

 

Dim oSMDoc As PartDocument = ThisApplication.ActiveDocument
Dim oSMDef As SheetMetalComponentDefinition = oSMDoc.ComponentDefinition
If oSMDef.HasFlatPattern = False Then
	MsgBox("There is no Flat Pattern yet.", vbOKOnly, "NO FLAT PATTERN")
	Return
End If
Dim oTopFace As Face = oSMDef.FlatPattern.TopFace
Dim oMeasureTools As MeasureTools = ThisApplication.MeasureTools
Dim oLoopLength As Double = 0
For Each oEdgeLoop As EdgeLoop In oTopFace.EdgeLoops
	oLoopLength = oLoopLength + oMeasureTools.GetLoopLength(oEdgeLoop)
Next
MsgBox("Loop Length = " & oLoopLength/2.54)

 

I hope this helps.
If this solves your problem, or answers your questions, please click 'Accept As Solution".
Or, if this helps you reach your goal, please click 'LIKES" 👍.

 

Also, if you're interested, here are a few of the 'Ideas' I'd like to get implemented.
If you agree with any of them, please vote for them.

  • Add more capabilities to the 'Customize' dialog box (exe. Add Tab & Add Panel) Click Here
  • MessageBox, InputBox, and InputListBox Size & Format Options Click Here
  • Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
  • Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
  • Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
  • Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here
  • SetDesignViewRepresentation - Fix limitations for DrawingView of a Part Click Here
  • Create DocumentSubTypeEnum Click Here

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 18

k14348
Advocate
Advocate

Hi,

    Hope this will work.

Sub LoopLength()
    
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oCmpDef As SheetMetalComponentDefinition
    Set oCmpDef = oDoc.ComponentDefinition
    
    Dim oFp As FlatPattern
    Set oFp = oCmpDef.FlatPattern
    
    Dim oBf As Face
    Set oBf = oFp.BaseFace
    
    Dim i As Integer
    Dim Result As Single
    Result = 0
    For i = 1 To oBf.EdgeLoops.Count
    
    Dim oEl As EdgeLoop
    Set oEl = oBf.EdgeLoops.Item(i)
    
    Result = (ThisApplication.MeasureTools.GetLoopLength(oEl) * 10) + Result
    Next
    MsgBox (Result)
    
    Dim textValue As Single
    textValue = Result
    Dim oName As String
    oName = "LoopLength"
    
    Dim oCProp As PropertySet
    Set oCProp = oDoc.PropertySets.Item("Inventor User Defined Properties")
    
    Dim oProp As Property
    Set oProp = oCProp.Add(textValue, oName)
End Sub

 

-Karth

Message 6 of 18

Anonymous
Not applicable

Hi, the below works really well adapting it to write to Custom Iproperties. Is there a way to drive this from assembly level so I don't have to manually add a rule to each part?

 

Dim oSMDoc As PartDocument = ThisApplication.ActiveDocument
Dim oSMDef As SheetMetalComponentDefinition = oSMDoc.ComponentDefinition
If oSMDef.HasFlatPattern = False Then
MsgBox("There is no Flat Pattern yet.", vbOKOnly, "NO FLAT PATTERN")
Return
End If
Dim oTopFace As Face = oSMDef.FlatPattern.TopFace
Dim oMeasureTools As MeasureTools = ThisApplication.MeasureTools
Dim oLoopLength As Double = 0
For Each oEdgeLoop As EdgeLoop In oTopFace.EdgeLoops
oLoopLength = oLoopLength + oMeasureTools.GetLoopLength(oEdgeLoop)
Next

iProperties.Value("Custom", "TOTAL_LOOP_LENGTH") = Round(oLoopLength*10)

0 Likes
Message 7 of 18

k14348
Advocate
Advocate


Sub Assyupdate()

Dim openDoc As AssemblyDocument
Set openDoc = ThisApplication.ActiveDocument
Dim doc As PartDocument
For Each doc In openDoc.AllReferencedDocuments
If doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

Dim oCmpDef As SheetMetalComponentDefinition
Set oCmpDef = doc.ComponentDefinition

Dim oFp As FlatPattern
Set oFp = oCmpDef.FlatPattern

Dim oBf As Face
Set oBf = oFp.BaseFace

Dim i As Integer
Dim Result As Single
Result = 0
For i = 1 To oBf.EdgeLoops.Count

Dim oEl As EdgeLoop
Set oEl = oBf.EdgeLoops.Item(i)

Result = (ThisApplication.MeasureTools.GetLoopLength(oEl) * 10) + Result
Next

Dim textValue As Single
textValue = Result
Dim oName As String
oName = "LoopLength"

Dim oCProp As PropertySet
Set oCProp = doc.PropertySets.Item("Inventor User Defined Properties")

Dim oProp As Property
Set oProp = oCProp.Add(textValue, oName)
End If
Next

End Sub

Message 8 of 18

Anonymous
Not applicable

Hi, thanks but I'm getting the following error message:

 

Error in rule program format:

All other sub's or functions must be after Sub Main()

 

 

 

0 Likes
Message 9 of 18

WCrihfield
Mentor
Mentor

Try this.

 

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oSMDoc As PartDocument
Dim oSMDef As SheetMetalComponentDefinition
Dim oTopFace As Face
Dim oMeasureTools As MeasureTools = ThisApplication.MeasureTools
Dim oLoopLength As Double
Dim oEdgeLoop As EdgeLoop
Dim oCustPropSet As PropertySet
Dim oProp As [Property]
Dim oPropName As String = "TOTAL_LOOP_LENGTH"
Dim oPropValue As Double
Dim oExists As Boolean  = False

For Each oRefDoc As Document In oADoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		If oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Autodesk Inventor Sheet Metal Part" Then
			oSMDoc = oRefDoc
			oSMDef = oSMDoc.ComponentDefinition
			If oSMDef.HasFlatPattern = False Then
				MsgBox("There is no Flat Pattern yet.", vbOKOnly, "NO FLAT PATTERN")
				Return
			End If
			oTopFace = oSMDef.FlatPattern.TopFace
			oLoopLength = 0
			For Each oEdgeLoop In oTopFace.EdgeLoops
				oLoopLength = oLoopLength + oMeasureTools.GetLoopLength(oEdgeLoop)
			Next
			oPropValue = Round(oLoopLength * 10)
			oCustPropSet = oSMDoc.PropertySets.Item("Inventor User Defined Properties")
			For Each oProp In oCustPropSet
				If oProp.Name = oPropName Then
					oExists = True
					oProp.Value = oPropValue
				End If
			Next
			If oExists = False Then
				oCustPropSet.Add(oPropValue, oPropName)
			End If
		End If
	End If
Next

 

I hope this helps.
If this solves your problem, or answers your questions, please click 'Accept As Solution".
Or, if this helps you reach your goal, please click 'LIKES" 👍.

 

Also, if you're interested, here are a few of the 'Ideas' I'd like to get implemented.
If you agree with any of them, please vote for them.

  • Add more capabilities to the 'Customize' dialog box (exe. Add Tab & Add Panel) Click Here
  • MessageBox, InputBox, and InputListBox Size & Format Options Click Here
  • Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
  • Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
  • Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
  • Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here
  • SetDesignViewRepresentation - Fix limitations for DrawingView of a Part Click Here
  • Create DocumentSubTypeEnum Click Here

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 18

Anonymous
Not applicable

Sorry no can't get this to work. Rule runs with no errors but nothing is written to any sheet metal parts. 

0 Likes
Message 11 of 18

Anonymous
Not applicable

A message box placed below this line doesn't appear when the rule is run but does when placed above.

 

If oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Autodesk Inventor Sheet Metal Part" Then

0 Likes
Message 12 of 18

JhoelForshav
Mentor
Mentor

@Anonymous

try changing it to:

If oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then

Or

If oRefDoc.DocumentSubType.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

That should work 🙂

0 Likes
Message 13 of 18

Anonymous
Not applicable

Hi ,

 

The first suggestion works thanks.

 

However, if there is a sheet metal part without a flat pattern  then the process fails and ideally id like it to then flat pattern the relevant part and continue instead of returning a message.

 

If oSMDef.HasFlatPattern = False Then
MsgBox("There is no Flat Pattern yet.", vbOKOnly, "NO FLAT PATTERN")
Return
End If

 

 

I have the below but not sure how to incorporate it into your rule?

 

If oCompDef.HasFlatPattern = False Then
oCompDef.Unfold
oDoc.Save
oDoc.Close
End If

 

0 Likes
Message 14 of 18

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

Try this 🙂

 

I also turned off screen updating in the application while unfolding the part so you dont have to see it open the part and unfold it. Also reactivated the assembly document after.

 

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oSMDoc As PartDocument
Dim oSMDef As SheetMetalComponentDefinition
Dim oTopFace As Face
Dim oMeasureTools As MeasureTools = ThisApplication.MeasureTools
Dim oLoopLength As Double
Dim oEdgeLoop As EdgeLoop
Dim oCustPropSet As PropertySet
Dim oProp As [Property]
Dim oPropName As String = "TOTAL_LOOP_LENGTH"
Dim oPropValue As Double
Dim oExists As Boolean = False

For Each oRefDoc As Document In oADoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		If oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then
			oSMDoc = oRefDoc
			oSMDef = oSMDoc.ComponentDefinition
			If oSMDef.HasFlatPattern = False Then
				Try
					ThisApplication.ScreenUpdating = False
					oSMDef.Unfold
					ThisApplication.ScreenUpdating = True
				Catch
					ThisApplication.ScreenUpdating = True
				End Try
				ThisDoc.Document.Activate
			End If
			oTopFace = oSMDef.FlatPattern.TopFace
			oLoopLength = 0
			For Each oEdgeLoop In oTopFace.EdgeLoops
				oLoopLength = oLoopLength + oMeasureTools.GetLoopLength(oEdgeLoop)
			Next
			oPropValue = Round(oLoopLength * 10)
			oCustPropSet = oSMDoc.PropertySets.Item("Inventor User Defined Properties")
			For Each oProp In oCustPropSet
				If oProp.Name = oPropName Then
					oExists = True
					oProp.Value = oPropValue
				End If
			Next
			If oExists = False Then
				oCustPropSet.Add(oPropValue, oPropName)
			End If
		End If
	End If
Next
iLogicVb.UpdateWhenDone = True
0 Likes
Message 15 of 18

JhoelForshav
Mentor
Mentor
Accepted solution

This is better. Doesnt leave the document that we had to unfold open...

 

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oSMDoc As PartDocument
Dim oSMDef As SheetMetalComponentDefinition
Dim oTopFace As Face
Dim oMeasureTools As MeasureTools = ThisApplication.MeasureTools
Dim oLoopLength As Double
Dim oEdgeLoop As EdgeLoop
Dim oCustPropSet As PropertySet
Dim oProp As [Property]
Dim oPropName As String = "TOTAL_LOOP_LENGTH"
Dim oPropValue As Double
Dim oExists As Boolean = False

For Each oRefDoc As Document In oADoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		If oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then
			oSMDoc = oRefDoc
			oSMDef = oSMDoc.ComponentDefinition
			If oSMDef.HasFlatPattern = False Then
				Try
					ThisApplication.ScreenUpdating = False
					oSMDef.Unfold
					cDef = ThisApplication.CommandManager.ControlDefinitions.Item("PartSwitchRepresentationCmd")
					cDef.Execute
					ThisApplication.ScreenUpdating = True
				Catch
					ThisApplication.ScreenUpdating = True
				End Try
				ThisDoc.Document.Activate
				oSMDoc.Close
			End If
			oTopFace = oSMDef.FlatPattern.TopFace
			oLoopLength = 0
			For Each oEdgeLoop In oTopFace.EdgeLoops
				oLoopLength = oLoopLength + oMeasureTools.GetLoopLength(oEdgeLoop)
			Next
			oPropValue = Round(oLoopLength * 10)
			oCustPropSet = oSMDoc.PropertySets.Item("Inventor User Defined Properties")
			For Each oProp In oCustPropSet
				If oProp.Name = oPropName Then
					oExists = True
					oProp.Value = oPropValue
				End If
			Next
			If oExists = False Then
				oCustPropSet.Add(oPropValue, oPropName)
			End If
		End If
	End If
Next
iLogicVb.UpdateWhenDone = True
Message 16 of 18

Donna_Fleming
Participant
Participant

 

Sorry. I meant to reply to Jhoel Forshav.

0 Likes
Message 17 of 18

Donna_Fleming
Participant
Participant

I know it's been a year, but thank you for providing this code.  It gets me a long way to where we need to be. We are asked to provide the total cutting inches required for the assembly. Would you be willing to add to this code so it totals the loop lengths for each piece to create a custom property in the assembly? 

0 Likes
Message 18 of 18

Donna_Fleming
Participant
Participant

I found some code by Curtis W. in another forum that worked for me to get a total of all the values created by the code @JhoelForshav  wrote. This is my complete rule combining the code of these two fine gentlemen:

 

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oSMDoc As PartDocument
Dim oSMDef As SheetMetalComponentDefinition
Dim oTopFace As Face
Dim oMeasureTools As MeasureTools = ThisApplication.MeasureTools
Dim oLoopLength As Double
Dim oEdgeLoop As EdgeLoop
Dim oCustPropSet As PropertySet
Dim oProp As [Property]
Dim oPropName As String = "LOOP_LENGTH"
Dim oPropValue As Double
Dim oExists As Boolean = False

For Each oRefDoc As Document In oADoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		If oRefDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then
			oSMDoc = oRefDoc
			oSMDef = oSMDoc.ComponentDefinition
			If oSMDef.HasFlatPattern = False Then
				Try
					ThisApplication.ScreenUpdating = False
					oSMDef.Unfold
					cDef = ThisApplication.CommandManager.ControlDefinitions.Item("PartSwitchRepresentationCmd")
					cDef.Execute
					ThisApplication.ScreenUpdating = True
				Catch
					ThisApplication.ScreenUpdating = True
				End Try
				ThisDoc.Document.Activate
				oSMDoc.Close
			End If
			oTopFace = oSMDef.FlatPattern.TopFace
			oLoopLength = 0
			For Each oEdgeLoop In oTopFace.EdgeLoops
				oLoopLength = oLoopLength + oMeasureTools.GetLoopLength(oEdgeLoop)
			Next
			oPropValue = oLoopLength/2.54
			oCustPropSet = oSMDoc.PropertySets.Item("Inventor User Defined Properties")
			For Each oProp In oCustPropSet
				If oProp.Name = oPropName Then
					oExists = True
					oProp.Value = oPropValue
				End If
			Next
			If oExists = False Then
				oCustPropSet.Add(oPropValue, oPropName)
			End If
		End If
	End If
Next
iLogicVb.UpdateWhenDone = True
'clear the custom property in the assembly 
iProperties.Value("Custom", "TOTAL_LOOP_LENGTH") = 0
'set a reference to the assembly component definintion.
'This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
'check for and skip virtual components
'(in case a virtual component trips things up)
If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
'custom property in the assembly 
xNumber = iProperties.Value("Custom", "TOTAL_LOOP_LENGTH") 
'custom property in the parts
yNumber = iProperties.Value(oOccurrence.Name, "Custom", "LOOP_LENGTH")
sumNumber = xNumber + yNumber
'set custom property values
iProperties.Value("Custom", "TOTAL_LOOP_LENGTH") = sumNumber 
Else
End If
Next

It works for me. If you have problems with it, I am sorry but my skills are not good enough
to solve your issue. I'm pretty much just a borrower of code at this stage and rely heavily
on gracious people who share their skills.

in 

0 Likes