跳转到内容

Options

此内容尚不支持你的语言。

lc_plugin::options wraps LinkCAD’s persistent typed option store. Plugins register option keys at load time, then read and write values during import/export.

The option store is the Rust counterpart to linkcad.v1.env option functions and the higher-level Python Option API.

Purpose

Options are host-managed key-value settings. Dialog widgets declared with DialogSpec register options automatically when DialogSpec::register_options() is called by the registration macro. Plugins can also register and access options directly.

Registration Functions

FunctionDescription
register_int(name: &str, default: i32)Register an integer option.
register_bool(name: &str, default: bool)Register a boolean option.
register_real(name: &str, default: f64)Register a floating-point option.
register_string(name: &str, default: &str)Register a string option.

Getters

FunctionDescription
get_int(name: &str) -> i32Read an integer option.
get_bool(name: &str) -> boolRead a boolean option.
get_real(name: &str) -> f64Read a floating-point option.
get_string(name: &str) -> StringRead a string option. Returns an empty string when the host returns no value.

Setters

FunctionDescription
set_int(name: &str, value: i32)Write an integer option.
set_bool(name: &str, value: bool)Write a boolean option.
set_real(name: &str, value: f64)Write a floating-point option.
set_string(name: &str, value: &str)Write a string option.

String inputs are truncated at the first interior NUL byte instead of panicking.

Direct Option Example

use lc_plugin::options;
fn register_options() {
options::register_bool("ExampleInMerge", true);
options::register_int("ExampleInFacets", 32);
options::register_string("ExampleInUnits", "um");
}
fn read_options() -> (bool, i32, String) {
(
options::get_bool("ExampleInMerge"),
options::get_int("ExampleInFacets"),
options::get_string("ExampleInUnits"),
)
}

Dialog-Backed Options

fn import_dialog_spec() -> DialogSpec {
DialogSpec::new("Import Options")
.group("Geometry")
.bool_field("ExampleInMerge", "Merge polygons", true)
.int_field("ExampleInFacets", "Minimum facets", 4, 256, 32)
.string_field("ExampleInUnits", "Units", "um")
}

When this dialog is passed to register_format!, the macro registers its options before it registers the dialog with the host.

Naming

Use stable, format-specific option names such as OdbppInStep or ExampleOutUnits. These names are persisted by the host, so changing them changes the stored settings key.