iLogic add iproperties from Excel

iLogic add iproperties from Excel

jishee
Enthusiast Enthusiast
1,617 Views
8 Replies
Message 1 of 9

iLogic add iproperties from Excel

jishee
Enthusiast
Enthusiast

I have a rule that adds custom iProperties to parts in an assembly from an Excel file. The rule runs as expected the first time it is run, however if I make a change to the Excel file and run the rule again to update the iProperties, I get an error. The rule is below. I am not advanced enough yet (but learning lots) to determine why it runs the first time but not again after changes. Thank you for any help.

 

oDocFile = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oOcc As ComponentOccurrence
Dim oDocFileName As String
Dim oFileNamePos As Long

For Each oOcc In oAsmCompDef.Occurrences
	
If Not TypeOf oOcc.Definition Is VirtualComponentDefinition Then
	
	oDocFile = oOcc.Definition.Document
	'Find position in full filename path string where component filename begins
	oFileNamePos = InStrRev(oDocFile.FullFileName, "\", - 1)
	'Strip off filename path string and set oDocFileName to just the component's file name
	oDocFileName = Mid(oDocFile.FullFileName, oFileNamePos + 1, Len(oDocFile.FullFileName) - oFileNamePos)
			'Set your delimiter
			Delimiter = InStr(oDocFileName, "-")
			Description = Left(oDocFileName, Delimiter - 1)
			
			'Open the Excel file
			GoExcel.Open("C:\Users\jishee\Documents\Work\Inventor_modeling\iLogic\Unit_Drawing_Tests\Part_iProperties.xlsx", "Parts")
						
			'Look at the first 15 rows of the Excel file
			'Start at row 2, since row 1 contains headings
			For rowCheck = 2 To 15
				'Compare the part name to the value in column A
        		If GoExcel.CellValue("A" & rowCheck) = Description Then
           			iProperties.Value(oDocFileName, "Custom", "Extrusion") = GoExcel.CellValue("B" & rowCheck)      
           			iProperties.Value(oDocFileName, "Custom", "Alloy-Temper") = GoExcel.CellValue("C" & rowCheck)
           			iProperties.Value(oDocFileName, "Custom", "Material") = GoExcel.CellValue("D" & rowCheck)
           			iProperties.Value(oDocFileName, "Custom", "Finish") = GoExcel.CellValue("E" & rowCheck)
           			iProperties.Value(oDocFileName, "Custom", "Color") = GoExcel.CellValue("F" & rowCheck)
           			iProperties.Value(oDocFileName, "Custom", "Hydro Code") = GoExcel.CellValue("G" & rowCheck)
           			iProperties.Value(oDocFileName, "Custom", "Routing") = GoExcel.CellValue("H" & rowCheck)
           			iProperties.Value(oDocFileName, "Project", "Description") = GoExcel.CellValue("I" & rowCheck)
				End If
			Next

			'Open the Excel file
			GoExcel.Open("C:\Users\jishee\Documents\Work\Inventor_modeling\iLogic\Unit_Drawing_Tests\Part_iProperties.xlsx", "Infills")

			'Look at the first 15 rows of the Excel file
			'Start at row 2, since row 1 contains headings
			For rowCheck = 2 To 15
				'Compare the part name to the value in column A
        		If GoExcel.CellValue("A" & rowCheck) = Description Then
	       			iProperties.Value(oDocFileName, "Custom", "Routing") = GoExcel.CellValue("B" & rowCheck)      
	       			iProperties.Value(oDocFileName, "Project", "Description") = GoExcel.CellValue("C" & rowCheck)
	       			iProperties.Value(oDocFileName, "Custom", "Make-up") = GoExcel.CellValue("D" & rowCheck)
				End If
			Next
End If
Next oOcc

  

0 Likes
Accepted solutions (2)
1,618 Views
8 Replies
Replies (8)
Message 2 of 9

marcin_otręba
Advisor
Advisor

can you show what error you get?

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 9

jishee
Enthusiast
Enthusiast

jishee_0-1588971475357.png

It shows up on the "Description" line between the message boxes.

jishee_1-1588971572701.png

 

0 Likes
Message 4 of 9

marcin_otręba
Advisor
Advisor

maybe it does not find “-“ in docname? in first message show delimiter and see its value. 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 5 of 9

jishee
Enthusiast
Enthusiast

It gives Delimiter = 0.

0 Likes
Message 6 of 9

marcin_otręba
Advisor
Advisor

i am not at computer right now but first line is confounding,please delete it. also instead of delimiter show docfile fullfilename, than you will know what happened.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 7 of 9

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, why don't you try to put the instruction on error resume next to see if it skips the error and continues with the execution.
I made some changes to your rule and remove what I thought was not necessary, try the code and see if it does what you need.

 

Dim AssyDoc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As AssemblyComponentDefinition = AssyDoc.ComponentDefinition

Dim oDocFile As Document, oDocFileName As String

For Each oOcc  As ComponentOccurrence In oAsmCompDef.Occurrences
	If Not TypeOf oOcc.Definition Is VirtualComponentDefinition Then
		On Error Resume Next
		oDocFile = oOcc.Definition.Document
		oDocFileName = oDocFile.displayname
		'Set your delimiter
		Delimiter = InStr(oDocFileName, "-")
		Description = Left(oDocFileName, Delimiter - 1)
				
		'Open the Excel file
		GoExcel.Open("C:\Users\jishee\Documents\Work\Inventor_modeling\iLogic\Unit_Drawing_Tests\Part_iProperties.xlsx", "Parts")
					
		'Look at the first 15 rows of the Excel file
		'Start at row 2, since row 1 contains headings
		For rowCheck = 2 To 15
			'Compare the part name to the value in column A
    		If GoExcel.CellValue("A" & rowCheck) = Description Then
       			iProperties.Value(oDocFileName, "Custom", "Extrusion") = GoExcel.CellValue("B" & rowCheck)      
       			iProperties.Value(oDocFileName, "Custom", "Alloy-Temper") = GoExcel.CellValue("C" & rowCheck)
       			iProperties.Value(oDocFileName, "Custom", "Material") = GoExcel.CellValue("D" & rowCheck)
       			iProperties.Value(oDocFileName, "Custom", "Finish") = GoExcel.CellValue("E" & rowCheck)
       			iProperties.Value(oDocFileName, "Custom", "Color") = GoExcel.CellValue("F" & rowCheck)
       			iProperties.Value(oDocFileName, "Custom", "Hydro Code") = GoExcel.CellValue("G" & rowCheck)
       			iProperties.Value(oDocFileName, "Custom", "Routing") = GoExcel.CellValue("H" & rowCheck)
       			iProperties.Value(oDocFileName, "Project", "Description") = GoExcel.CellValue("I" & rowCheck)
			End If
		Next

		'Open the Excel file
		GoExcel.Open("C:\Users\jishee\Documents\Work\Inventor_modeling\iLogic\Unit_Drawing_Tests\Part_iProperties.xlsx", "Infills")

		'Look at the first 15 rows of the Excel file
		'Start at row 2, since row 1 contains headings
		For rowCheck = 2 To 15
			'Compare the part name to the value in column A
    		If GoExcel.CellValue("A" & rowCheck) = Description Then
       			iProperties.Value(oDocFileName, "Custom", "Routing") = GoExcel.CellValue("B" & rowCheck)      
       			iProperties.Value(oDocFileName, "Project", "Description") = GoExcel.CellValue("C" & rowCheck)
       			iProperties.Value(oDocFileName, "Custom", "Make-up") = GoExcel.CellValue("D" & rowCheck)
			End If
		Next
	End If
Next oOcc

 

If you find an error you can alternately insert a message box inside your rule to search for the source of the error.

I hope some of this can be useful to you. Cheers

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 8 of 9

Darkforce_the_ilogic_guy
Advisor
Advisor
Accepted solution

the reason that you can run it one time and not the second is that you forgot to close the excel file 

 

need to  add 

 

GoExcel.close 

after you are done using it ..  go into joblist and find and force close all excel program and see it work again. 

 

remember to add the GoExcel.Close code if you want to use it more then one time 

0 Likes
Message 9 of 9

jishee
Enthusiast
Enthusiast

Thank you @Sergio.D.Suárez  and @Darkforce_the_ilogic_guy . It is working fine now.

0 Likes