Class CadApplication
A running OpenCAD2D, driven from another program the way a Tekla Open API program drives a running Tekla
Structures: new CadApplication() connects, Documents lists the drawings it has open and each
CadRemoteDocument reads and edits one of them.
public sealed class CadApplication : IDisposable
- Inheritance
-
CadApplication
- Implements
- Inherited Members
Examples
using (var app = new CadApplication())
{
CadRemoteDocument drawing = app.ActiveDocument;
drawing.Insert(new DxfLine(new GeoPoint3(0, 0, 0), new GeoPoint3(1000, 0, 0)) { Layer = "Steel" });
drawing.CommitChanges();
drawing.SendCommand("ZOOM E ");
}
Remarks
The program talks to the app over a named pipe that only the Windows user who runs the app can open, and the
entities travel as DXF text, so what is read and written are the library's own DxfLine, DxfMText,
DxfDimension and the rest. Nothing else is installed on the app's side: it is on by default in the app.
One request is run at a time in an app. A second program that asks while the first is being served waits for it.
Constructors
- CadApplication()
Connects to the app the user activated last.
- CadApplication(CadRunningApp)
Connects to one of the apps GetRunning() listed.
- CadApplication(string, string)
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 GetRunning(). A tool joins the run of its command with JoinRun(int).
Properties
- ActiveDocument
Gets the drawing the user works in, or null when the app has none open.
- Documents
Gets the drawings the app has open.
- Running
Gets the app this one is connected to.
Methods
- Dispose()
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(string)
Connects to the app that has a file open.
- GetErrors(int)
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()
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(int)
Gets the picture of the drawing canvas of the window as it last drew it, nothing shown or changed: the picture
--screenshot --canvaswrites, so that what the user sees can be compared with a render of the same drawing.
- GetToolSetting(string)
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(int)
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 CommitChanges() makes are in the one undo step of the command, and Esc in the app takes them back. The run is left by End() or Fail(string).
- New(string)
Starts a new drawing and shows it.
- Open(string)
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(string, object)
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 GetToolSetting(string) gives it. Only on the channel of the tools, with the token of the tool.