Table of Contents

CadCommandContext

from OpenCAD2D import CadCommandContext

class CadCommandContext(System.Object) ยท CadCommandContext in the .NET reference

What a command's body works with while it runs: the document, the answer to its last prompt, the objects selected, and the way to make its edit. One context lives for one run of a command.

Properties and fields

ClearsSelection

.NET

@property
def ClearsSelection(self) -> bool
@ClearsSelection.setter
def ClearsSelection(self, value: bool) -> None

Gets or sets whether the document's selection is cleared when the command ends, as AutoCAD clears it after MOVE.

Command

.NET

@property
def Command(self) -> CadCommand

Gets the command.

Database

.NET

@property
def Database(self) -> DxfDatabase

Gets the drawing as it stands now; a new object after an undo, so it is read again each time rather than kept.

Document

.NET

@property
def Document(self) -> CadDocument

Gets the document.

Documents

.NET

@property
def Documents(self) -> CadDocuments

Gets the drawings open in the app: the list, the one shown, and the calls that open, make, show or close one. A command may read the list and close another drawing; opening, making and showing a drawing end the command running, so they are refused here (see CadDocuments).

Editor

.NET

@property
def Editor(self) -> CadEditor

Gets the editor of the session: the view, the selection by area, the system variables and the named views. A view call made while the command runs is part of the command's undo step.

Input

.NET

@property
def Input(self) -> CadInput

Gets the answer to the last prompt.

Progress

.NET

@property
def Progress(self) -> CadProgress

Gets the progress meter of the status bar, for long work: using (var meter = c.Progress.Start("Checking")), then CadProgressMeter.SetLimit and CadProgressMeter.MeterProgress.

Selected

.NET

@property
def Selected(self) -> System.Collections.Generic.IReadOnlyList[str]

Gets the objects CadCommandContext.SelectObjects gave, in ordinal order, those on locked layers left out.

Session

.NET

@property
def Session(self) -> CadCommandSession

Gets the session the command runs in.

Space

.NET

@property
def Space(self) -> CadSpace

Gets the space the command works in: the document's working space, model space while a viewport of the layout shown is worked through.

Methods

Apply

.NET

def Apply(
    self,
    planned: System.Collections.Generic.IReadOnlyList[CadEditRecord],
    apply: System.Action[CadEditScope],
) -> CadEditResult

Makes an edit of the command through CadDocument.ApplyEdit; all the edits of one run are one undo step. A refusal or failure is written into the history.

CloseUndoStep

.NET

def CloseUndoStep(self) -> None

Closes the command's undo step opened so far, so that its edits up to now are one step and those it makes next another, as TEXTEDIT makes one step of each text it edits.

Length

.NET

@staticmethod
def Length(value: float) -> str

Writes a length as the command line writes one: to 4 places.

OpenUndoStep

.NET

def OpenUndoStep(self) -> None

Opens the command's undo step now, so that edits made through the document's own methods (CadLayerEditor, CadGrips, CadPropertyEditor) join it rather than being steps of their own.

Remember

.NET

def Remember(self, key: str, value: float) -> None

Keeps a number for the next run of a command.

Remembered

.NET

def Remembered(self, key: str, fallback: float) -> float

Gets a number kept from a run of a command before, as the radius CIRCLE offers next.

SelectObjects

.NET

def SelectObjects(self) -> System.Collections.Generic.IEnumerable[CadPrompt]

Asks "Select objects:" until Enter, unless objects were selected before the command started, which are taken instead; the result is CadCommandContext.Selected, those on a locked layer left out with "1 was on a locked layer." The body yields what this yields: foreach (CadPrompt p in c.SelectObjects()) yield return p;.

Write

.NET

def Write(self, line: str) -> None

Writes a line into the history of the command line.