Table of Contents

CadApplication

from OpenCAD2D.Remote import CadApplication

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

A running OpenCAD2D, driven from another program the way a Tekla Open API program drives a running Tekla Structures: new CadApplication() connects, CadApplication.Documents lists the drawings it has open and each CadRemoteDocument reads and edits one of them.

Constructors

__init__

.NET

def __init__(self) -> None

Connects to the app the user activated last.

def __init__(self, app: CadRunningApp) -> None

Connects to one of the apps CadApplication.GetRunning listed.

def __init__(self, pipe: str, token: str) -> None

Connects to the private channel an app gives the tools it starts, by the name of its pipe and with the token it gave that tool: the channel is open whether or not "Allow other programs to connect" is on, takes no other client, and is never listed in CadApplication.GetRunning. A tool joins the run of its command with CadApplication.JoinRun.

Properties and fields

ActiveDocument

.NET

@property
def ActiveDocument(self) -> CadRemoteDocument | None

Gets the drawing the user works in, or null when the app has none open.

Documents

.NET

@property
def Documents(self) -> CadRemoteDocuments

Gets the drawings the app has open.

Running

.NET

@property
def Running(self) -> CadRunningApp

Gets the app this one is connected to.

Methods

Dispose

.NET

def Dispose(self) -> None

Closes the connection; the app keeps running and its drawings open. A call on this object or on a drawing of it after that raises ObjectDisposedException and opens no new pipe (a connection lost by the app is opened again; one closed here is not): make a new CadApplication. Calling it again does nothing.

ForDocument

.NET

@staticmethod
def ForDocument(path: str) -> CadApplication

Connects to the app that has a file open.

GetErrors

.NET

def GetErrors(self, count: int = ...) -> CadRemoteErrors

Gets what went wrong in the app lately: the entries of its crash log (the exceptions nobody caught, with the command that ran) and the requests it could not answer for a fault of its own. Nothing is changed.

GetRunning

.NET

@staticmethod
def GetRunning() -> System.Collections.Generic.IReadOnlyList[CadRunningApp]

Lists the apps that are running, the one activated last first: each with its process id, its window's title and the drawings it has open. An app that has gone leaves no trace; an app busy with a long command is listed with no drawings.

GetScreenshot

.NET

def GetScreenshot(self, maxSide: int = ...) -> CadRemoteScreenshot

Gets the picture of the drawing canvas of the window as it last drew it, nothing shown or changed: the picture --screenshot --canvas writes, so that what the user sees can be compared with a render of the same drawing.

GetToolSetting

.NET

def GetToolSetting(self, name: str) -> Any

Reads a setting the tool declares in its plugin.json, as the user last set it in Load/Unload Applications, or its default. Only on the channel of the tools, with the token of the tool; the app answers at once, whatever its window is doing, in a run or out of one.

JoinRun

.NET

def JoinRun(self, run: int) -> CadRemoteRun

Joins the run of a command the app started for this tool: every request made on this connection from now on is part of that run, so that the changes CadRemoteDocument.CommitChanges makes are in the one undo step of the command, and Esc in the app takes them back. The run is left by CadRemoteRun.End or CadRemoteRun.Fail.

New

.NET

def New(self, template: str | None = ...) -> CadRemoteDocument

Starts a new drawing and shows it.

Open

.NET

def Open(self, path: str) -> CadRemoteDocument

Opens a drawing from a file and shows it, or, where the app has the file open already, returns that drawing and shows it.

SetToolSetting

.NET

def SetToolSetting(self, name: str, value: object) -> None

Sets a setting the tool declares in its plugin.json. The app checks the value as it checks one typed in the settings window, keeps it in its settings file and shows it there; the next CadApplication.GetToolSetting gives it. Only on the channel of the tools, with the token of the tool.

Operators and Python protocols

__enter__

def __enter__(self) -> Self

__exit__

def __exit__(self, *args: object) -> None