Part and Sheetmetal extents from assembly using ilogic

Part and Sheetmetal extents from assembly using ilogic

Anonymous
Not applicable
3,734 Views
15 Replies
Message 1 of 16

Part and Sheetmetal extents from assembly using ilogic

Anonymous
Not applicable

Hi All,

 

I am into an ilogic to get extents of part and sheet metal from Assembly. I have ended up in a logic in which i can get the part extents from Assembly but the value of Sheet metal extents are different. For this I am running a seperate ilogic to get sheetmetal dimensions. I tried options to combine these two ilogic to run a single rule for an assembly comprising of both part and sheetmetal components.

Can anyone provide a suggestion to combine these two seperate rules together using an If else loop?

I am posting the two rules which I have been using.

 

For sheetmetal extents:

Sub Main()
'Determines if there is a flat pattern
Dim oDoc As PartDocument
oDoc = ThisDoc.Document
'ensure this part has a flat pattern
Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oDoc.ComponentDefinition

If oSMDef.FlatPattern Is Nothing Then
'Warns the user there is no flat pattern
'MessageBox.Show("This file has no flat pattern", "iLogic")
Else
Extents
End If
End Sub

Sub Extents()
extents_length = SheetMetal.FlatExtentsLength
extents_width = SheetMetal.FlatExtentsWidth
LengthFrac = Round(SheetMetal.FlatExtentsLength, 0)
WidthFrac = Round(SheetMetal.FlatExtentsWidth, 0)
Dim oValue As String
Dim param As Parameter

If extents_width > extents_length Then
oValue = (WidthFrac & " x " & LengthFrac & " x " & Thickness)

iProperties.Value("Custom", "StockSize") = oValue
Else
oValue = (LengthFrac & " x " & WidthFrac & " x " & Thickness)
iProperties.Value("Custom", "StockSize") = oValue
End If
End Sub

 

In Assembly to get part extents:

Public Sub Main()
' Reading the current assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

' Reading current assembly component definition.
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition

' Reading Child part(leaf occurrences) of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences

' Iterate through all part occurrences in assembly.

For Each oOcc In oLeafOccs
L = Math.Abs(oOcc.RangeBox.MaxPoint.X - oOcc.RangeBox.MinPoint.X) * 10
W = Math.Abs(oOcc.RangeBox.MaxPoint.Y - oOcc.RangeBox.MinPoint.Y) * 10
H = Math.Abs(oOcc.RangeBox.MaxPoint.Z - oOcc.RangeBox.MinPoint.Z) * 10

Dim oList As New ArrayList
oList.Add(L)
oList.Add(W)
oList.Add(H)

Call oList.Sort()

iProperties.Value(oOcc.Name, "Custom", "Length")= oList.Item(2)
iProperties.Value(oOcc.Name,"Custom", "Width") = oList.Item(1)
iProperties.Value(oOcc.Name, "Custom", "Thickness") = oList.Item(0)
Smallest = oList.Item(0)
Middle = oList.Item(1)
Largest = oList.Item(2)
iProperties.Value(oOcc.Name, "Custom", "StockSize") = Largest & " x " & Middle & " x " & Smallest & " "

Next

End Sub

 

Can anyone suggest a way to combine both?

 

Thanks in advance.

 

Regards,

Aswin Mathai

0 Likes
Accepted solutions (1)
3,735 Views
15 Replies
Replies (15)
Message 2 of 16

marcin_otręba
Advisor
Advisor

hi,

 

you can check this one :

 

 

Public Sub Main()
' Reading the current assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

' Reading current assembly component definition.
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition

' Reading Child part(leaf occurrences) of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences

' Iterate through all part occurrences in assembly.

For Each oOcc In oLeafOccs
	Dim odoc As PartDocument
	Try
		odoc=oOcc.definition.document
		Catch
		End Try
	Dim oSMCD As SheetMetalComponentDefinition
oSMCD = odoc.ComponentDefinition
' Look for Flatpattern
If Not oSMCD.HasFlatPattern Then
 
   oSMCD.Unfold()
   odoc.Update2(True)
   oSMCD.FlatPattern.ExitEdit
Else

End If

Dim fp As FlatPattern = oSMCD.FlatPattern

L = fp.Length*10

W = fp.Width*10	

H = oSMCD.Thickness.Value*10

Dim oList As New ArrayList
oList.Add(L)
oList.Add(W)
oList.Add(H)

Call oList.Sort()

