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

Unable to cast COM object error - for loop erroring out on certain sub assemblies, need help understanding

ilogic help.gif

Hello, I have a few iLogic rules that I use to help automate the iProperties on the configurators.  I use them across most of my configurators but every once in a while it errors out on specific subassemblies or components.  In this case, if I suppress sub assembly VTHFAB4-MCI:1 , there is no error.  So I tried to add an if statement just to skip that sub assembly but I am getting this error.  I need help understanding why this would error out for specific components or sub assemblies.  Also help understanding the error message for the conditional statement.  Any help would be greatly appreciated. 

 

Added conditional statement is on sub iPropPartsProject

 

PREED7QR59_0-1666902507619.png

 

 

'iPropertiesRule
	'This rule will change the various iProperties of the Assembly, SubAssemblies and Piece parts.   
	
	'Requires -  User parameters (Text): Designer, Project

Sub main()
	iProp
	iPropColumn
	iPropPartsProject
	iPropPartsDate
	iPropPartsDesigner
End Sub


'Changes Project of Assembly from the input on the form
Sub iProp
	
	iProperties.Value("Project", "Project") = Project

End Sub


'Changes custom Material iProperty for Assembly and Subassemblies, places catelog part number, places desciption based on material
Sub iPropColumn
	
	Select Case PumpSize

		Case "4.0 in"
			
			iProperties.Value("ColumnPipe:1", "Project", "Stock Number") = "PP4SCH40C"
			iProperties.Value("ColumnPipe:1", "Project", "Description") = "PIPE, 4 in SCH40 - PP4SCH40C"
			iProperties.Value("ColumnPipe:1", "Project", "Part Number") = "4 IN COLUMN"

		Case "6.0 in"
			
			iProperties.Value("ColumnPipe:1", "Project", "Stock Number") = "PP6SCH40C"
			iProperties.Value("ColumnPipe:1", "Project", "Description") = "PIPE, 6 in SCH40 - PP6SCH40C"
			iProperties.Value("ColumnPipe:1", "Project", "Part Number") = "6 IN COLUMN"
			
		Case "8.0 in"
			
			iProperties.Value("ColumnPipe:1", "Project", "Stock Number") = "PP8SCH40C"
			iProperties.Value("ColumnPipe:1", "Project", "Description") = "PIPE, 8 in SCH40 - PP8SCH40C"
			iProperties.Value("ColumnPipe:1", "Project", "Part Number") = "8 IN COLUMN"
	
	End Select
	
End Sub


'Goes through all parts & subassemblies and replaces the Project based on form inputs
Sub iPropPartsProject
	
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all Of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef)  
	
	If oOccurrence = "VTHFAB4-MCI:1" Then
	
	Else
		'create iprop with default Value
		iProperties.Value("Project", "Project") = Project
		'write to component iprops
		iProperties.Value(oOccurrence.Name, "Project", "Project") = _
		iProperties.Value("Project", "Project")
		MessageBox.Show(oOccurrence.Name, "Title")
	End If
	On Error Resume Next
Next

End Sub


'Pulls current date and goes though and updates date for every part, sub assembly and assembly
Sub iPropPartsDate
	
	Dim strFileName As String
	strFileName = ThisDoc.Document.FullFileName
	Dim oFS As Object
	oFS = CreateObject("Scripting.FileSystemObject")
	Dim oDate1 As String
	'Dim oDate2 As String
	oDate1 = oFS.GetFile(strFileName).DateLastModified
	'oDate2 = oFS.GetFile(strFileName).DateCreated

	'MessageBox.Show(oDate1 & " and " & oDate2)

	Dim oAsmCompDef As AssemblyComponentDefinition
	oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

	'Iterate through all Of the occurrences
	Dim oOccurrence As ComponentOccurrence
	For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef)  

			'create iprop with default Value
			iProperties.Value("Project", "Creation Date") = oDate1
			'write to component iprops
			iProperties.Value(oOccurrence.Name, "Project", "Creation Date") = _
			iProperties.Value("Project", "Creation Date")

		On Error Resume Next
	Next

End Sub


'Pulls designer from form and goes though and updates designer for every part, sub assembly and assembly
Sub iPropPartsDesigner
	
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all Of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef)  
	
		'create iprop with default Value
		iProperties.Value("Project", "Designer") = Designer
		'write to component iprops
		iProperties.Value(oOccurrence.Name, "Project", "Designer") = _
		iProperties.Value("Project", "Designer")
		
	On Error Resume Next
Next

End Sub
Labels (3)