Monday, August 11, 2014

The Power of Ilogic...Part 3...

In parts 1 & 2 we looked at how to pull information into inventor from an excel doc and also how to pull information from inventor into excel.  On this last part we are going to look at how to create an excel doc using ilogic and then pull information from inventor into that newly created excel doc.  So, let's go ahead and dive in.
Below is the code that we are going to look at:

myXLS_file = "C:\Users\Public\Documents\Autodesk\Inventor 2015\Templates\" & iProperties.Value("Custom", "Customer") & "-" & iProperties.Value("Project", "Project") & ".xls"
excelApp = CreateObject("Excel.Application")
excelApp.Visible = False
excelApp.DisplayAlerts = False

If dir(myXLS_file)<>"" Then
excelWorkbook = excelApp.Workbooks.Open(myXLS_file)
excelSheet = excelWorkbook.Worksheets(1).activate
excelWorkbook = excelApp.Workbooks.Add
End If

With excelApp
'iproperties call out
.ActiveCell.Value = "Project:"
.ActiveCell.Value = "Customer:"
.ActiveCell.Value = "Address Line 1:"
.ActiveCell.Value = "Address Line 2:"
.ActiveCell.Value = "Company:"
.ActiveCell.Value = "Manager:"
.ActiveCell.Value = "Engineer:"
.ActiveCell.Value = "Rev Number:"
'iproperties info being exported
.ActiveCell.Value = iProperties.Value("Project", "Revision Number")
.ActiveCell.Value = iProperties.Value("Summary", "Manager")
.ActiveCell.Value = iProperties.Value("Summary", "Company")
.ActiveCell.Value = iProperties.Value("Project", "Project")
.ActiveCell.Value = iProperties.Value("Project", "Engineer")
.ActiveCell.Value = iProperties.Value("Custom", "Customer")
.ActiveCell.Value = iProperties.Value("Custom", "Address1")
.ActiveCell.Value = iProperties.Value("Custom", "Address2")
End With
excelApp = Nothing

At the beginning of this code we are defining the path in which the file is going to be saved and also defining the name of the excel file being created.  In the naming of the excel document we are pulling Inventor iproperties out to give it the name.

One other thing that you will notice is the difference in which we are pulling out the information.  In this form we are calling to activate a certain cell and then populate it with the text or property that we assign to it.  Where as in the other parts we are calling to an excel app where as before we called out "GoExcel".  With calling the excel app we are basically starting a new file from scratch which is why we can't do the "GoExcel".  Once you have placed the code to fill in the cells how you want it then we do our coding to autofit the columns to the text, and then we do a save as which refers to the initial variable that we defined in the code.  Then we call an excel close to close the file and quit to end the excelapp to make sure that Inventor fully closes out of the excel function.

No comments:

Post a Comment