iProperties.Value(oOcc.Name, "Custom", "Length")= oList.Item(2)
iProperties.Value(oOcc.Name,"Custom", "Width") = oList.Item(1)
iProperties.Value(oOcc.Name, "Custom", "Thickness") = oList.Item(0)
Smallest = oList.Item(0)
Middle = oList.Item(1)
Largest = oList.Item(2)
iProperties.Value(oOcc.Name, "Custom", "StockSize") = Largest & " x " & Middle & " x " & Smallest & " "

Next

End Sub

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 16

Anonymous
Not applicable

Hi @marcin_otręba ,

 

Thanks for your valuable time and the support provided. 

The code was working good for Assemblies that contain only sheet metal components. When I am using the same code for the part document, it returns no value.

 

Also, in case of sheet metal parts, if am mirroring one of the sheet metal part, then the value that is displayed of the mirrored components are different that the parent component. To solve this I have used the reuse option insted of mirror option.

 

Could you please check into the below code? This one works good for components other than sheet metal. but itsnot returning any value for sheet metal parts.

 

Public Sub Main()
' Reading the current assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

' Reading current assembly component definition.
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition

' Reading Child part(leaf occurrences) of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences

' Iterate through all part occurrences in assembly.

For Each oOcc In oLeafOccs
	Dim odoc As PartDocument
		odoc=oOcc.definition.document
	Dim sDocumentSubType = odoc.SubType
		sdoc = odoc.SubType
		
If sdoc = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
		L = Round((Math.Abs(oOcc.RangeBox.MaxPoint.X - oOcc.RangeBox.MinPoint.X) * 10),0)
		W = Round((Math.Abs(oOcc.RangeBox.MaxPoint.Y - oOcc.RangeBox.MinPoint.Y) * 10),0)
		H = Round((Math.Abs(oOcc.RangeBox.MaxPoint.Z - oOcc.RangeBox.MinPoint.Z) * 10),0)
		 
		Dim oList As New ArrayList 
		oList.Add(L)
		oList.Add(W)
		oList.Add(H)
		 
		Call oList.Sort()
		
		iProperties.Value(oOcc.Name, "Custom", "Length")= oList.Item(2)
		iProperties.Value(oOcc.Name,"Custom", "Width") = oList.Item(1)
		iProperties.Value(oOcc.Name, "Custom", "Thickness") = oList.Item(0)
		Smallest = oList.Item(0)
		Middle = oList.Item(1)
		Largest = oList.Item(2)
		iProperties.Value(oOcc.Name, "Custom", "StockSize") = Largest & " x " & Middle & " x " & Smallest & " "
	End If
	
	If sdoc = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
		extents_length = SheetMetal.FlatExtentsLength
		extents_width = SheetMetal.FlatExtentsWidth
		LengthFrac = Round(SheetMetal.FlatExtentsLength, 0)
		WidthFrac = Round(SheetMetal.FlatExtentsWidth, 0)
	Dim oValue As String
	Dim param As Parameter
	
		If extents_width > extents_length Then
			oValue = (WidthFrac & " x " & LengthFrac & " x " & Thickness)
			
			iProperties.Value("Custom", "StockSize") = oValue
		Else
			oValue = (LengthFrac & " x " & WidthFrac & " x " & Thickness)
			iProperties.Value("Custom", "StockSize") = oValue
	End If
End If
Next

End Sub

Can you guide in this?Thanks in advance.
Regards,

Aswin Mathai
0 Likes
Message 4 of 16

marcin_otręba
Advisor
Advisor

hi,

 

The code was working good for Assemblies that contain only sheet metal components. When I am using the same code for the part document, it returns no value. - you wanted code for sheetmetal extens. It works for sheetmetal components.

 

Also, in case of sheet metal parts, if am mirroring one of the sheet metal part, then the value that is displayed of the mirrored components are different that the parent component. To solve this I have used the reuse option insted of mirror option. This  is because in part wchich have derivered component sheetmetal style if wrong , and must be equal to derivvedparts.

 

Could you please check into the below code? This one works good for components other than sheet metal. but itsnot returning any value for sheet metal parts. - i corrected your code.

 

Public Sub Main()
' Reading the current assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

' Reading current assembly component definition.
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition

' Reading Child part(leaf occurrences) of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences

' Iterate through all part occurrences in assembly.

