Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control...

20
December 2-5, 2003 MGM Grand Hotel Las Vegas Control Your Autodesk Inventor® Data with Linked External Parameters Sean Dotson, PE MA43-2 Need to control an assembly or a part file from one master location? Then this course is for you. You learn several methods of linking external information to control the size, shape and function of parts and assemblies. Topics include linked and embedded spreadsheets and derived parameters, the foundation of skeletal modeling. About the Speaker: Sean has worked in the custom automated machinery industry for the last 6 years and currently works for PGT Industries in Florida. He provides design, engineering analysis, and CAD management solutions to three different engineering groups within PGT. Sean also provides training and VB and VBA customization of Autodesk Inventor® to client companies. He is perhaps best known for his numerous tutorials on advanced Autodesk Inventor subjects, which he offers free-of-charge at his website (www.sdotson.com). Sean also co-authored Animator for Autodesk Inventor, an animation add-on application. Sean can be reached at: [email protected]

Transcript of Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control...

Page 1: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

December 2-5, 2003 ◊ MGM Grand Hotel Las Vegas

Control Your Autodesk Inventor® Data with Linked External Parameters Sean Dotson, PE MA43-2 Need to control an assembly or a part file from one master location? Then this course is for you. You learn

several methods of linking external information to control the size, shape and function of parts and assemblies. Topics include linked and embedded spreadsheets and derived parameters, the foundation of skeletal modeling.

About the Speaker: Sean has worked in the custom automated machinery industry for the last 6 years and currently works for PGT Industries in Florida. He provides design, engineering analysis, and CAD management solutions to three different engineering groups within PGT. Sean also provides training and VB and VBA customization of Autodesk Inventor® to client companies. He is perhaps best known for his numerous tutorials on advanced Autodesk Inventor subjects, which he offers free-of-charge at his website (www.sdotson.com). Sean also co-authored Animator for Autodesk Inventor, an animation add-on application. Sean can be reached at: [email protected]

Page 2: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

2

Introduction........................................................................................................... 3

What is the Purpose of using External Data in Model Files? ......................................................................3 Ways to Control Models with External Data .............................................................................................3

Embedding Excel Workbooks................................................................................. 3 Pros and Cons ......................................................................................................................................3 Create the Worksheet ...........................................................................................................................3 Using Data Validation............................................................................................................................4 Assigning Validation to a Cell .................................................................................................................4 Types of Data Validation .......................................................................................................................5 Input and Error Messages .....................................................................................................................6 VLOOKUP and HLOOKUP Functions ........................................................................................................6 Embedding the Worksheet.....................................................................................................................7 Completing the Model ...........................................................................................................................8 Changing and Updating the Model..........................................................................................................9

Linked Excel Workbooks ...................................................................................... 10 Pros and Cons .................................................................................................................................... 10 Creating the Worksheet....................................................................................................................... 10 Linking the Worksheet to Models ......................................................................................................... 11 Completing the Model ......................................................................................................................... 12 Managing Linked Worksheets .............................................................................................................. 12 Some Examples of a Linked Excel Workbook ......................................................................................... 12

Derived Parameters in Part Files ......................................................................... 13 Pros and Cons .................................................................................................................................... 13 Creating the Master Parameter File (“Master”)....................................................................................... 13 Derive in the Master ........................................................................................................................... 14 Creating the Assembly ........................................................................................................................ 15 Changing the Assembly ....................................................................................................................... 16

External Text or Excel files linked via VBA Functions in Parameters ................... 17 Pros and Cons .................................................................................................................................... 17 Creating the Part ................................................................................................................................ 17 Creating the Text File.......................................................................................................................... 18 Writing the Code ................................................................................................................................ 18 Creating the VBA-Parameter Link ......................................................................................................... 19

Conclusions.......................................................................................................... 20

Page 3: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

3

Introduction What is the Purpose of using External Data in Model Files?

Gives the user the ability to control the size and shape of several models from one location Gives the user the ability to perform complex calculations with minimal data entry Gives the Cad Manager the ability to limit the available choices for sizes and dimensions of parts Allows the CAD Manager to create a intuitive user interface for creating families of parts Centralizes and Standardizes model data

