Skip to content

Option Types

The Option class provides factory methods for defining typed, persistent options that generate UI controls in tool and format plugin dialogs.

Common Parameters

All option factories accept these parameters:

ParameterTypeDescription
labelstrDisplay label (first positional argument)
defaultvariesDefault value
tooltipstrTooltip text
enabled_whencallableCallback receiving self, returning bool — greys the control out when False
namestrKeyword-only. Overrides the generated option key

Option.integer()

Spin box for integer values.

count = Option.integer("Count", default=1, min=0, max=1000)
ParameterTypeDefaultDescription
defaultint0Default value
minint0Minimum value
maxint999999Maximum value

Option.real()

Double spin box for floating-point values.

scale = Option.real("Scale Factor", default=1.0, min=0.001, max=1e6, decimals=4)
ParameterTypeDefaultDescription
defaultfloat0.0Default value
minfloat0.0Minimum value
maxfloat1e9Maximum value
decimalsint2Decimal places displayed

Option.boolean()

Checkbox for true/false values.

flatten = Option.boolean("Flatten hierarchy", default=False)
ParameterTypeDefaultDescription
defaultboolFalseDefault value

Option.string()

Single-line text field.

name = Option.string("Output name", default="output")
ParameterTypeDefaultDescription
defaultstr""Default value

Option.choice()

Dropdown selector.

mode = Option.choice("Mode", choices=["Fast", "Precise", "Custom"], default="Fast")
ParameterTypeDefaultDescription
choiceslist[str]requiredAvailable options
defaultstrfirst choiceDefault selection

Option.path()

File path picker with browse button.

output = Option.path("Output file", file_filter="CSV Files (*.csv)")
ParameterTypeDefaultDescription
defaultstr""Default path
file_filterstr"*.*"File type filter string

Option.color()

Color picker button.

fill = Option.color("Fill color", default="#FF0000")
ParameterTypeDefaultDescription
defaultstr"#000000"Default color (hex)

Option.cell_choice()

Dropdown populated with all cell names from the current drawing.

target = Option.cell_choice("Target cell")
ParameterTypeDefaultDescription
defaultstr""Default cell name

Option.table()

Editable grid with typed columns. See also Panel Assembly Tutorial.

entries = Option.table(
"My Table",
columns=[
TableColumn(key="name", label="Name", col_type="string"),
TableColumn(key="value", label="Value", col_type="real", decimals=3),
],
)
ParameterTypeDefaultDescription
columnslist[TableColumn]requiredColumn definitions
defaultlist[dict][]Default rows

The value is a list[dict] where each dict maps column keys to values.

TableColumn

PropertyTypeDescription
keystrDict key for this column
labelstrColumn header
col_typestrstring, integer, real, choice, cell_choice
defaultAnyDefault value for new rows
choiceslist[str]Options for choice columns
decimalsintDecimal places for real columns
min_valueint|floatMinimum for numeric columns
max_valueint|floatMaximum for numeric columns

Conditional Visibility

Use enabled_when to dynamically enable/disable options:

class MyTool(Tool):
mode = Option.choice("Mode", choices=["Simple", "Advanced"])
threshold = Option.real(
"Threshold",
default=0.5,
enabled_when=lambda self: self.mode == "Advanced",
)
iterations = Option.integer(
"Iterations",
default=10,
enabled_when=lambda self: self.mode == "Advanced",
)

When mode is “Simple”, the threshold and iterations fields are grayed out.

Option Keys

Each option is persisted under a string key. When an Option is used as a class attribute, LinkCAD generates that key as PyPlugin.<Class>.<attribute>. The reserved PyPlugin root keeps plugin options out of the application’s own settings namespace, and the class segment keeps two plugins that both call an option flatten apart:

class AsciiWriter(FormatWriter):
flatten = Option.boolean("Flatten hierarchy", default=False)
# persisted as "PyPlugin.AsciiWriter.flatten"

The attribute name is used as written, so the key and the Python attribute that reads it are spelled the same. Every option is also settable from the command line under that key:

linkcad --PyPlugin.AsciiWriter.flatten=1 ...

Pass the keyword-only name argument to choose the key yourself:

flatten = Option.boolean("Flatten hierarchy", default=False, name="MyFormatFlatten")

Option values are loaded onto the instance before run(), read(), or write() is called, so inside those methods self.flatten is the current value. Setting the attribute directly also works, which is what makes a plugin drivable from the script editor without opening its dialog.