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.

Wednesday, August 6, 2014

Any topics you would like to see?

After Part 3 of The Power of Ilogic I would like to go to a topic that is suggested by you out there.  If there is some task or what have you that would be easier if it were automated or just wondering how to do something.  Please post your question or situation in the comments and I would love to hear from you and help out.

Monday, August 4, 2014

Power of ilogic Part 2...

So, in Part 1 we looked at pulling information from Excel and putting it into Inventor.  And, as a reminder this is what the code looked like for that process.
GoExcel.Open("C:\Users\Public\Documents\Autodesk\Inventor 2015\Templates\Projects template.xlsx", "Sheet1")
iProperties.Value("Project", "Revision Number") = GoExcel.CellValue("B8")
iProperties.Value("Summary", "Manager") = GoExcel.CellValue("B6")
iProperties.Value("Summary", "Company") = GoExcel.CellValue("B5")
iProperties.Value("Project", "Project") = GoExcel.CellValue("B1")
iProperties.Value("Project", "Engineer") = GoExcel.CellValue("B7")
iProperties.Value("Custom", "Customer") = GoExcel.CellValue("B2")
iProperties.Value("Custom", "Address1") = GoExcel.CellValue("B3")
iProperties.Value("Custom", "Address2") = GoExcel.CellValue("B4")

This time we are going to look at how to take information from Inventor and put it into Excel.  We are going to use the same excel file as last time and just ad some more stuff to it.  We will use P1's code as our reference.
GoExcel.Open("C:\Users\Public\Documents\Autodesk\Inventor 2015\Templates\Projects template.xlsx", "Sheet1")
GoExcel.CellValue("B19") = iProperties.Value("Project", "Revision Number")
GoExcel.CellValue("B17") = iProperties.Value("Summary", "Manager")
GoExcel.CellValue("B16") = iProperties.Value("Summary", "Company")
GoExcel.CellValue("B12") = iProperties.Value("Project", "Project")
GoExcel.CellValue("B18") = iProperties.Value("Project", "Engineer")
GoExcel.CellValue("B13") = iProperties.Value("Custom", "Customer")
GoExcel.CellValue("B14") = iProperties.Value("Custom", "Address1")
GoExcel.CellValue("B15") = iProperties.Value("Custom", "Address2")

Notice that in this code we basically just flipp flopped what was on each side of the equal sign.
These are simple codes for pulling info out of an Inventor file.  In Part 3 we will look at writing a rule that will create an excel doc for us and then pull information out of your inventor part and input it into the newly created excel doc.