Variable fragments can be used for automatically changing a nomenclature of fragments inserted into an assembly depending on some conditions. A variable fragment is when you use a textual variable as a name of a fragment.
In the our drill jig example, if the length of the workpiece is at least three times higher than the holes spacing, two holes are drilled, otherwise - one. The number of holes to be drilled affects the design of the jig:
Additionally, different types of drill bushings can be used.
You can make a single assembly drawing, which will automatically switch between different design options. In our case, the design with two holes require three additional fragments for the second hole: liner bushing, drill bushing and locking screw. When inserting these fragments ($drill2, $liner, $screw) and the drill bushing for the first hole ($drill1), we used variables instead of constant fragment names:
In order to insert a fragment this way, first type a name of a variable in curvy braces into the fragment file input box of the command's parameters window. Value of the variable should contain a path to fragment file. Extension is not required, as the system adds the standard T-FLEX CAD document extension (.grb) automatically. Inputting a name of a non-existent variable or a variable containing path to non-existent file yields an error. In our example fragment files are located in the same folder, as the assembly file, so relative path contains file name only. Upon inputting a variable name, press in drawing window. The specified fragment will be loaded and you will need to define its position in assembly drawing. Further work with the fragment is performed in usual way.
Expressions of variable fragments in the drill jig assembly are defined as follows:
$drill1 = switch($type,"renewable","Bushing GOST 18431-73","quick-renewable","Bushing GOST 18432-73")
$drill2 = L<=3*l?"":switch($type,"renewable","Bushing GOST 18431-73","quick-renewable","Bushing GOST 18432-73")
$liner = L<=3*l?"":"Bushing GOST 18433-73"
$screw = L<=3*l?"":"Screw GOST 9052-69"
The L variable defines the length of the workpiece, the l variable defines the holes spacing. Thus, if the length of the workpiece is at least three times higher than the spacing, values of variable fragments contain names of required additional parts, and such parts are being included into the assembly; otherwise values are empty and fragments are not included. The type of the drill bushing is switched by the switch() function depending on the user-selected value of the $type external variable of the assembly.
When variables are used for switching fragments, such fragments should have the same set of fixing elements, in order to avoid incorrect positioning. If you link variables of fragments with variables of assembly, then names of variables in both fragments should match. The semantic load of variables should also be the same (if in one of the variable fragments the variable d is responsible for the outer diameter, then in the second the same variable should be responsible for a similar parameter). If you need to use nodes from a variable fragment, then in the second fragment you must create the same number of nodes with the same names. From all of the above, we can conclude that despite the convenience of using variable fragments, you should work with them very carefully.
Alternatively, the same result could be achieved using variable visibility levels. Both approaches affect not only the display of elements in drawing, but also their inclusion into product composition, because the Don't include invisible objects checkbox is enabled in product composition parameters by default.