Auto export driven dimension value to Excel

<?xml encoding=”UTF-8″>By Adam Nagy

Sometimes there could be a main dimension that causes the whole model to change, and so the values of the driven dimensions change as well. You could either monitor the main dimension for change using iLogic or one of the driven dimensions. In this case I’m going to do the latter.

Let’s say we have the following part with a sketch that defines the Width and Height of the base of the model. We also have at the bottom a Driven Dimension associated with a Reference Parameter named DrivenWidth which changes when the Width changes:

Dims

I then create a rule named DrivenWidthRule which has DrivenWidth=DrivenWidth in it so it will be recognized as a Driving Rule for DrivenWidth – even though it’s only affected by Width:

Params

DrivenWidthRule:

' To fake a "Driving Rule"
DrivenWidth=DrivenWidth
' Actually simply using the parameter would be enough to trigger the rule
' Dim t = DrivenWidth
xlsFilePath =
"C:UsersAdministratorDocumentsInventorMyProjectparameters.xls"
' Write info to excel file
GoExcel.Open(xlsFilePath, "Sheet1")
' Find the relevant parameter
' (in case we store many of them)
' Names are in column A with title "Name"
i = GoExcel.FindRow(xlsFilePath, "Sheet1", "Name", "=", "DrivenWidth")
If i > 0 Then
' Found it
' Values are in column B
GoExcel.CellValue(xlsFilePath, "Sheet1", "B" + i.ToString()) =
DrivenWidth
End If
GoExcel.Save
GoExcel.Close

Now whenever Width changes, it will change DrivenWidth and so DrivenWidthRule will be called which then can update the values in the Excel file:

Excel

 


Comments

One response to “Auto export driven dimension value to Excel”

  1. Thanks for this post Adam! I needed this for my master thesis. I will give you full credit of course. Now I understand how it’s possible to communicate with excel.

Leave a Reply to Diogo LançaCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading