Sheet metal parts length and width after bending

Sheet metal parts length and width after bending

Ahmed.shawkyXTZHN
Enthusiast Enthusiast
643 Views
11 Replies
Message 1 of 12

Sheet metal parts length and width after bending

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

Hi all , is there a code or a way to get sheet metal part length , width and height after bending  to be shown in part list same as flat pattern , thanks in advance

0 Likes
Accepted solutions (3)
644 Views
11 Replies
Replies (11)
Message 2 of 12

Andrii_Humeniuk
Advisor
Advisor

Hi @Ahmed.shawkyXTZHN . You can get the overall dimensions of the part using the OrientedMinimumRangeBox function. The results are in lines 11-13.

Dim oDoc As Document = ThisDoc.Document
If Not TypeOf oDoc Is PartDocument Then Exit Sub
Dim oPDoc As PartDocument = oDoc
Dim oBodies As SurfaceBodies = oPDoc.ComponentDefinition.SurfaceBodies
If oBodies.Count = 0 Then Exit Sub
Dim oBox As OrientedBox = oBodies(1).OrientedMinimumRangeBox
Dim lengths(3) As Double
Dim dSize As New List(Of Double)
dSize.AddRange({oBox.DirectionOne.Length, oBox.DirectionTwo.Length, oBox.DirectionThree.Length })
dSize.Sort()
lengths(0) = dSize(2) 'Max size box (cm)
lengths(1) = dSize(1) 'Mid size box (cm)
lengths(2) = dSize(0) 'Min size box (cm)

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 12

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast
thanks for your quick reply , where I will find the result's ?
0 Likes
Message 4 of 12

Andrii_Humeniuk
Advisor
Advisor

You did not write how you want to get the result, so it is in the code in lines 11-13, in the comments of these lines of code there is a brief description of the dimensions. Describe how you want to describe the size of your part based on the information that you can get 3 sizes (mid, min, max). Maybe you want to record this information under Part Number or something like that?

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 5 of 12

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast
yes I mean how the result will show in the table how to link it?
0 Likes
Message 6 of 12

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Parts List displays information from part properties. That is, you can add this code to the part document and set it to a trigger. Next, you need to describe in which cell you want to write information about the dimensions of the part and in what form (Max x Min x Mid). Also need information in which units do you need the dimensions (mm, cm)?

As an example, I recorded the information about the dimensions in the Part Number.

Dim oDoc As Document = ThisDoc.Document
If Not TypeOf oDoc Is PartDocument Then Exit Sub
Dim oPDoc As PartDocument = oDoc
Dim oProp As Inventor.Property = oPDoc.PropertySets("Design Tracking Properties")("Part Number")
Dim oBodies As SurfaceBodies = oPDoc.ComponentDefinition.SurfaceBodies
If oBodies.Count = 0 Then Exit Sub
Dim oBox As OrientedBox = oBodies(1).OrientedMinimumRangeBox
Dim lengths(3) As Double
Dim dSize As New List(Of Double)
dSize.AddRange({oBox.DirectionOne.Length, oBox.DirectionTwo.Length, oBox.DirectionThree.Length })
dSize.Sort()
MessageBox.Show(dSize(2) & " cm", "Max size box")
MessageBox.Show(dSize(1) & " cm", "Mid size box")
MessageBox.Show(dSize(0) & " cm", "Min size box")
oProp.Value = Round(dSize(2), 3) & "х" & Round(dSize(1), 3) & "х" & Round(dSize(0), 3)

 I hope you understand that I need more information to better help you, I can't read minds anyway(

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 7 of 12

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

thanks A lot, I got the Idea , is it possible to link to custom property and to be separate results not under one property for example to be under "total length", "total width", "total height" , and for units we are using mm, thanks.

0 Likes
Message 8 of 12

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

This code creates and updates information in custom properties. Max - "total length", Mid - "total width", Min - "total height". Rounding: 3 decimal places.

