Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

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

EESignature

(Not an Autodesk Employee)