Ways to Control Models with External Data There are four popular ways to control your Inventor data externally:

1. Embedded Excel Workbooks 2. Linked Excel Workbooks 3. Derived Parameters in Part Files 4. External Text or Excel files linked via VBA Functions in Parameters

Embedding Excel Workbooks Pros and Cons There are two basic ways to begin the embedding process. The first is to build the model with dummy dimensions, embed the spreadsheet and then equate the model dimension values to the embedded parameter names. The second workflow is to create the embedded worksheet first, embed it into a blank part file and then create the model based on these parameters. While the latter workflow is a bit more streamlined it does require more forethought on the part of the user. I prefer and recommend the first workflow as it allows the user to completely flesh out the model before assigning the variable parameters. Pros:

Data is contained within the file (easy to control) Can be used as “template” files Non-project specific Can be used to validate or limit user input

Cons: Can only control one file at a time

Create the Worksheet When creating the worksheet to be embedded users should consider some of the following suggestions:

Note that the order of the parameter data is different than that in the parameters dialogue in the part file. (Parameter Name/Value/Units/Comments)

Physically segregate the editable and calculated data into different areas of the spreadsheet or on separate tabs. Supporting calculations can also be hidden.

Highlight cells where user entry or selection is allowed. Do not insert blank rows between parameters. Inventor stops reading the Excel file when it

encounters a blank row. Once the Excel file has been linked you cannot easily move the position of the parameters.

PLAN AHEAD!

Page 4: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

4

Using Data Validation A very useful tool for Embedded and Linked Spreadsheets is Data Validation. Data Validation ensures that users can only select certain values or combinations, reducing design errors or the creation of non-standard parts. Furthermore it reduces the amount of information the user is required to enter to create the part or assembly. Finally, the creator of the part can assign meaningful or helpful input and error messages to guide the user during the part creation process. Examples of data validation might include:

Restrict users from creating parts longer than a certain length (e.g. stock material length) Force users to select a standard sized part to reduce custom manufacturing costs Present the user with a list of possible configurations and allow the spreadsheet to calculate the size

Figure 1 - Example of Completed Spreadsheet

Assigning Validation to a Cell To validate the value of a cell, highlight the cell and select Data>Validation form the main menu. A dialogue (Figure 2) will allow the user to select a form of validation and set the rules for what is allow to be entered into the selected cell.

Page 5: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

5

Types of Data Validation

Whole Number: Only allows user to enter integer values. The input is further restricted to a subset of numbers that can be defined as being greater than, less than, equal to, between, not between etc.. a set of hard coded values or can refer to other cells on the sheet allowing dynamic rule creation.

Decimal: Only allows user to enter decimal number values. The input is further restricted to a subset of numbers that can be defined as being greater than, less than, equal to, between, not between etc.. a set of hard coded values or can refer to other cells on the sheet allowing dynamic rule creation.

List: Restricts the user to choosing one of the presented list of choices. A cell range in the worksheet defines these choices.

Date: Only allows user to enter a date formatted value. The input is further restricted to a subset of dates that can be defined as being greater than, less than, equal to, between, not between etc.. a set of hard coded values or can refer to other cells on the sheet allowing dynamic rule creation.

Time: Only allows user to enter a time formatted value. The input is further restricted to a subset of times that can be defined as being greater than, less than, equal to, between, not between etc.. a set of hard coded values or can refer to other cells on the sheet allowing dynamic rule creation.

Text Length: Only allows user to enter text (including numbers) of a certain number of characters. The input is further restricted to a subset of number of characters that can be defined as being greater than, less than, equal to, between, not between etc.. a set of hard coded values or can refer to other cells on the sheet allowing dynamic rule creation.

Custom: Allows the creator to define a custom validation based on the values of other cells. For example a number entered, when added to 3 other numbers, cannot be larger than a certain value. This type of validation is very powerful.

Figure 2 - Data Validation Dialogue

