CadToolPalettes
from OpenCAD2D import CadToolPalettes
class CadToolPalettes(System.Object) ยท CadToolPalettes in the .NET reference
The tool palettes of the window: the palettes in the order of their tabs, the one shown, and the tools cut or copied that Paste puts back. The set is kept in one JSON file beside the settings (CadToolPalettes.DefaultPath, written by CadToolPalettes.Save, read by CadToolPalettes.Load); one palette, or all of them, can be written to a file of their own (CadToolPalettes.Export) and read from one (CadToolPalettes.Import) in the same format, which the guide of the presenter describes member by member. A set with no file starts as CadToolPalettes.CreateStarter makes it.
The JSON of the tool palettes. A file is an object with format (OpenCAD2D.ToolPalettes), version (1), active (the place of the palette shown, from 0) and palettes, a list of objects with name, view (icons, iconsAndText or list), iconSize (16 to 96) and tools. A tool has kind (block, hatch, command, text or separator), name and description, and by kind: command command and icon; block file, block, scale, angle (degrees), promptForScale, promptForRotation and explode; hatch hatchType (pattern, userDefined, solid or gradient), pattern, angle, scale, spacing, gradient and associative; and for the three that draw, layer, color, linetype and lineWeight where set. A member missing keeps its default; a tool of another kind is skipped.
Constructors
__init__
def __init__(self) -> None
Properties and fields
Format
Format: ClassVar[str]
The format a file of tool palettes has.
NewPaletteName
NewPaletteName: ClassVar[str]
The name of the palette a new one is given where it is not named.
Version
Version: ClassVar[int]
The version this writes; a file of a later version is read as far as it is understood.
Active
@property
def Active(self) -> CadToolPalette | None
Gets the palette shown; null where the set has none.
ActiveIndex
@property
def ActiveIndex(self) -> int
@ActiveIndex.setter
def ActiveIndex(self, value: int) -> None
Gets or sets the place in CadToolPalettes.Palettes of the palette shown; kept inside the list, 0 with none.
Clipboard
@property
def Clipboard(self) -> System.Collections.Generic.IReadOnlyList[CadTool]
Gets the tools cut or copied, which CadToolPalettes.Paste puts into a palette.
DefaultPath
DefaultPath: ClassVar[str]
Gets the file the palettes are kept in: %AppData%\OpenCAD2D\ToolPalettes.json, beside the settings.
IsModified
@property
def IsModified(self) -> bool
Gets whether the set changed since it was made, read or last saved.
Palettes
@property
def Palettes(self) -> System.Collections.Generic.IReadOnlyList[CadToolPalette]
Gets the palettes, in the order of their tabs.
Methods
Add
def Add(self, palette: CadToolPalette) -> CadToolPalette
Puts a palette after the last, its name made unique, and shows it.
def Add(self, name: str) -> CadToolPalette
Makes an empty palette after the last, its name made unique, and shows it.
AddBlocks
def AddBlocks(
self,
name: str,
file: str,
blockNames: System.Collections.Generic.IEnumerable[str],
) -> CadToolPalette
Makes a palette of a drawing's blocks: one palette named for the drawing, a block tool for each name, taking the drawing as its source, as DesignCenter's Create Tool Palette does.
Copy
def Copy(self, tools: System.Collections.Generic.IEnumerable[CadTool]) -> None
Puts copies of tools on the clipboard, as Copy of a tool's menu does.
CreateStarter
@staticmethod
def CreateStarter() -> CadToolPalettes
Makes the set a window starts with where it has no file: Draw and Modify of command tools (LINE, PLINE, CIRCLE ... MOVE, COPY, TRIM ...), Annotation (text, dimensions, leaders, tables), Hatches (the ANSI patterns the presenter has, solid and gradient fills and some materials), Architectural Hatches (the AR- patterns, drawn at their size in millimetres) and ISO Hatches (ISO02W100 to ISO15W100). All are the presenter's own: its patterns and its icons.
Cut
def Cut(self, palette: CadToolPalette, tools: System.Collections.Generic.IEnumerable[CadTool]) -> None
Puts the tools on the clipboard and takes them out of the palette, as Cut does.
Export
@staticmethod
def Export(path: str, palettes: System.Collections.Generic.IEnumerable[CadToolPalette]) -> None
Writes palettes to a file of their own, in the format of the set, for CadToolPalettes.Import to read on another machine.
Import
def Import(self, path: str) -> System.Collections.Generic.IReadOnlyList[CadToolPalette]
Reads a file CadToolPalettes.Export (or CadToolPalettes.Save) wrote and adds its palettes after the last, their names made unique.
Load
@staticmethod
def Load(path: str) -> CadToolPalettes
Reads the set from its file, never throwing: no file gives CadToolPalettes.CreateStarter; a file that does not read gives it too, said in the log once.
Move
def Move(self, palette: CadToolPalette, index: int) -> bool
Moves a palette to another place among the tabs; the palette shown stays the one shown.
Paste
def Paste(self, palette: CadToolPalette, index: int) -> System.Collections.Generic.IReadOnlyList[CadTool]
Puts copies of the tools on the clipboard into a palette, at a place of its list; the clipboard stays full, so they can be pasted again.
Remove
def Remove(self, palette: CadToolPalette) -> bool
Takes a palette out; the palette shown stays the one shown where it is another, else the one next to it is.
Rename
def Rename(self, palette: CadToolPalette, name: str) -> bool
Renames a palette; a name another palette has gets (2) and on after it.
Save
def Save(self, path: str) -> None
Writes the set to a JSON file, the folder made where it is missing, as CadToolPalettes.ToJson gives it; the set is no longer modified.
ToJson
def ToJson(self) -> str
Gives the set as the JSON text CadToolPalettes.Save writes: two spaces of indent and LF line ends.
Touch
def Touch(self) -> None
Tells the set it changed, as the window does after it changes a tool or a palette in place.
TryParse
@staticmethod
def TryParse(text: str) -> tuple[bool, CadToolPalettes, str]
Reads a set from JSON text, as CadToolPalettes.ToJson wrote it; a value that is not valid falls back to its default with a Warn naming it.
UniqueName
def UniqueName(self, wanted: str, except_: CadToolPalette | None = ..., /) -> str
Gives a palette name that no palette of the set has, letters of either case the same: the name wanted, else with (2), (3) and on after it.