# External Text Files to Control Variables/Equations in SolidWorks

External Text Files to Control Variables/Equations in SolidWorks

1. ### Step 1: Model the part

A simple prismatic part from the SolidWorks CSWA Exam will be used in this tutorial. Details of the various approaches on how to create this model will not be given here. I will link a YouTube video at the end of this tutorial to show one way I used to create this model and additional comments on linking variable dimensions to an external text file with real world applications.

A designer with experience will create models that are robust so that changes to dimensions will not create failed features or unpredictable results. Modeling experience will help you develop strategies to make your models more robust. Some basic concepts are to sketch on planes controlled from the primary planes (Front, Right, Top) and to dimension to these and the primary planes whenever possible. If you sketch on 'model surfaces' rather than planes with dimensions to part edges, those features then become dependent on the surfaces and edges of their "parents" which would cause them to fail if their "parents" are changed in such a way they no longer have the planar surface or the edges you used to control the 'child' feature.

Notice the variable dimensions labeled with letters. Try to model this part so that changes to 6 dimensions labeled with Alpha characters (A, B, C, D, E) create no feature failures or errors on rebuild when those dimensions are changed. Also, the length of he angled surface from the flat plane to the center line is one-forth of the B dimension as shown.

Material: 6061 Alloy. Density = 0.0027g/mm^3

Unit system: MMGS (millimeter, gram, second)

For the default values of the variables, let's set

A= 105 mm, B = 205 mm, C= 45 mm, D= 23 degrees, and E = 33 degrees. In our Global Variables, we will change those dimensions to the values below and compare our mass properties in each configuration. The configurations can be controlled by the external text file we link to in the Equations table.

2. ### Step 2: Change Default Dimensions Names

First, make sure the Dimension Names are displayed in the graphics area.

When dimensioning the profile sketches and the extrusion depths, change the default names to meaningful names that will help identify the correct dimensions to link to variable names in the Equations Table. Once the dimensions are liked to variables the dimension names cannot be changed unless they are unlinked from the variable names. Also, once the variables are then subsequently liked to an external text file, the dimensions names cannot be changed unless unlinked to the external text file.

So, the dimension names should now appear with the appropriate names on the sketch.

Once all the features have been added to the model, all the dimensions should also be visible. It is helpful to hide those dimensions that will not be changed in this tutorial. To do this, right-click on the dimension and select the 'hide' option on each dimension. Or, alternatively, you can right-click on the feature in the Feature Manager Tree and select Hide Dimensions. Using this option you may hide the Named Dimensions that we want to remain visible so toggle those dimensions back on and hide them using the first method by selecting the names in the graphics screen and hiding them there.

Once the all but the variable dimensions are hidden, your model should look something like this one below.

3. ### Step 3: Create the Variables in Equations

Select the Equations tool

Or, use the Equations Icon to open the Equations table and access the Global Variables.

Now, create the Global Variables one at a time and fill in the appropriate values for the 1st configuration.

4. ### Step 4: Link the dimensions to the Global Variables

Double-click the dimension to be linked to a Global Variable in the Equations table and type in an equal sign (=) so the pop-up menu shows the options as shown below.

Select Global Variables, and then pick the appropriate variable to link to the dimension.

Once you have linked the dimension, the dimension will now show it is linked with a Summation Sign in front of the dimension value with the value from the Global Variables.

Continue linking each of the dimensions to the appropriate Global Variable until each of the 6 dimensions are successfully linked.

The length of the inclined surface to the right and back of the object is dimensioned to be 1/4 of the Width as shown.

5. ### Step 5: Validate Model Robustness with Variable Changes

Each of the dimensions should now show they are linked with the Summation Sign in front of the dimensions as show below.

Try changing the values (within ranges that make sense) in the Global Variables in the Equations table and update the model to see the dimensions change. If features in the model fail or have warnings, investigate the failure and resolve the issue before proceeding.

Change the Global Variable values back to the Configuration 1 values as shown in this table:

6. ### Step 6: Link to an External Text File

Open the Equations table and Select the option at the bottom of the table: 1- 'Link to External Text File.' 2- Select, 'Create new file,' and 3- Change the default name 'equations.txt' to 'Configuration1.txt.'

Open Notepad and edit the Configuration1.txt file. Make a few changes to the variable values in Notepad and save. Now update the model and make sure the dimensions change to the variable values in the text file.

Change the values back in Notepad to the Configuration1 values and save. Again n Notepad, change the values now to the Configuration 2 values as shown in the table below. Save the text file as, 'Configuraton2.txt.'

You should have two text files in your directory with the values shown in the table.

7. ### Step 7: Link Variables to Alternate text files.

Open the Equations Table again and select the 'Edit Link' option at the end of the 'Link to external file' file name box.

Change the linked file to Configuration2.txt. Select the 'Link' option from the open dialogue box, then from the warning box, select, 'OK.'

When the Equation Table closes, your model should automatically rebuild to the new dimensions in Configuation 2.

8. ### Step 8: Compare Mass Properties

To insure we have made the correct model, let's compare mass properties of the two models.

If the origin of you model is not at the back left corner of the part, let's assign a coordinate system at that location so all the values of the center-of-gravity will be positive values.

From the Pull-down menus, Select Insert, Reference Geometry, Coordinate System.

Now pick the Origin, and the X-axis, and Y-axis to give the location and orientation of your user-defined Coordinate System as shown below.

Let's now look at the mass properties of Configuration1. You may want to change the unit settings and the decimal places using the Options at the top of the Mass Properties dialogue box. Make sure your total mass for Config1 is 2040.6 grams. If your value is not within a few tenths of a gram, let's do further investigation as to why they are different.

The Center of Mass should be:

X = 109.31 mm

Y = 16.66 mm

Z = 49.29 mm

Now, change to Configuration 2 by opening the Equations table, and changing the linked file name to the Configuration2.txt file. The model will automatically update to the new values. Under the Mass Properties, the mass of this model should be 2628.5 grams. Also check the Center of Mass values. In this model they should be:

X = 123.33 mm

Y = 19.08 mm

Z = 54.26 mm