SWITCHPART
One of several imported parts, picked by a value as SWITCH picks one: the value is looked up in a table of parts, a dictionary (by key) or a list (by position), and the part shown changes when the value (usually a variable) does. Use it for a drawing that takes one of several inserts, tabs or logos depending on a setting.
Syntax
SWITCHPART value,{key:part,key:part,…}
SWITCHPART value,{part,part,…}
SWITCHPART @id,value,{key:part,…},otherwise,layer
| Argument | Meaning |
|---|---|
| value | What picks the part: a variable (STYLE), or any expression (W>200, IF(…)). |
| {key:part,…} | A dictionary of parts: each shown when value is its key (a number, text in quotes, TRUE or FALSE, or an expression). |
| {part,…} | A list of parts: value says which, from 0. |
| part | A PART (a part of the library, or a page, by name), a VECTORIMAGE (another format) or a RASTERIMAGE (a picture), written in full. They are usually all on the same points, so whichever is shown is where the others would be. |
| otherwise | A part shown when value isn't a key of the dictionary, or a position in the list (optional). |
Keys are compared as SWITCH and dictionaries compare them: numbers by value (2 is 4/2), text exactly (a number
never equals text). A list's positions are whole numbers from 0; any other value (1.5, -1, text) isn't one. A table is
one or the other: every part with a key, or none. If value picks no part and there is no otherwise, nothing is
drawn but a dotted frame where the first part would be.
The id, layer and any settings after it are the element settings. The parts are drawn on the switch part's layer (their drawings' own layers kept where this drawing has a layer of the same name).
Examples
PARTDEF "One","LINE @1,P0,P1"
PARTDEF "Two","LINE @1,P0,P1\nLINE @2,P1,P2"
STYLE=1
P4=[600,0]
P5=[600,100]
SWITCHPART @9,STYLE,{1:PART @1,P4,P5,"One",0,2:PART @2,P4,P5,"Two",0},0
STYLE=2

With STYLE 1 the first part (one line) is drawn; setting it to 2 draws the second (two lines) instead.
PARTDEF "One","LINE @1,P0,P1"
PARTDEF "Two","LINE @1,P0,P1\nLINE @2,P1,P2"
PARTDEF "Diagonal","LINE @1,P0,P2"
STYLE=0
P4=[600,0]
P5=[600,100]
SWITCHPART @9,STYLE,{PART @1,P4,P5,"One",0,PART @2,P4,P5,"Two",0},PART @3,P4,P5,"Diagonal",0,0
STYLE=5
A list: STYLE 0 shows the first part, 1 the second, and anything else (5 here) the otherwise part, a diagonal.
Notes
- Only the part shown is drawn, selected, measured and exported, as that part would be on its own: a drawing file's part as a subroutine or block where the format has them, a picture as an image. The others are kept in the drawing, ready for when the value changes.
- Each part keeps its own scoping: a drawing file's variables with the same names as this drawing's take this drawing's values.
- Switch parts are usually placed with the Part Import Tool, the
Vector Import Tool or the Raster Image Tool, with
Switch Between Files ticked: each
value: fileline becomes an entry of the dictionary, and theDEFAULT:line the otherwise part.
See also: SWITCH, PART, VECTORIMAGE, RASTERIMAGE.