Help needed: Setting sheet metal rule to predifined parts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to get this to work. I searched quite a bit on this forum and even tried ChatGPT to see if it got me anywhere. I can do some simple iLogic, but this one is over my head. So hopefully someone can help me out here.
What I want to achieve is the following:
I have a Top Level assembly, and there is a parameter called 'Colorchoice". I want this parameter to set the sheet metal rule of certain parts that are located is some subassemblies. In this assemblies I have renamed the brouwser names so I will avoid issues when copying the project.
My chosen structure:
Main Assembly: “TEMPLATE – AS01”
Sub Assembly: “Badvorm”
Contains:
- Part “Vloerplan”
- Sub assembly: “Kopschot Voor”
- Sub assembly: “Kopschot Achter”
- Sub assembly: “Wand Links”
- Sub assembly: “Wand Rechts”
“Kopschot Voor” contains the following parts:
“Wand Voor”
“Rib Wand Voor”
“Rib Randhout Wand Voor”
“Kopschot Achter” contains the following parts:
“Wand Achter”
“Rib Wand Achter”
“Rib Randhout Wand Achter”
“Wand Links” contains the following parts:
“Wand Links”
“Rib Wand Links”
“Rib Randhout Wand Links”
“Wand Rechts” contains the following parts:
“Wand Rechts”
“Rib Wand Rechts”
“Rib Randhout Wand Rechts”
I want to set the Sheet Metal rules only for the for the parts as mentioned above. There are more subassemblies and parts, but these are the only ones that need to be changed. I want the to set a parameter named “oKleur” to hold the value to set the sheet metal rule to.
Sub Main
' Get the active assembly.
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument
' Call the function
Call TraverseAssembly(oAssyDoc.ComponentDefinition.Occurrences)
End Sub
Sub TraverseAssembly(oOccs As ComponentOccurrences)
' Iterate through all of the occurrence in this collection
Dim oOcc As ComponentOccurrence
' Set the parameter value for sheet metal rule
Dim oKleur As String
oKleur = Colorchoice
' Iterate through each sub assembly
For Each subAssembly As ComponentOccurrence In oAssyDoc.ComponentDefinition.Occurrences
If subAssembly.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim subAssemblyDoc As AssemblyDocument
subAssemblyDoc = subAssembly.Definition.Document
' Check if the sub assembly is in the specified list
If subAssembly.Name = "Badvorm" Then
' Iterate through parts in the sub assembly
For Each part As ComponentOccurrence In subAssemblyDoc.ComponentDefinition.Occurrences
If part.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim partDoc As PartDocument
partDoc = part.Definition.Document
' Check if the part is in the specified list
Select Case part.Name
Case "Vloerplan", "Wand Voor", "Rib Wand Voor", "Rib Randhout Wand Voor", _
"Wand Achter", "Rib Wand Achter", "Rib Randhout Wand Achter", _
"Wand Links", "Rib Wand Links", "Rib Randhout Wand Links", _
"Wand Rechts", "Rib Wand Rechts", "Rib Randhout Wand Rechts"
' Set the active sheet metal style
Dim sheetMetal As SheetMetalComponentDefinition
sheetMetal = partDoc.ComponentDefinition
SheetMetal.SetActiveStyle(oKleur)
End Select
End If
Next
End If
End If
Next
End Sub
I am still lost in how to use the Inventor API. I did get some results with some very basic code, but it never did run without issues or stopped working all together. This need to be a more robust piece of code I'm afraigd. I feel like I do understand the bigger picture, but am totally lost is the details...
So any help would be really appreciated. Many thanks in advance!