Dim oDoc As Document = ThisDoc.Document
Dim oUOfM As UnitsOfMeasure = oDoc.UnitsOfMeasure
If Not TypeOf oDoc Is PartDocument Then Exit Sub
Dim oPDoc As PartDocument = oDoc
Dim oCustom As PropertySet = oPDoc.PropertySets("Inventor User Defined Properties")
Dim oBodies As SurfaceBodies = oPDoc.ComponentDefinition.SurfaceBodies
If oBodies.Count = 0 Then Exit Sub
Dim oBox As OrientedBox = oBodies(1).OrientedMinimumRangeBox
Dim oTotlL, oTotlW, oTotlH As Inventor.Property
Dim lengths(3) As Double
Dim dSize As New List(Of Double)
dSize.AddRange({oBox.DirectionOne.Length, oBox.DirectionTwo.Length, oBox.DirectionThree.Length })
dSize.Sort()
lengths(0) = Round(oUOfM.ConvertUnits(dSize(2), kCentimeterLengthUnits, kMillimeterLengthUnits), 3)
lengths(1) = Round(oUOfM.ConvertUnits(dSize(1), kCentimeterLengthUnits, kMillimeterLengthUnits), 3)
lengths(2) = Round(oUOfM.ConvertUnits(dSize(0), kCentimeterLengthUnits, kMillimeterLengthUnits), 3)
Try : oCustom("total length").Value = lengths(0)
Catch : oCustom.Add(lengths(0), "total length") : End Try
Try : oCustom("total width").Value = lengths(1)
Catch : oCustom.Add(lengths(1), "total width") : End Try
Try : oCustom("total height").Value = lengths(2)
Catch : oCustom.Add(lengths(2), "total height") : End Try

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 9 of 12

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

thanks a lot it's working great.

0 Likes
Message 10 of 12

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast

@Andrii_Humeniuk thanks bro , sorry for bothering you again 😅 , is it possible to run it as external rule to assembly , I mean instead of add it to part wise can I run it from sheet metal assembly , thanks.

0 Likes
Message 11 of 12

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

This rule can be run on both PartDocument and AssemblyDocument, it searches all SheetMetal and adds size properties to it. I hope this is what you wanted?

Sub main 
	Dim oDoc As Document = ThisDoc.Document
	oUOfM = oDoc.UnitsOfMeasure
	If TypeOf oDoc Is PartDocument Then
		Call GetBoxForSheetNetal(oDoc)
	Else If TypeOf oDoc Is AssemblyDocument Then
		Dim oAsmDoc As AssemblyDocument = oDoc
		Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
		If oAsmDoc.AllReferencedDocuments.Count = 0 Then Exit Sub
		For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
			If Not TypeOf oRefDoc Is PartDocument Or
				oOccs.AllReferencedOccurrences(oRefDoc).Count = 0 Then Continue For
			If CheckPartOnSheet(oRefDoc) Then Continue For
			Call GetBoxForSheetNetal(oRefDoc)
		Next
	End If
End Sub

Dim oUOfM As UnitsOfMeasure

Private Function CheckPartOnSheet(ByVal oPDoc As PartDocument) As Boolean
	If Not oPDoc.IsModifiable Or
		oPDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Return True
	Return False
End Function

Private Sub GetBoxForSheetNetal(ByVal oPDoc As PartDocument)
	Dim oCustom As PropertySet = oPDoc.PropertySets("Inventor User Defined Properties")
	Dim oBodies As SurfaceBodies = oPDoc.ComponentDefinition.SurfaceBodies
	If oBodies.Count = 0 Then Return
	Dim oBox As OrientedBox = oBodies(1).OrientedMinimumRangeBox
	Dim oTotlL, oTotlW, oTotlH As Inventor.Property
	Dim lengths(3) As Double
	Dim dSize As New List(Of Double)
	dSize.AddRange({oBox.DirectionOne.Length, oBox.DirectionTwo.Length, oBox.DirectionThree.Length })
	dSize.Sort()
	lengths(0) = Round(oUOfM.ConvertUnits(dSize(2), kCentimeterLengthUnits, kMillimeterLengthUnits), 3)
	lengths(1) = Round(oUOfM.ConvertUnits(dSize(1), kCentimeterLengthUnits, kMillimeterLengthUnits), 3)
	lengths(2) = Round(oUOfM.ConvertUnits(dSize(0), kCentimeterLengthUnits, kMillimeterLengthUnits), 3)
	Try : oCustom("total length").Value = lengths(0)
	Catch : oCustom.Add(lengths(0), "total length") : End Try
	Try : oCustom("total width").Value = lengths(1)
	Catch : oCustom.Add(lengths(1), "total width") : End Try
	Try : oCustom("total height").Value = lengths(2)
	Catch : oCustom.Add(lengths(2), "total height") : End Try
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 12 of 12

Ahmed.shawkyXTZHN
Enthusiast
Enthusiast
Yes , thanks a lot.
0 Likes