For Each oOcc In oLeafOccs
	Dim odoc As PartDocument
		odoc=oOcc.definition.document
	Dim sdoc = odoc.SubType
		
		
	If sdoc = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
		L = Round((Math.Abs(oOcc.RangeBox.MaxPoint.X - oOcc.RangeBox.MinPoint.X) * 10),0)
		W = Round((Math.Abs(oOcc.RangeBox.MaxPoint.Y - oOcc.RangeBox.MinPoint.Y) * 10),0)
		H = Round((Math.Abs(oOcc.RangeBox.MaxPoint.Z - oOcc.RangeBox.MinPoint.Z) * 10),0)
		 
		Dim oList As New ArrayList 
		oList.Add(L)
		oList.Add(W)
		oList.Add(H)
		 
		Call oList.Sort()
		
		iProperties.Value(oOcc.Name, "Custom", "Length")= oList.Item(2)
		iProperties.Value(oOcc.Name,"Custom", "Width") = oList.Item(1)
		iProperties.Value(oOcc.Name, "Custom", "Thickness") = oList.Item(0)
		Smallest = oList.Item(0)
		Middle = oList.Item(1)
		Largest = oList.Item(2)
		iProperties.Value(oOcc.Name, "Custom", "StockSize") = Largest & " x " & Middle & " x " & Smallest & " "
	End If
	
	If sdoc = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

		Try
		odoc=oOcc.definition
		Catch
		End Try
		If odoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count = 1 Then
			Dim sh As SheetMetalComponentDefinition=odoc.ComponentDefinition
			sh.SheetMetalStyles.Item (odoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1).parent.ActiveSheetMetalStyle.name).Activate
		End If
			
		Dim oSMCD As SheetMetalComponentDefinition
		oSMCD = odoc.ComponentDefinition
		' Look for Flatpattern
		If Not oSMCD.HasFlatPattern Then
 
		   oSMCD.Unfold()
		   odoc.Update2(True)
		   oSMCD.FlatPattern.ExitEdit
		End If

		Dim fp As FlatPattern = oSMCD.FlatPattern
		extents_length  = fp.Length
		extents_width = fp.Width
		Thickness = oSMCD.Thickness.Value
		LengthFrac = Round(extents_length, 0)
		WidthFrac = Round(extents_width, 0)
		Dim oValue As String
		Dim param As Parameter
		
			If extents_width > extents_length Then
				oValue = (WidthFrac & " x " & LengthFrac & " x " & Thickness)
				
				iProperties.Value(oOcc.Name, "Custom", "StockSize") = oValue
			Else
				oValue = (LengthFrac & " x " & WidthFrac & " x " & Thickness)
				iProperties.Value(oOcc.Name, "Custom", "StockSize") = oValue
			End If
	End If
Next

End Sub

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 5 of 16

Anonymous
Not applicable

Hi @marcin_otręba ,

 

Thanks for the solution.

 

Why could this error be popping up?

info8FMAA_0-1590753334276.png

Regards,

 

Aswin mathai

 

0 Likes
Message 6 of 16

marcin_otręba
Advisor
Advisor

i found one mistake in line :

odoc=oOcc.definition should be odoc=oOcc.definition.document, but i didint get an error running this rule at my inventor.

 

 

Public Sub Main()
' Reading the current assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

' Reading current assembly component definition.
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition

' Reading Child part(leaf occurrences) of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences

' Iterate through all part occurrences in assembly.

