Apply a sheet metal rule to multiple parts at once

Apply a sheet metal rule to multiple parts at once

reine_den_andra
Enthusiast Enthusiast
912 Views
15 Replies
Message 1 of 16

Apply a sheet metal rule to multiple parts at once

reine_den_andra
Enthusiast
Enthusiast

Is there a way to apply a sheet metal rule to multiple parts at once?

I get 100's of STEP files that don't have a sheet metal rule on them, and therefore can't make a flat pattern.

What I do today is to open each part for itself, put a sheet metal rule on it, and then be able to make a flat patten on it. That takes some time....

0 Likes
Accepted solutions (3)
913 Views
15 Replies
Replies (15)
Message 2 of 16

hollypapp65
Collaborator
Collaborator

Add Sheet Metal rule to ipt Template then import again.

You also save Sheet Metal Rules to Style Library and use it in ipt that don't have Sheet Metal Rules.

You do need a Rule in Style Library first.  Then write program to copy it to other file.

0 Likes
Message 3 of 16

reine_den_andra
Enthusiast
Enthusiast

Thank you for the reply. The thing is, I dont know how to do rules at all. Its pure Greek to me, and I feel stupid.

Can you help me with this?

0 Likes
Message 4 of 16

hollypapp65
Collaborator
Collaborator
0 Likes
Message 5 of 16

reine_den_andra
Enthusiast
Enthusiast

Yes I know what sheet metal rules are, I have 30 of them. But I dont know how to apply a specific sheet metal rule to let´s say 20 "dead" parts at the same time.
Is that possible? 

0 Likes
Message 6 of 16

jnowel
Collaborator
Collaborator
Accepted solution

This is something i did in the past to batch change all the sheetmetal rule for all the components in an assy.
The sheetmetal rules need to be in the Standard (or all the part has it as a local sheetmetal rule)

 

You'll select a rule and that would affect ALL the sheetmetal components.

Give it a try and let me know if you encounter some issues

 

If Not TypeOf ThisApplication.ActiveDocument Is AssemblyDocument Then 
	MessageBox.Show("Use this rule in an Assy only")
	Exit Sub
End If

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument

Dim oOcc As ComponentOccurrence
Dim oPartDict As New Dictionary(Of String, String)
Dim oSMStyle As SheetMetalStyle = Nothing

For Each oOcc In oADoc.ComponentDefinition.Occurrences
	Dim oOccDoc As Document = oOcc.Definition.Document
	Dim oOccDocName As String = oOccDoc.FullDocumentName

	If Not oOccDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For 'NOT SHEETMETAL
	If Not oPartDict.ContainsKey(oOccDocName) Then
		oPartDict.Add(oOccDocName, oOccDocName)
		
		Logger.Info(oOccDocName)
		Dim oPartDoc As PartDocument = oOccDoc
		Dim oPartCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
		
		Try: oPartCompDef.UseSheetMetalStyleThickness = True
		Catch : Logger.Info("ERROR in UseSheetMetalStyleThickness: " & oPartDoc.DisplayName)
		End Try
		
		Try : oPartCompDef.UseSheetMetalStyleUnfoldMethod = True
		Catch : Logger.Info("ERROR in UseSheetMetalStyleUnfoldMethod: " & oPartDoc.DisplayName)
		End Try
		
		Try : oPartCompDef.UseSheetMetalStyleMaterial = True
		Catch : Logger.Info("ERROR in UseSheetMetalStyleMaterial: " & oPartDoc.DisplayName)
		End Try
		
		Logger.Info("Active Rule: " & oPartCompDef.ActiveSheetMetalStyle.Name)
		
		If oSMStyle Is Nothing Then
			Dim oSMStyles As SheetMetalStyles = oPartCompDef.SheetMetalStyles
			Dim oSMStyleList As New List(Of String)
			For i = 1 To oPartCompDef.SheetMetalStyles.Count
				oSMStyleList.Add(oPartCompDef.SheetMetalStyles.Item(i).Name)
			Next i
			
			oSMStyleName = InputListBox("Select Sheetmetal Rule", oSMStyleList, oPartCompDef.SheetMetalStyles(1), Title := "Title", ListName := "List")
			Try
				oSMStyle = oPartCompDef.SheetMetalStyles.Item(oSMStyleName)
			Catch
				MessageBox.Show("No Style Selected, Exiting")
			End Try
			Logger.Info(oSMStyleName)
			
		End If
		
		Try
			oPartCompDef.SheetMetalStyles.Item(oSMStyleName).Activate
			Logger.Info("NEW Rule: " & oPartCompDef.ActiveSheetMetalStyle.Name)
		Catch :
			Logger.Info("ERROR: " & oPartDoc.DisplayName)
		End Try
			
		If Not oPartCompDef.HasFlatPattern Then
			oPartCompDef.Unfold
		End If
		
	End If
