Ilogic - Add Standard Virtual Parts From an Excel File

Ilogic - Add Standard Virtual Parts From an Excel File

brendan.henderson
Advisor Advisor
2,828 Views
24 Replies
Message 1 of 25

Ilogic - Add Standard Virtual Parts From an Excel File

brendan.henderson
Advisor
Advisor

I'm having a crack at using code supplied by @Curtis_Waguespack but it keeps producing an error, shown below.

 

I have changed the code to reflect the location and name of the excel file, and commented out some of the iProp rows I don't need.  

 

Also attached is the excel file and the customised code. Really appreciate anybody having a look at this for me.

 

cw.jpg

Brendan Henderson
CAD Manager


New Blog | Old Blog | Google+ | Twitter


Inventor 2016 PDSU Build 236, Release 2016.2.2, Vault Professional 2016 Update 1, Win 7 64 bit


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Accepted solutions (3)
2,829 Views
24 Replies
Replies (24)
Message 21 of 25

Curtis_Waguespack
Consultant
Consultant

Hi @e_frissell ,

 

I think that would look like this. You might need to adjust a bit ( I didn't test) .

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim myXLS As String = "C:\TEMP\Test98.xlsx"
Dim oFileDlg As Inventor.FileDialog

Try
	GoExcel.Open(myXLS, "Sheet1")
Catch

	
	ThisApplication.CreateFileDialog(oFileDlg)
	oFileDlg.Filter = "Microsoft Excel Files (*.xlsx; *.xls)|*.xlsx;*.xls|"
	oFileDlg.ShowOpen()
	
	If oFileDlg.FileName = ""
		MessageBox.Show("Excel file not selected", "iLogic", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
		Exit Sub
	End If
	
	myXLS = oFileDlg.FileName

	GoExcel.Open(myXLS, "Sheet1")
	
End Try

'do impressive things with the Excel data here
'do impressive things with the Excel data here
'do impressive things with the Excel data here


GoExcel.Close

 

EESignature

0 Likes
Message 22 of 25

e_frissell
Advocate
Advocate

Way cool, that worked!  I had thought a return value would be needed if the file didn't exist to prevent an error but it works just fine

Message 23 of 25

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@e_frissell 

 

This is another way to do this, that I think I like a better than the try/catch mostly because of the way the GoExcel function works behind the scenes. If you see any glitches with the try/catch version you might give this a try.

 

Dim myXLS As String = "C:\TEMP\Test98.xlsx"
Dim oFilename As String = System.IO.Path.GetFileName(myXLS)

If System.IO.File.Exists(oFilename) = False Then
	Dim oFileDlg As Inventor.FileDialog
	ThisApplication.CreateFileDialog(oFileDlg)
	oFileDlg.Filter = "Microsoft Excel Files (*.xlsx; *.xls)|*.xlsx;*.xls|"
	oFileDlg.ShowOpen()
	If oFileDlg.FileName = ""
		MessageBox.Show("Excel file not selected", "iLogic", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
		Exit Sub
	End If	
	myXLS = oFileDlg.FileName	
End If

GoExcel.Open(myXLS, "Sheet1")
'do impressive things with the Excel data here
'do impressive things with the Excel data here
'do impressive things with the Excel data here
GoExcel.Close

 

EESignature

0 Likes
Message 24 of 25

e_frissell
Advocate
Advocate

Nice!  The try-catch is working right now, and while I can't explain why I like this one more than the try catch method, I do like it and I'll update the code to this

0 Likes
Message 25 of 25

e_frissell
Advocate
Advocate

@Curtis_Waguespack funny story moved ahead with phase 2 of my script and the try-catch method posted the other day errored out, swapped it for this second method, and it works great