For Each oOcc In oLeafOccs
	Dim odoc As PartDocument
		odoc=oOcc.definition.document
	Dim sdoc = odoc.SubType
		
		
	If sdoc = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
		L = Round((Math.Abs(oOcc.RangeBox.MaxPoint.X - oOcc.RangeBox.MinPoint.X) * 10),0)
		W = Round((Math.Abs(oOcc.RangeBox.MaxPoint.Y - oOcc.RangeBox.MinPoint.Y) * 10),0)
		H = Round((Math.Abs(oOcc.RangeBox.MaxPoint.Z - oOcc.RangeBox.MinPoint.Z) * 10),0)
		 
		Dim oList As New ArrayList 
		oList.Add(L)
		oList.Add(W)
		oList.Add(H)
		 
		Call oList.Sort()
		
		iProperties.Value(oOcc.Name, "Custom", "Length")= oList.Item(2)
		iProperties.Value(oOcc.Name,"Custom", "Width") = oList.Item(1)
		iProperties.Value(oOcc.Name, "Custom", "Thickness") = oList.Item(0)
		Smallest = oList.Item(0)
		Middle = oList.Item(1)
		Largest = oList.Item(2)
		iProperties.Value(oOcc.Name, "Custom", "StockSize") = Largest & " x " & Middle & " x " & Smallest & " "
	End If
	
	If sdoc = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

		Try
		odoc=oOcc.definition.document
		Catch
		End Try
		If odoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count = 1 Then
			Dim sh As SheetMetalComponentDefinition=odoc.ComponentDefinition
			sh.SheetMetalStyles.Item (odoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1).Parent.ActiveSheetMetalStyle.name).Activate
		End If
			
		Dim oSMCD As SheetMetalComponentDefinition
		oSMCD = odoc.ComponentDefinition
		' Look for Flatpattern
		If Not oSMCD.HasFlatPattern Then
 
		   oSMCD.Unfold()
		   odoc.Update2(True)
		   oSMCD.FlatPattern.ExitEdit
		End If

		Dim fp As FlatPattern = oSMCD.FlatPattern
		extents_length  = fp.Length
		extents_width = fp.Width
		Thickness = oSMCD.Thickness.Value
		LengthFrac = Round(extents_length, 0)
		WidthFrac = Round(extents_width, 0)
		Dim oValue As String
		Dim param As Parameter
		
			If extents_width > extents_length Then
				oValue = (WidthFrac & " x " & LengthFrac & " x " & Thickness)
				
				iProperties.Value(oOcc.Name, "Custom", "StockSize") = oValue
			Else
				oValue = (LengthFrac & " x " & WidthFrac & " x " & Thickness)
				iProperties.Value(oOcc.Name, "Custom", "StockSize") = oValue
			End If
	End If
Next

End Sub

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 7 of 16

Anonymous
Not applicable

Hi @marcin_otręba ,

 

Sorry to bother you again.

1. While running the code, it opens each file in a seperate window, and then it gets the value. Is there a way to avoid this?

2. The code returns error file if a part is not having flat pattern.

 

Regards,

Aswin Mathai

0 Likes
Message 8 of 16

marcin_otręba
Advisor
Advisor
Accepted solution

hi,

1. While running the code, it opens each file in a seperate window, and then it gets the value. Is there a way to avoid this? - if flat pattern is missing it must be unfolded, when you run unfold method then file is open in seperate window.

2. The code returns error file if a part is not having flat pattern. - i corrected it

 

Public Sub Main()
' Reading the current assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

' Reading current assembly component definition.
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition

' Reading Child part(leaf occurrences) of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences

' Iterate through all part occurrences in assembly.
Dim oOcc As ComponentOccurrence
For Each oOcc In oLeafOccs
	Dim odoc As PartDocument
		odoc=oOcc.Definition.Document
	Dim sdoc = odoc.SubType
		
		
	If sdoc = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
		L = Round((Math.Abs(oOcc.RangeBox.MaxPoint.X - oOcc.RangeBox.MinPoint.X) * 10),0)
		W = Round((Math.Abs(oOcc.RangeBox.MaxPoint.Y - oOcc.RangeBox.MinPoint.Y) * 10),0)
		H = Round((Math.Abs(oOcc.RangeBox.MaxPoint.Z - oOcc.RangeBox.MinPoint.Z) * 10),0)
		 
		Dim oList As New ArrayList 
		oList.Add(L)
		oList.Add(W)
		oList.Add(H)
		 
		Call oList.Sort()
		
		iProperties.Value(oOcc.Name, "Custom", "Length")= oList.Item(2)
		iProperties.Value(oOcc.Name,"Custom", "Width") = oList.Item(1)
		iProperties.Value(oOcc.Name, "Custom", "Thickness") = oList.Item(0)
		Smallest = oList.Item(0)
		Middle = oList.Item(1)
		Largest = oList.Item(2)
		iProperties.Value(oOcc.Name, "Custom", "StockSize") = Largest & " x " & Middle & " x " & Smallest & " "
	End If
	
	If sdoc = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

		Try
		odoc = oOcc.Definition.Document
		
		Catch
		End Try
			If odoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count = 1 Then
			

			Dim sh As SheetMetalComponentDefinition=odoc.ComponentDefinition
			sh.SheetMetalStyles.Item (odoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.componentdefinition.ActiveSheetMetalStyle.name).Activate
		End If
			
		Dim oSMCD As SheetMetalComponentDefinition
		oSMCD = odoc.ComponentDefinition
		' Look for Flatpattern
		If Not oSMCD.HasFlatPattern Then
 			 odoc = ThisApplication.Documents.Open(oOcc.Definition.Document.fullfilename,True)
		   oSMCD.Unfold()
		   odoc.Update2(True)
		 oSMCD.FlatPattern.ExitEdit
		 odoc.save
		 odoc.close
		End If

		Dim fp As FlatPattern = oSMCD.FlatPattern
		extents_length  = fp.Length
		extents_width = fp.Width
		Thickness = oSMCD.Thickness.Value
		LengthFrac = Round(extents_length, 0)
		WidthFrac = Round(extents_width, 0)
		Dim oValue As String
		Dim param As Parameter
		
			If extents_width > extents_length Then
				oValue = (WidthFrac & " x " & LengthFrac & " x " & Thickness)
				
				iProperties.Value(oOcc.Name, "Custom", "StockSize") = oValue
			Else
				oValue = (LengthFrac & " x " & WidthFrac & " x " & Thickness)
				iProperties.Value(oOcc.Name, "Custom", "StockSize") = oValue
			End If
	End If