Next

 

Message 7 of 16

reine_den_andra
Enthusiast
Enthusiast

OH MY GOD !!! You made my day 100% better. THANK YOU! ❤️

This is as close as you can get to what I mean. Absolutely incredible! 😀
(The only thing that doesn't work is that the thickness doesn't change even though it says so when I open the detail.)

Edit: It works perfectly. I tried an old STEP export which is a bit incorrect.

 

I'm not very good at this with rules. What do you mean by: The sheetmetal rules need to be in the Standard.

 

Message 8 of 16

jnowel
Collaborator
Collaborator

I may have worded it poorly.
What I meant is that the SheetMetal Rule be saved in the Library (so every sheetmetal part can access that rule)

You can do that by "Save to Library", is still haven't.

jnowel_1-1764332074475.png


I was (incorrectly) thinking it is the same as "Add to Standard" option when creating new Local style like in the drawing environment.


The iLogic rule above assumes that all sheetmetal parts has access to the Sheetmetal rule you want applied.
If the sheetmetal rule is unavailable, the iLogic rule will fail to activate/change to that chosen sheetmetal rule.

if you can enable your iLogic Log through

jnowel_2-1764332428421.png

 

You can see the logs (as i included them in the ilogic rule) and a bit of what has happened.
as an example of what happens when the sheetmetal rule is unavailable in one of the parts:
say, i selected "Steel 5mm" but this is only a local style (to the first part, "TEST copy.ipt") and only available to that part only

jnowel_3-1764332564644.png


the log will show the active rule before changing, which is "Steel 3mm" and it successfully change it to "Steel 5mm"
but for "TEST.ipt", it errors as it cannot change to the "Steel 5mm" (as it is unavailable)

jnowel_5-1764332701919.png


as opposed to say changing it to "HDPE 10mm" that is saved in the Library and accessible to all sheetmetal
Both "TEST copy.ipt" and "TEST.ipt" has been successfully change to the new sheetmetal rule selected

jnowel_6-1764332908010.png

 



 

Message 9 of 16

reine_den_andra
Enthusiast
Enthusiast
Accepted solution

You are lika a god to me! Thank you for all this. I am soo happy right now!

I will click "Accept Solution" here.

0 Likes
Message 10 of 16

reine_den_andra
Enthusiast
Enthusiast

Hello

This works great. But is i possible to make this work with sub-assemblies?

 

If Not TypeOf ThisApplication.ActiveDocument Is AssemblyDocument Then 
	MessageBox.Show("Use this rule in an Assy only")
	Exit Sub
End If

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument

Dim oOcc As ComponentOccurrence
Dim oPartDict As New Dictionary(Of String, String)
Dim oSMStyle As SheetMetalStyle = Nothing

