- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
has anyone changed sheet metal styles from the assembly?
I'm trying to run the ChangeStyleToNewOne rule on each of the sheetmetal parts in an assembly, but it's not working.
Does anyone have any ideas how I can fix it?
Sub Main() Dim thisAssyDoc As AssemblyDocument = CType(ThisDoc.Document, AssemblyDocument) AddCusProp(thisAssyDoc) End Sub Sub AddCusProp(assemblyDoc As AssemblyDocument)
For Each subCompOcc As ComponentOccurrence In assemblyDoc.ComponentDefinition.Occurrences Dim oPartDoc As PartDocument= subCompOcc.ActiveEditDocument If oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Dim oscCompDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition Dim ActiveStyle As SheetMetalStyle = oscCompDef.ActiveSheetMetalStyle ChangeStyleToNewOne(ActiveStyle) ElseIf oPartDoc.SubType = DocumentTypeEnum.kAssemblyDocumentObject Then AddCusProp(oPartDoc.Definition.Document) End If Next End Sub Sub ChangeStyleToNewOne(ActiveStyle) If ActiveStyle = "10ga GA Brt" Then SheetMetal.SetActiveStyle("10ga GA Brt (Test)") ElseIf ActiveStyle = "10ga GA Jkt" Then SheetMetal.SetActiveStyle("10ga GA Jkt (Test)") ElseIf ActiveStyle = "10ga SS 304L Solid" Then SheetMetal.SetActiveStyle("10ga SS 304L Solid (Test)") ElseIf ActiveStyle = "12ga GA Brt" Then SheetMetal.SetActiveStyle("12ga GA Brt (Test)") ElseIf ActiveStyle = "12ga GA Jkt" Then SheetMetal.SetActiveStyle("12ga GA Jkt (Test)") ElseIf ActiveStyle = "14ga GA Brt" Then SheetMetal.SetActiveStyle("14ga GA Brt (Test)") ElseIf ActiveStyle = "14ga GA Jkt" Then SheetMetal.SetActiveStyle("14ga GA Jkt (Test)") ElseIf ActiveStyle = "14ga SS 304L Solid" Then SheetMetal.SetActiveStyle("14ga SS 304L Solid (Test)") ElseIf ActiveStyle = "16ga GA Brt" Then SheetMetal.SetActiveStyle("16ga GA Brt (Test)") ElseIf ActiveStyle = "16ga GA Jkt" Then SheetMetal.SetActiveStyle("16ga GA Jkt (Test)") ElseIf ActiveStyle = "16ga SS 304L Solid" Then SheetMetal.SetActiveStyle("16ga SS 304L Solid (Test)") ElseIf ActiveStyle = "18ga GA Brt" Then SheetMetal.SetActiveStyle("18ga GA Brt (Test)") ElseIf ActiveStyle = "18ga GA Jkt" Then SheetMetal.SetActiveStyle("18ga GA Jkt (Test)") ElseIf ActiveStyle = "18ga SS 304L Solid" Then SheetMetal.SetActiveStyle("18ga SS 304L Solid (Test)") ElseIf ActiveStyle = "20ga GA Brt" Then SheetMetal.SetActiveStyle("20ga GA Brt (Test)") ElseIf ActiveStyle = "20ga GA Jkt" Then SheetMetal.SetActiveStyle("20ga GA Jkt (Test)") Else SheetMetal.SetActiveStyle("Default") iProperties.Value("Project", "Stock Number") = "Material no disponible para tolerancias" iProperties.Value("Project", "Description") = "Material no disponible para tolerancias" End If End Sub
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This worked
Dim oDoc As PartDocument oDoc = ThisApplication.ActiveDocument Dim oCompDef As SheetMetalComponentDefinition oCompDef = oDoc.ComponentDefinition oCompDef.SheetMetalStyles.Item("18GA GA Jkt (Test)").Activate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
What version of Inventor are you using? Try this version of your code. I changed a few thing around, and I am using a fairly new tool to direct all those vague iLogic snippets to the proper document reference. If you have any questions about any of this, feel free to ask them.
Sub Main()
Dim thisAssyDoc As AssemblyDocument = CType(ThisDoc.Document, AssemblyDocument)
AddCusProp(thisAssyDoc)
End Sub
Sub AddCusProp(assemblyDoc As AssemblyDocument)
For Each subCompOcc As ComponentOccurrence In assemblyDoc.ComponentDefinition.Occurrences
If subCompOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
AddCusProp(subCompOcc.Definition.Document)
End If
If Not TypeOf subCompOcc.Definition Is SheetMetalComponentDefinition Then Continue For
Dim oscCompDef As SheetMetalComponentDefinition = subCompOcc.Definition
Dim ActiveStyle As SheetMetalStyle = oscCompDef.ActiveSheetMetalStyle
ChangeStyleToNewOne(oscCompDef.Document, ActiveStyle)
Next
End Sub
Sub ChangeStyleToNewOne(oSMDoc As PartDocument, ActiveStyle As SheetMetalStyle)
Dim SOP = StandardObjectFactory.Create(oSMDoc)
If ActiveStyle.Name = "10ga GA Brt" Then
SOP.SheetMetal.SetActiveStyle("10ga GA Brt (Test)")
ElseIf ActiveStyle.Name = "10ga GA Jkt" Then
SOP.SheetMetal.SetActiveStyle("10ga GA Jkt (Test)")
ElseIf ActiveStyle.Name = "10ga SS 304L Solid" Then
SOP.SheetMetal.SetActiveStyle("10ga SS 304L Solid (Test)")
ElseIf ActiveStyle.Name = "12ga GA Brt" Then
SOP.SheetMetal.SetActiveStyle("12ga GA Brt (Test)")
ElseIf ActiveStyle.Name = "12ga GA Jkt" Then
SOP.SheetMetal.SetActiveStyle("12ga GA Jkt (Test)")
ElseIf ActiveStyle.Name = "14ga GA Brt" Then
SOP.SheetMetal.SetActiveStyle("14ga GA Brt (Test)")
ElseIf ActiveStyle.Name = "14ga GA Jkt" Then
SOP.SheetMetal.SetActiveStyle("14ga GA Jkt (Test)")
ElseIf ActiveStyle.Name = "14ga SS 304L Solid" Then
SOP.SheetMetal.SetActiveStyle("14ga SS 304L Solid (Test)")
ElseIf ActiveStyle.Name = "16ga GA Brt" Then
SOP.SheetMetal.SetActiveStyle("16ga GA Brt (Test)")
ElseIf ActiveStyle.Name = "16ga GA Jkt" Then
SOP.SheetMetal.SetActiveStyle("16ga GA Jkt (Test)")
ElseIf ActiveStyle.Name = "16ga SS 304L Solid" Then
SOP.SheetMetal.SetActiveStyle("16ga SS 304L Solid (Test)")
ElseIf ActiveStyle.Name = "18ga GA Brt" Then
SOP.SheetMetal.SetActiveStyle("18ga GA Brt (Test)")
ElseIf ActiveStyle.Name = "18ga GA Jkt" Then
SOP.SheetMetal.SetActiveStyle("18ga GA Jkt (Test)")
ElseIf ActiveStyle.Name = "18ga SS 304L Solid" Then
SOP.SheetMetal.SetActiveStyle("18ga SS 304L Solid (Test)")
ElseIf ActiveStyle.Name = "20ga GA Brt" Then
SOP.SheetMetal.SetActiveStyle("20ga GA Brt (Test)")
ElseIf ActiveStyle.Name = "20ga GA Jkt" Then
SOP.SheetMetal.SetActiveStyle("20ga GA Jkt (Test)")
Else
SOP.SheetMetal.SetActiveStyle("Default")
SOP.iProperties.Value("Project", "Stock Number") = "Material no disponible para tolerancias"
SOP.iProperties.Value("Project", "Description") = "Material no disponible para tolerancias"
End If
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS)
.
If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This code show this error
Error on Line 19 : 'StandardObjectFactory' is not declared. It may be inaccessible due to its protection level.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
OK. I think that StandardObjectFactory.Create() tool just became available in Inventor 2022, so that will not be an option to use in this situation. The idea of using it though, was because that "SheetMetal" iLogic snippet does not have a way for you to specify which document you want it to act upon (target), and this would have been one way of making it target a specific document. The "iProperties.Value()" iLogic snippet does allow you to specify either a component name or document name, as the first (of 3) input variables, but that can be confusing to use too, when you are wanting it to target another document. In situations like this, I usually prefer to eliminate the use of that iProperties.Value snippet, in favor of the regular Inventor API route:
Document.PropertySets.Item("PropertySetName").Item("PropertyName").Value
That way you can start from an actual Document object, so you know for sure which document you are dealing with. The SheetMetal snippet can also be avoided, in favor of similar (but longer) API route if needed, similar to the code that @dalton98 posted.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Sub Main()
Dim thisAssyDoc As AssemblyDocument = CType(ThisDoc.Document, AssemblyDocument)
ChangeToTest(thisAssyDoc)
End Sub
Sub ChangeToTest(assemblyDoc As AssemblyDocument)
For Each subCompOcc As ComponentOccurrence In assemblyDoc.ComponentDefinition.Occurrences
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
If oCompDef is oDoc.ComponentDefinition Then
oCompDef.SheetMetalStyles.Item("18ga GA JKT (Test)").Activate
Else
MessageBox.Show("Fail", "Title")
End If
Next
End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here is a working code to change the style of level one occurrences in an assembly. If the sheetmetal parts are in a subassembly you will need additional code to detect an assembly and iterate through those as well.
Sub Main() Dim thisAssyDoc As AssemblyDocument = CType(ThisDoc.Document, AssemblyDocument) ChangeToTest(thisAssyDoc) End Sub Sub ChangeToTest(assemblyDoc As AssemblyDocument) For Each subCompOcc As ComponentOccurrence In assemblyDoc.ComponentDefinition.Occurrences Dim oCompDef As ComponentDefinition = subCompOcc.Definition If TypeOf oCompDef Is SheetMetalComponentDefinition Then oCompDef = subCompOcc.Definition Try oCompDef.SheetMetalStyles.Item("18ga GA JKT (Test)").Activate Catch MessageBox.Show("Fail to find Style", "Title") End Try Else MessageBox.Show("Fail", "Title") End If Next End Sub
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @antonio.silvaluna. Here is another version you can try that is similar to the last one I posted. But this version does not use the StandardObjectFactory route. Instead it uses the API route. I also combined the two Sub routines into one. That Sub routine might even be simplified even further since the 'test' version of SheetMetalStyle is always named exactly the same as the original, but with the " (Test)" at the end if its name. It might just be able to capture its current SheetMetalStyle name, check if it 'EndsWith' " (Test)", and if not, try to change it to the same name with that at the end of it. But I don't know if that would fit your more practical needs later. But since the other 'Test' version SheetMetalStyle might not exist, in order to avoid that potential error without making the code exponentially longer, I incorporated a Try...Catch statement, and put the main task inside of that. And since I don't know how many components you may be cycling through, in the Catch side I left the MsgBox commented out, and left the Logger line un-commented, to help it run more smoothly. You would then want to check your iLogicLog tab to see if it encountered any problems afterwards.
Sub Main()
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
ChangeToTest(oADoc)
End Sub
Sub ChangeToTest(oADoc As AssemblyDocument)
For Each oOcc As ComponentOccurrence In oADoc.ComponentDefinition.Occurrences
If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
ChangeToTest(oOcc.Definition.Document)
End If
If Not TypeOf oOcc.Definition Is SheetMetalComponentDefinition Then Continue For
Dim oSMDef As SheetMetalComponentDefinition = oOcc.Definition
Dim ActiveStyle As SheetMetalStyle = oSMDef.ActiveSheetMetalStyle
'since the other named SheetMetalStyle may not exist, we will use a Try...Catch statement
Try
If ActiveStyle.Name = "10ga GA Brt" Then
oSMDef.SheetMetalStyles.Item("10ga GA Brt (Test)").Activate
ElseIf ActiveStyle.Name = "10ga GA Jkt" Then
oSMDef.SheetMetalStyles.Item("10ga GA Jkt (Test)").Activate
ElseIf ActiveStyle.Name = "10ga SS 304L Solid" Then
oSMDef.SheetMetalStyles.Item("10ga SS 304L Solid (Test)").Activate
ElseIf ActiveStyle.Name = "12ga GA Brt" Then
oSMDef.SheetMetalStyles.Item("12ga GA Brt (Test)").Activate
ElseIf ActiveStyle.Name = "12ga GA Jkt" Then
oSMDef.SheetMetalStyles.Item("12ga GA Jkt (Test)").Activate
ElseIf ActiveStyle.Name = "14ga GA Brt" Then
oSMDef.SheetMetalStyles.Item("14ga GA Brt (Test)").Activate
ElseIf ActiveStyle.Name = "14ga GA Jkt" Then
oSMDef.SheetMetalStyles.Item("14ga GA Jkt (Test)").Activate
ElseIf ActiveStyle.Name = "14ga SS 304L Solid" Then
oSMDef.SheetMetalStyles.Item("14ga SS 304L Solid (Test)").Activate
ElseIf ActiveStyle.Name = "16ga GA Brt" Then
oSMDef.SheetMetalStyles.Item("16ga GA Brt (Test)").Activate
ElseIf ActiveStyle.Name = "16ga GA Jkt" Then
oSMDef.SheetMetalStyles.Item("16ga GA Jkt (Test)").Activate
ElseIf ActiveStyle.Name = "16ga SS 304L Solid" Then
oSMDef.SheetMetalStyles.Item("16ga SS 304L Solid (Test)").Activate
ElseIf ActiveStyle.Name = "18ga GA Brt" Then
oSMDef.SheetMetalStyles.Item("18ga GA Brt (Test)").Activate
ElseIf ActiveStyle.Name = "18ga GA Jkt" Then
oSMDef.SheetMetalStyles.Item("18ga GA Jkt (Test)").Activate
ElseIf ActiveStyle.Name = "18ga SS 304L Solid" Then
oSMDef.SheetMetalStyles.Item("18ga SS 304L Solid (Test)").Activate
ElseIf ActiveStyle.Name = "20ga GA Brt" Then
oSMDef.SheetMetalStyles.Item("20ga GA Brt (Test)").Activate
ElseIf ActiveStyle.Name = "20ga GA Jkt" Then
oSMDef.SheetMetalStyles.Item("20ga GA Jkt (Test)").Activate
Else
oSMDef.SheetMetalStyles.Item("Default").Activate
Dim oSMDoc As PartDocument = oSMDef.Document
oSMDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value = "Material no disponible para tolerancias"
oSMDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value = "Material no disponible para tolerancias"
End If
Catch oEx As Exception
'MsgBox(oEx.Message & vbCrLf & oEx.StackTrace, vbExclamation, "")
Logger.Error(oEx.Message & vbCrLf & oEx.StackTrace)
End Try
Next
End Sub
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report