The most popular form of Data Validation is the LIST validation tool. This allows the creator to restrict the possible entries to those assigned in a list. To use this form of validation simply enter the allowable choices into a set of cell (often off to the side, hidden or on the second sheet) and select this range with the data

Page 6: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

6

validation tool. A drop down list will appear in the selected cell. Only the values listed in the source range will be allowed to be selected.

Input and Error Messages On the second tab of the dialogue the creator can assign a custom input (default is none) message to be displayed when the user clicks on the validated cell. An example of an input message could be “Please select a sprocket pitch”. On the third tab the creator can assign a message that appears if the user attempts to input a value that is not allowed by the validation rules. The default message is “The value you entered is not valid” but can be customized.

VLOOKUP and HLOOKUP Functions Another very useful tool for linked and embedded spreadsheets are the VLOOKUP (vertical Lookup) and HLOOKUP (horizontal Lookup) functions. These functions allow the creator to use tabular data in their spreadsheets and then “lookup” dimensional values based on user input (often from a validated cell). An example of the use of this function might be to lookup the pitch (in inches) of a sprocket based on the roller chain series. (e.g. a #40 roller chain sprocket has a pitch of ½”) To use these functions create a range of cells with an index row or column then rows and columns of corresponding data. Below is a tabulated chart of dimensions (A-D) as a function of thread size.

Figure 3 - Tabulated Part

To find the value of dimension A for a thread size of 10-24 we would first create the table in Excel. Next select the cell where you want the result to appear. In the formula bar click on the = button and select VLOOKUP from the formula pull down.

Thread A B C D 10-24 3.25 1.5 0.25 0.5 1/4"-20 4.375 2.5 0.375 0.5 5/16"-18 4.4375 3 0.4375 0.5 3/8"-16 5 3.5 0.5 0.5 1/2"-13 5.625 3.5 0.625 0.5 5/8"-11 6.375 3.5 0.875 0.5 3/4"-10 6.875 3.5 0.875 0.5

Page 7: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

7

The VLOOKUP dialogue guides the user as how to format the function. See Figure 4 for an example dialogue. While the dialogue has context sensitive help we’ll explain a few of the entries here in detail. Clicking on the icon to the right of each text box allows you to select the cells in question to fill in the boxes.

Lookup_value: This is the value which you are looking up in the table. In our case it’s the thread size. We select the cell where the user enters the thread size. (A12)

Table_Array: This is the cell range that contains the tabulated data. Be sure to select the row that contains the lookup_value values.

Col_index_num: This is the column from which you want values returned. The first column is 1. If we want the value of A that is associated with our thread selection we’d choose 2 as it’s the second column.

Range_lookup: This option field determines if we want an exact match (FALSE) or the closest match (TRUE). This is useful if you want the user to be able to enter a certain amount of “slop”. For example if the user enters 4.35 and you have a table value for 4.2, 4.4 and 4.7, it will select the values that correspond to 4.4. In our case we want an exact match so we choose FALSE.

After entering the values click OK and the value of the cell that corresponds to the intersection of 10-24 and A should appear in the cell. Repeat this process for the other cells, making sure to change the column_index_num each time.

Figure 4 - Sample VLOOKUP Dialogue

Often the Lookup_value will be a list validated cell to ensure that the value will be found in the table. The HLOOKUP function provides similar functionality. Use HLOOKUP if your table is arranged with the “key” values in columns and the data in rows.

Embedding the Worksheet After you have created the model it’s time to embed the worksheet. Open the model file and click on the parameters button. At the bottom of the dialogue click on the Link button (a slight misnomer). In the resulting open dialogue select the Excel sheet, set the radio button to Embed and enter the cell in which the

Page 8: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

8

parameters begin. There is no need for the source Excel file to be in the Project Path and in fact can be discarded after it is embedded. The parameters will be added to the parameters dialogue as shown below. However hopefully your cells will not be yellow as shown in the figure. A yellow cell in the parameters dialogue indicates that the data is malformed in the Excel worksheet. Often it’s a problem with units or the user put the columns in the wrong order (recall the Excel sheet order is different from the parameters dialogue order). Once the data in the Excel sheet is fixed, the cells will turn back to white.

Figure 5 - Embedded Parameters

Completing the Model Once the Excel sheet has been embedded its time to assign the embedded parameters to the model dimensions. There are two ways to assign the parameters:

Edit each feature and assign the parameter name to the value of the feature or sketch dimensions via the feature or sketch dimension edit function (or via the parameters dialogue)

If you embedded the sheet before modeling, model the part using the parameter names as entries in dimension fields

Page 9: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

9

Changing and Updating the Model

Once all features have been assigned their embed values, changing the size of the model is easy. Right click on the Excel sheet in the browser and select Edit. Change the values in the sheet and click on the Save (relabeled as Update) button. Return to the Inventor model and click update (often this step is not required). The model will update based on the values entered into the Excel sheet. Excel Embedded parts are often useful as “template” parts. Place the file in your templates directory. Create a new part file based off this template. Edit the Excel sheet, update the model and then save. It is a quick and easy way to provide your users with a foolproof method for generating classes of parts.

Figure 6 - Sprockets Created from Embedded Worksheet

Excel sheets can also be embedded into assemblies to control constraint parameters. An example of this might be a robot whose joint positions are controlled by the embedded Excel table. Taking this example a step further, a combination of a data validation list and a VLOOKUP function could allow the user to place the robot in a number of named positions (e.g. home, perch, loading position etc..).

Figure 7 - Example of Excel Embedded in an Assembly

Page 10: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

10

Figure 8 - Robot Positions Based on Worksheet Selections

Linked Excel Workbooks Pros and Cons The process of linking Excel worksheets is very similar to that of embedding them. One of the major advantages of linking worksheets is the ability to control multiple part and assembly files from one master document. The powerful calculation and logic functions in Excel allow the creator to make a user interface that is both easy to use and allows the most output with the least amount of user input. Pros:

Can be used to control many files at once Can perform complex and logic calculations in the Excel spreadsheet Can be used to validate or limit user input

Cons: Project sensitive Changes to one file my conflict with another in the assembly Some versions of Inventor have problems communicating with Excel without problems

Creating the Worksheet A linked worksheet is in many ways the same as an embedded one. The same rules apply and the same suggestions should be followed as well. Using VLOOKUP and Data Validation techniques, create a well-defined user interface. In the case of this linked worksheet, we place both parameters for parts and the assembly in the file. Recall that Excel stops reading parameters when it finds a blank row.1 Equations in assembly worksheets tend to be much more complex than in part files. Be sure to familiarize yourself with the various Excel functions (IF..THEN, MIN, MAX, SUM, AVG etc..) An example of a worksheet is shown in Figure 9.

1 You can separate each part’s parameters by a space and adjust the starting cell for each file individually, however any additional parameters that need to be added will force you to change the position of other part’s parameters creating a cascading failure. Great thought needs to be given if you choose this method. An easier way is to color code the parameters by part file (see above).

Page 11: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

11

In this worksheet we have provided 3 user inputs; Product Width, Product Weight and Center-to-Center distance of the shafts. The Product Width is a list-validated pull down offering a range of choices. The weight field is an open-ended user input. Finally the Center-to-Center distance is validated so that users cannot choose values longer than 200” or shorter than 30”. To determine the width of the conveyor we use a VLOOKUP function and consult the chart at the bottom of the page. To determine the # of sprockets to be used we also use a VLOOKUP function to consult the chart. However if the weight of the product is more than 50lbs and the conveyor width is larger than 4” we add an additional sprocket. The equation below which determines the number of sprockets, shows the true power of using these linked parameters =IF(B21>4,(IF(B7>50,(VLOOKUP(B6,A29:C32,3,FALSE))+1,(VLOOKUP(B6,A29:C32,3,FALSE)))),(VLOOKUP(B6,A29:C32,3,FALSE))) Take some time to try and break down the function to see what it is doing.

Linking the Worksheet to Models The process of linking an excel worksheet is similar to that of embedding. Open the model file to which the Excel file will be linked. Open the parameters dialogue and click Link. In the open dialogue select the Excel file, select Link and enter the starting cell for the parameters. Repeat this process for each of the files in the assembly that require to be linked. Finally, link the assembly to the Excel sheet as well.

Figure 9 - Linked Assembly Worksheet

One thing to be aware of is the fact that linked Excel sheets are project specific. The Excel sheet must remain in one of the specific project paths (but not a library path) and cannot be deleted like an embedded sheet.

Page 12: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

12

Completing the Model Again, the process of completing the models in the linked workflow is similar to that of the embedded process.

Edit each feature and assign the parameter name to the value of the feature or sketch dimensions via the feature or sketch dimension edit function (or via the parameters dialogue)

If you linked the sheet before modeling, model the part using the parameter names as entries in dimension fields

Managing Linked Worksheets You access the linked worksheet in the same manner as an embedded worksheet; by expanding the browser, right clicking on the Excel icon and selecting Edit. Since the workbook must exist in the project path you can also open it directly from Windows Explorer. Once you have made your changes to the Excel sheet, click the Save (Update) button and return to Inventor. In Inventor issue a global update. Be aware that changes to some files may create error in the assembly. Be sure to fully test all possibilities before publishing your model to the rest of your users. Limit their access to knon problems by using data validation techniques. You can link multiple Excel workbooks to one model file. However given the complexity that can occur I suggest putting all parameters into one file. This makes it easier to manage and debug should there be problems. Should you choose to move the location of the Excel workbook, you must open each file and right click on the Excel icon and select change source. This allows you to redefine the position of the workbook. Design Assistant can also be used to change the location or source of the Excel workbook.

Some Examples of a Linked Excel Workbook Below are some images of a conveyor whose parts and assembly are linked to the Excel sheet shown in Figure 9. By entering only 3 values; Product Width (a list box), Product weight and Center-to-Center distance, the conveyor is developed by a series of calculations in the Excel workbook.

Page 13: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

13

Note 1 - Cutaway to Show Stiffeners

Figure 10 - Configurations of Conveyors

One note: In this example I made a mirrored derived part of one of the conveyor sides to get the opposite hand side. When you update the assembly the derived-mirrored part does not update. Clicking update once more causes the second part to update. If you make a habit of deriving derived parts, keep in mind you will have to hit update multiple times.

Derived Parameters in Part Files Pros and Cons Using derived parameters in parts is the fundamental basis of Master Sketch Modeling (a.k.a. Skeletal Modeling). While this course will not discuss this exact topic we can take some of the fundamental concepts and apply them to traditionally constrained assemblies. While derived parameter linking does not have the computational horsepower that Excel provides, there are no external document or files types to deal with as all data is contained within a native Inventor file. Pros:

Can be used to control many files at once Parameters can easily be changed to alter the assembly. No external files or connection problems with

which to deal. Cons:

Project sensitive Limited calculations and function available in the parameter dialogue < R7 cannot control assembly parameters from the master file (but there is a workaround and a light

at the end of the tunnel)

Creating the Master Parameter File (“Master”) The basic concept behind the Master Parameter File (Master) is an Inventor part file that contains only parameters, with no geometry. These parameters will be derived into all other part files and will be linked via the derived part engine. The derived part will be created based on these parameter names and values so when the Master changes, the other parts update in turn. To begin the process start a new part file and open the parameters dialogue. Create as many user parameters as required. You can always come back and add more at a later date. Be sure to check the Export box at the

Page 14: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

14

end of each row of parameters. Only exported parameters get carried over to the derived parts. You can use dummy parameters to help with complex calculations. Not checking the export box means they will not be included in the derived parts (but their calculated values will still affect the other exported parameters) You can use the limited Inventor functions (+,-,*,/,Floor(), Ceil(), PI(),Min, Max etc..) to help develop simple calculations in the parameters dialogue, however they are more difficult to use than their Excel counterparts. Once you have created all the user parameters you require you are done with the Master file. It’s that simple.

Figure 11 - User Parameters in the Master File

Derive in the Master Start a new part file. Before creating any geometry (you can derive it in after geometry has been created however) exit all sketches and click on the derive parts button. Select your Master file. You will see a dialogue like Figure 12. In this dialogue you choose what you want to derive into the new part file. All we are concerned about are the Exported parameters. Maybe sure the symbol next to Exported parameters is a yellow + and click OK. If you now examine the parameters dialogue you will see that the exported parameters now appear in this part. You can now create the geometry of the part, referring to the names of the parameters as you build it. Repeat this for each part in the assembly that requires to be linked. A tip for similar parts: If you have many similar parts in an assembly (e.g. a lot of square steel tubes), rather than deriving the Master into several different parts, make one part and then Save Copy As.. to a new name. Open the new part and adjust the dimensions or values as necessary. This maintains the link to the Master file while preventing the creator from repeating the derived workflow over and over.

Page 15: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

15

Figure 12 - Derived Part Dialogue

Creating the Assembly After all parts have been linked, create the assembly using conventional constraint techniques. If you have a simple assembly then the process is complete. However you may have an assembly that needs to refer to one of the parameters that resides in the Master file. For Inventor R6 & R7, you must use a workaround to obtain these parameters. Follow this process to obtain these parameters:

1. Create a new assembly level sketch on a part that uses the parameter of interest as one of it’s main features (e.g. length of a tube)

2. Project an edge from this part onto the new sketch 3. Place the center of an ellipse on the midpoint of this line and an endpoint of the ellipse on the line’s

endpoint. 4. Place a dimension on the major radius of the ellipse. 5. Inventor will prompt you that this must be a driven dimension. Accept the dialogue. 6. The driven dimension now appears in the parameters dialogue and can be referred to as a variable.

When the part updates, the driven dimension will also update. Keep in mind the dimension value is ½ of the length of the line you projected. See Figure 13. Due to a bug in R7, you cannot use a circle (which would be simpler).

R8 makes it even easier to use these parameters. Clicking on the Link button in the parameters menu brings up the normal File Open menu. However if you change the file filter you will notice you can now link part files. Simply select the Master file and the exported parameters will be copied into the assembly file. You can now refer to them in your assembly and they will update with the Master. Figure 14 shows some example outputs.

Page 16: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

16

Figure 13 - Workaround for Assembly Parameters

Changing the Assembly To alter the assembly, simply open the Master file and change the parameters. Save the file and then update the assembly. Sometimes a double update or rebuild all is required if you assembly is very complex.

Figure 14 - Examples of Weldment Configurations

Page 17: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

17

External Text or Excel files linked via VBA Functions in Parameters Pros and Cons While a bit more complicated than previous methods, the process of linking parameters to a text or Excel file via VBA is useful in that the master data can reside in one spot for ALL files. Multiple files can refer to this data including multiple files in the same project. Furthermore the master file (text or Excel) can be write protected or hidden so that users have NO way of changing the values within the file. This workflow is useful for making configurations of a part. Pros:

Multiple files can key off the master text or Excel file The data in the master text file can be protected and made uneditable

Cons: More complicated to create Limited tools to “guide” users on how to change the parts

Creating the Part For our example in this section we shall be using a simple rectangular solid. We create a 1” x 1” x 1” square and name the parameters Length, Width and Depth. We also create a user parameter named ConfigNumber to control what in state we want the part to exist.

Figure 15 - VBA Controlled Cube and Configurations

Page 18: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

18

Creating the Text File In this example we will link to a simple text file. Using Notepad or other text editor create a file that follows this format.

Config# Parameter, Value, Parameter2, Value2, Parameter3, Value3 Config# Parameter, Value, Parameter2, Value2, Parameter3, Value3 Config# Parameter, Value, Parameter2, Value2, Parameter3, Value3

Etc… so a sample file might look like:

1 Length,1,Width,1,Depth,1 2 Length,1,Width,2,Depth,.25 3 Length,4,Width,.75,Depth,0.375 4 Length,10,Width,2,Depth,0.125

So for Configuration #3, Length=4, Width=0.75 and Depth = 0.375 and so forth… Save this file to somewhere on a drive accessible to your machine.

Writing the Code Don’t run away yet. I’ve written it all for you. You just need to fill in some blanks. First open the Visual Basic Editor (Tools>Macros>Visual Basic Editor) and then look in the Project Window. Find your document and expand the Modules folder and then click on the Functions module. In the code window (to the right) paste in the code as shown in the Table below.

Figure 16 - Projects Window

Page 19: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

19

The areas you will need to edit are highlighted in yellow.

1. Name the Function GetLength something descriptive for this parameter. 2. In place of CurDir & "\CubeDims.txt" you can place the path to your text file. (e.g.

“C:\folders\more folders\text.txt” ). Be sure to include the quotes. 3. In place of Length you will put in the same text as you have in the row of interest in the text file. 4. Finally replace the last GetLength with the same function name you did in step 1.

Dim strOpenName As String Dim tempstring As Variant Dim datastring As String Dim arDataValues() As String 'the code above this line only needs to be entered once. Public Function GetLength(ConfigNumber As Double) As Double 'sets the name of the text file to open strOpenName = CurDir & "\CubeDims.txt" If strOpenName <> "" Then Open strOpenName For Input As #1 Do While Not EOF(1) Line Input #1, tempstring If Int(ConfigNumber) = tempstring Then Line Input #1, datastring Exit Do End If Loop Close #1 End If arDataValues = Split(datastring, ",") For I = 0 To UBound(arDataValues) If arDataValues(I) = "Length" Then GetLength = arDataValues(I + 1) Exit For End If Next I End Function

Creating the VBA-Parameter Link Now return to your Inventor model and enter the parameters dialogue. In a notepad file type the following:

VBA:GetLength(ConfigNumber) * 1 in

Then paste this into the expression box for the Length parameter. We paste it in to avoid having Inventor try to run the function before we finish typing. So let’s step back and see what’s we’ve done.

Page 20: Control Your Autodesk Inventor® Data with Linked External Parameters · 2018-07-19 · Control Your Autodesk Inventor© Data With Linked External Parameters 5 Types of Data Validation

Control Your Autodesk Inventor© Data With Linked External Parameters

20

The VBA:GetLength(ConfigNumber) * 1 in text passes the value of the ConfigNumber to the VBA function named GetLength. Within the function named GetLength we open the text file and then iterate through its lines until we find the line where the ConfigNumber matches the line we read. We take the next line and separate out the parameter names and values and pass the value of interest back to the parameter. Sounds confusing but try it, it’ll make sense soon enough. So that takes care of the Length parameter. To take care of the others, copy the code above (minus the bold DIM statements) and paste it below the current code. Make changes to the highlighted areas (remember to use a different function name). Return to the parameters dialogue and paste the following text into the Width parameter’s expression box:

VBA:GetWidth(ConfigNumber) * 1 in Repeat again for the Depth code and parameter. When you are done your parameter window should look like Figure 17. The code window is too large to paste here but will be available in the download packet.

Figure 17 - Completed Parameter Table

So when you change the value of ConfigNumber to a value between 1 and 4 you will update the model to these corresponding values. Any other value of ConfigNumber (e.g. 5) will not change the model. So, while this method is a bit more complex, it does have its advantages. Furthermore in the future releases of Inventor it is likely we will be able to access more of the API and hence control conditional suppression, colors etc. in parts via this workflow. It’s best to start practicing now.

Conclusions By embedding, linking, deriving in parameters, or using VBA, CAD managers can help to create easy to use data sets. By using tools such as data validation, VLOOKUP and HLOOKUP functions, and a properly designed user interface, CAD managers can restrict users to creating only valid parts, reducing design error and custom manufacturing processes. While each workflow has its advantages and disadvantages, one of them is sure to fit your workflow and allow your users to create more accurate parts quicker. This handout along with the model files will be available at http://www.sdotson.com shortly after AU.