For Each oOcc In oADoc.ComponentDefinition.Occurrences
	Dim oOccDoc As Document = oOcc.Definition.Document
	Dim oOccDocName As String = oOccDoc.FullDocumentName

	If Not oOccDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For 'NOT SHEETMETAL
	If Not oPartDict.ContainsKey(oOccDocName) Then
		oPartDict.Add(oOccDocName, oOccDocName)
		
		Logger.Info(oOccDocName)
		Dim oPartDoc As PartDocument = oOccDoc
		Dim oPartCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
		
		Try: oPartCompDef.UseSheetMetalStyleThickness = True
		Catch : Logger.Info("ERROR in UseSheetMetalStyleThickness: " & oPartDoc.DisplayName)
		End Try
		
		Try : oPartCompDef.UseSheetMetalStyleUnfoldMethod = True
		Catch : Logger.Info("ERROR in UseSheetMetalStyleUnfoldMethod: " & oPartDoc.DisplayName)
		End Try
		
		Try : oPartCompDef.UseSheetMetalStyleMaterial = True
		Catch : Logger.Info("ERROR in UseSheetMetalStyleMaterial: " & oPartDoc.DisplayName)
		End Try
		
		Logger.Info("Active Rule: " & oPartCompDef.ActiveSheetMetalStyle.Name)
		
		If oSMStyle Is Nothing Then
			Dim oSMStyles As SheetMetalStyles = oPartCompDef.SheetMetalStyles
			Dim oSMStyleList As New List(Of String)
			For i = 1 To oPartCompDef.SheetMetalStyles.Count
				oSMStyleList.Add(oPartCompDef.SheetMetalStyles.Item(i).Name)
			Next i
			
			oSMStyleName = InputListBox("Select Sheetmetal Rule", oSMStyleList, oPartCompDef.SheetMetalStyles(1), Title := "Title", ListName := "List")
			Try
				oSMStyle = oPartCompDef.SheetMetalStyles.Item(oSMStyleName)
			Catch
				MessageBox.Show("No Style Selected, Exiting")
			End Try
			Logger.Info(oSMStyleName)
			
		End If
		
		Try
			oPartCompDef.SheetMetalStyles.Item(oSMStyleName).Activate
			Logger.Info("NEW Rule: " & oPartCompDef.ActiveSheetMetalStyle.Name)
		Catch :
			Logger.Info("ERROR: " & oPartDoc.DisplayName)
		End Try
			
		If Not oPartCompDef.HasFlatPattern Then
			oPartCompDef.Unfold
		End If
		
	End If
Next

 

0 Likes
Message 11 of 16

Curtis_Waguespack
Consultant
Consultant

Hi @reine_den_andra, see this version of @jnowel's example that will traverse through subassemblies.

Hope that helps, Curtis

 

Sub Main

	If TypeOf ThisApplication.ActiveDocument Is PartDocument Then
		Call SMRules(ThisApplication.ActiveDocument)
		Exit Sub
	ElseIf TypeOf ThisApplication.ActiveDocument Is DrawingDocument Then
		MessageBox.Show("Rule can not be used in a drawing")
		Exit Sub
	End If

	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences

	Call TraverseAssembly(oOccs)

End Sub

Function TraverseAssembly(oOccs As ComponentOccurrences)

Dim oPartDict As New Dictionary(Of String, String)
Dim oOcc As ComponentOccurrence
For Each oOcc In oOccs

	If oOcc.Suppressed = True Then Continue For

	Dim oOccDoc As Document = oOcc.Definition.Document
	Dim oOccDocName As String = oOccDoc.FullDocumentName

	If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	'step into subassembly
	Call TraverseAssembly(oOcc.SubOccurrences)
	Else 'process parts
	If Not oOccDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For 'NOT SHEETMETAL
	If Not oPartDict.ContainsKey(oOccDocName) Then oPartDict.Add(oOccDocName, oOccDocName)

	Logger.Info(oOccDocName)
	Call SMRules(oOccDoc)

	End If
Next

End Function

Sub SMRules(oOccDoc As PartDocument)

Dim oSMStyle As SheetMetalStyle = Nothing

Dim oPartDoc As PartDocument = oOccDoc
Dim oPartCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition

Try : oPartCompDef.UseSheetMetalStyleThickness = True
Catch : Logger.Info("ERROR in UseSheetMetalStyleThickness: " & oPartDoc.DisplayName)
End Try

Try : oPartCompDef.UseSheetMetalStyleUnfoldMethod = True
Catch : Logger.Info("ERROR in UseSheetMetalStyleUnfoldMethod: " & oPartDoc.DisplayName)
End Try

Try : oPartCompDef.UseSheetMetalStyleMaterial = True
Catch : Logger.Info("ERROR in UseSheetMetalStyleMaterial: " & oPartDoc.DisplayName)
End Try

Logger.Info("Active Rule: " & oPartCompDef.ActiveSheetMetalStyle.Name)

If oSMStyle Is Nothing Then
Dim oSMStyles As SheetMetalStyles = oPartCompDef.SheetMetalStyles
Dim oSMStyleList As New List(Of String)
For i = 1 To oPartCompDef.SheetMetalStyles.Count
	oSMStyleList.Add(oPartCompDef.SheetMetalStyles.Item(i).Name)
Next i

oSMStyleName = InputListBox("Select Sheetmetal Rule", oSMStyleList, oPartCompDef.SheetMetalStyles(1), Title := "Title", ListName := "List")
Try
	oSMStyle = oPartCompDef.SheetMetalStyles.Item(oSMStyleName)
Catch
	MessageBox.Show("No Style Selected, Exiting")
End Try
Logger.Info(oSMStyleName)

End If

Try
	oPartCompDef.SheetMetalStyles.Item(oSMStyleName).Activate
	Logger.Info("NEW Rule: " & oPartCompDef.ActiveSheetMetalStyle.Name)
Catch :
	Logger.Info("ERROR: " & oPartDoc.DisplayName)
End Try

If Not oPartCompDef.HasFlatPattern Then
oPartCompDef.Unfold
End If

End Sub
0 Likes
Message 12 of 16

reine_den_andra
Enthusiast
Enthusiast

Thank you for reply! 😀

I will try this tomorrow at work. (Sweden 18:50 a clock) 😁

0 Likes
Message 13 of 16

reine_den_andra
Enthusiast
Enthusiast

Hi!

I have tested this now. It's a bit strange. The box about which sheet metal rule you want opens up for each detail. In this case, 50 times in an assembly with subassemblies and parts 😁.

Even if the SAME part is in multiple places.
In a perfect world, I would wish that the first code I posted, @jnowel´s could take subassemblies.

0 Likes
Message 14 of 16

jnowel
Collaborator
Collaborator
Accepted solution

hmm. I think it might be better to just run thru all the referenced documents instead of relying on the component occurrence like in the original code.

Try the one below.

If Not TypeOf ThisApplication.ActiveDocument Is AssemblyDocument Then 
	MessageBox.Show("Use this rule in an Assy only")
	Exit Sub
End If

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oOcc As ComponentOccurrence
Dim oSMStyle As SheetMetalStyle = Nothing

For Each oRefDoc As Document In oADoc.AllReferencedDocuments

	If Not oRefDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For 'NOT SHEETMETAL
	
	Dim oPartDoc As PartDocument = oRefDoc
	Dim oPartCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
	
	If oSMStyle Is Nothing Then
		Dim oSMStyles As SheetMetalStyles = oPartCompDef.SheetMetalStyles
		Dim oSMStyleList As New List(Of String)
		For i = 1 To oPartCompDef.SheetMetalStyles.Count
			oSMStyleList.Add(oPartCompDef.SheetMetalStyles.Item(i).Name)
		Next i
		
		oSMStyleName = InputListBox("Select Sheetmetal Rule", oSMStyleList, oPartCompDef.SheetMetalStyles(1), Title := "Title", ListName := "List")
		Try
			oSMStyle = oPartCompDef.SheetMetalStyles.Item(oSMStyleName)
		Catch
			MessageBox.Show("No Style Selected, Exiting")
		End Try
		Logger.Info(vbLf & "Selected Sheetmetal Style: " & oSMStyleName & vbLf)
		
	End If
	
	Logger.Info(oRefDoc.DisplayName)
	
	Try: oPartCompDef.UseSheetMetalStyleThickness = True
	Catch : Logger.Info("     ERROR in UseSheetMetalStyleThickness: " & oPartDoc.DisplayName)
	End Try
	
	Try : oPartCompDef.UseSheetMetalStyleUnfoldMethod = True
	Catch : Logger.Info("    ERROR in UseSheetMetalStyleUnfoldMethod: " & oPartDoc.DisplayName)
	End Try
	
	Try : oPartCompDef.UseSheetMetalStyleMaterial = True
	Catch : Logger.Info("    ERROR in UseSheetMetalStyleMaterial: " & oPartDoc.DisplayName)
	End Try
	
	Logger.Info("     Active Rule: " & oPartCompDef.ActiveSheetMetalStyle.Name)
		
	Try
		oPartCompDef.SheetMetalStyles.Item(oSMStyleName).Activate
		Logger.Info("     NEW Rule: " & oPartCompDef.ActiveSheetMetalStyle.Name)
	Catch :
		Logger.Info("     ERROR: SM Style Missing/Not Applied")
	End Try
		
	If Not oPartCompDef.HasFlatPattern Then
		oPartCompDef.Unfold
	End If
	

Next

 

(I also changed the logger info so it makes it easier to check the issues)

jnowel_1-1768901514560.png

 

 

 

 

0 Likes
Message 15 of 16

reine_den_andra
Enthusiast
Enthusiast

Oh my god! 😀😀😀
You're absolutely amazing at this. This is so good I feel guilty.
How can I thank you?

0 Likes
Message 16 of 16

jnowel
Collaborator
Collaborator

all good. I'm still also learning as well here in the forums.😁
seeing other people's solutions give me ideas and perspective; and solving problems also help me practice