Next

End Sub

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 9 of 16

Anonymous
Not applicable

Hi @marcin_otręba,

 

Thanks for the solution. It worked. Thanks for the help once again.

 

Regards,

 

Aswin mathai

Message 10 of 16

marcin_otręba
Advisor
Advisor

Nice to hear that.Could you accept it as solution then.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 11 of 16

deffysalfauzi
Enthusiast
Enthusiast

stock size is different (in milimeter), how to fix it, please.
Screenshot 2024-06-28 142544.pngScreenshot 2024-06-28 142413.pngScreenshot 2024-06-28 142444.png

0 Likes
Message 12 of 16

marcin_otręba
Advisor
Advisor

 

 

Hi,

 

Inventor stores valueas in cm not in mm, code corrected to be:

 

marcin_otrba_0-1719562252314.png

 

Public Sub Main()
' Reading the current assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

' Reading current assembly component definition.
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition

' Reading Child part(leaf occurrences) of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences

' Iterate through all part occurrences in assembly.
Dim oOcc As ComponentOccurrence
For Each oOcc In oLeafOccs
	Dim odoc As PartDocument
		odoc=oOcc.Definition.Document
	Dim sdoc = odoc.SubType
		
		
	If sdoc = "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
		L = Round((Math.Abs(oOcc.RangeBox.MaxPoint.X - oOcc.RangeBox.MinPoint.X) * 10),0)
		W = Round((Math.Abs(oOcc.RangeBox.MaxPoint.Y - oOcc.RangeBox.MinPoint.Y) * 10),0)
		H = Round((Math.Abs(oOcc.RangeBox.MaxPoint.Z - oOcc.RangeBox.MinPoint.Z) * 10),0)
		 
		Dim oList As New ArrayList 
		oList.Add(L)
		oList.Add(W)
		oList.Add(H)
		 
		Call oList.Sort()
		
		iProperties.Value(oOcc.Name, "Custom", "Length")= oList.Item(2)
		iProperties.Value(oOcc.Name,"Custom", "Width") = oList.Item(1)
		iProperties.Value(oOcc.Name, "Custom", "Thickness") = oList.Item(0)
		Smallest = oList.Item(0)
		Middle = oList.Item(1)
		Largest = oList.Item(2)
		iProperties.Value(oOcc.Name, "Custom", "StockSize") = Largest & " x " & Middle & " x " & Smallest & " "
	End If
	
	If sdoc = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

		Try
		odoc = oOcc.Definition.Document
		
		Catch
		End Try
			If odoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count = 1 Then
			

			Dim sh As SheetMetalComponentDefinition=odoc.ComponentDefinition
			sh.SheetMetalStyles.Item (odoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.componentdefinition.ActiveSheetMetalStyle.name).Activate
		End If
			
		Dim oSMCD As SheetMetalComponentDefinition
		oSMCD = odoc.ComponentDefinition
		' Look for Flatpattern
		If Not oSMCD.HasFlatPattern Then
 			 odoc = ThisApplication.Documents.Open(oOcc.Definition.Document.fullfilename,True)
		   oSMCD.Unfold()
		   odoc.Update2(True)
		 oSMCD.FlatPattern.ExitEdit
		 odoc.save
		 odoc.close
		End If

		Dim fp As FlatPattern = oSMCD.FlatPattern
		extents_length  = fp.Length
		extents_width = fp.Width
		Thickness = oSMCD.Thickness.Value * 10
		LengthFrac = Round(extents_length, 0) *10 
		WidthFrac = Round(extents_width, 0) * 10 
		Dim oValue As String
		Dim param As Parameter
		
			If extents_width > extents_length Then
				oValue = (WidthFrac & " x " & LengthFrac & " x " & Thickness)
				
				iProperties.Value(oOcc.Name, "Custom", "StockSize") = oValue
			Else
				oValue = (LengthFrac & " x " & WidthFrac & " x " & Thickness)
				iProperties.Value(oOcc.Name, "Custom", "StockSize") = oValue
			End If
	End If
Next

End Sub
 

 

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 13 of 16

deffysalfauzi
Enthusiast
Enthusiast
Thanks. It worked. I have one more question. If the plate size is changed, can the stock size automatically update without having to click 'Run' or 'Regenerate'?
0 Likes
Message 14 of 16

marcin_otręba
Advisor
Advisor

you can put code from below into external rule ad set it to be run before document save event using itrigger:

 

If ThisApplication.ActiveEditDocument.subtype = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
Dim odoc As PartDocument 
		Try
		odoc=  ThisApplication.ActiveEditDocument
		
		Catch
		End Try
			If odoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Count = 1 Then
			

			Dim sh As SheetMetalComponentDefinition=odoc.ComponentDefinition
			sh.SheetMetalStyles.Item (odoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.componentdefinition.ActiveSheetMetalStyle.name).Activate
		End If
			
		Dim oSMCD As SheetMetalComponentDefinition
		oSMCD = odoc.ComponentDefinition
		' Look for Flatpattern
		If Not oSMCD.HasFlatPattern Then
 			 odoc = ThisApplication.Documents.Open(odoc.fullfilename,True)
		   oSMCD.Unfold()
		   odoc.Update2(True)
		 oSMCD.FlatPattern.ExitEdit
		 odoc.save
		 odoc.close
		End If

		Dim fp As FlatPattern = oSMCD.FlatPattern
		extents_length  = fp.Length
		extents_width = fp.Width
		Thickness = oSMCD.Thickness.Value * 10
		LengthFrac = Round(extents_length, 0) *10 
		WidthFrac = Round(extents_width, 0) * 10 
		Dim oValue As String
	
			If extents_width > extents_length Then
				oValue = (WidthFrac & " x " & LengthFrac & " x " & Thickness)
				Try
					odoc.propertysets.item(4).item("StockSize").Value = oValue
					Catch
					odoc.PropertySets.Item(4).Add(oValue, "StockSize")
					End Try
				
			Else
				oValue = (LengthFrac & " x " & WidthFrac & " x " & Thickness)
			Try
					odoc.propertysets.item(4).item("StockSize").Value = oValue
					Catch
						   odoc.PropertySets.Item(4).Add(oValue, "StockSize")
					End Try
			End If
	End If

 

marcin_otrba_0-1719567751483.png

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 15 of 16

deffysalfauzi
Enthusiast
Enthusiast
Thank you very much. How do I add material in oValue, for example: SUS316L, 1.5 x 100 x 50 mm?
0 Likes
Message 16 of 16

marcin_otręba
Advisor
Advisor

easiest way is:

ps. i corrected previous code.

If ThisApplication.ActiveEditDocument.subtype = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
	Dim odoc As PartDocument 
	Try
		odoc=  ThisApplication.ActiveEditDocument
	Catch
	End Try
	Dim oSMCD As SheetMetalComponentDefinition
	oSMCD = odoc.ComponentDefinition
		' Look for Flatpattern
		If Not oSMCD.HasFlatPattern Then
		  	oSMCD.Unfold()
		  	odoc.Update2(True)
		 	oSMCD.FlatPattern.ExitEdit
		End If
	Dim fp As FlatPattern = oSMCD.FlatPattern
	extents_length  = fp.Length
	extents_width = fp.Width
	Thickness = oSMCD.Thickness.Value * 10
	LengthFrac = Round(extents_length, 0) *10 
	WidthFrac = Round(extents_width, 0) * 10 
		
	Dim oValue As String
		If extents_width > extents_length Then
			oValue = "=<Material>, " & (WidthFrac & " x " & LengthFrac & " x " & Thickness)
			Try
				odoc.PropertySets.Item(4).Item("StockSize").Value = oValue
			Catch
				odoc.PropertySets.Item(4).Add(oValue, "StockSize")
			End Try
		Else
			oValue = "=<Material>, " & (LengthFrac & " x " & WidthFrac & " x " & Thickness)
			Try
				odoc.PropertySets.Item(4).Item("StockSize").Value = oValue
			Catch
				odoc.PropertySets.Item(4).Add(oValue, "StockSize")
			End Try
		End If
End If
 

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes