Table of Contents

Class CadDocuments

Namespace
OpenCAD2D
Assembly
OpenCAD2D.Core.dll

The drawings open in the app, as AutoCAD's DocumentManager holds the documents of a session: listed, one made active, one opened, a new one made from the template, one closed with or without its changes saved. A plugin reaches it as Documents or Documents. Every call does what the user's action or a Remote call does, through the window's own code: Open(string) is File > Open, a drawing opened already is shown, not read twice; Add(string) is QNEW; Active set is a click on the drawing's row of the DRAWINGS list; the close calls are the x of a row once the question is answered.

public sealed class CadDocuments : IReadOnlyList<CadDocument>, IReadOnlyCollection<CadDocument>, IEnumerable<CadDocument>, IEnumerable
Inheritance
CadDocuments
Implements
Inherited Members

Remarks

The drawings are listed by file name, as Remote lists them, a drawing with no file by its name (Drawing1.dwg). Call it on the window's thread, as every callback of a plugin is run. A callback's Document is the drawing shown when it was made, so it is read again after a call that shows another drawing.

Where no window runs the plugin (a test, a plugin's own test, the Remote test server) HasWindow is false: the list is the one drawing of the session and it is the active one, and the calls that open, make, show or close a drawing throw InvalidOperationException and say so, as the window holds the drawings and a session alone does not.

Showing another drawing ends the command running in the drawing shown, as it does when the user clicks another row. A call that would do so while a command runs there is refused instead, so that a plugin's command is not ended under its own body: Open(string), Add(string) and setting Active belong to a button's, a menu's or a DRAWINGS row's callback, where no command runs. A command may read the list and close another drawing.

Properties

Active

Gets or sets the drawing the user works in, null where none is open: AutoCAD's MdiActiveDocument. Setting it shows another drawing open, as clicking its row of the DRAWINGS list does; the drawing already shown is left as it is.

Count

Gets the number of drawings open: 2 for a window with A-101.dwg and B-202.dwg open.

HasWindow

Gets whether the app's window holds the drawings: false in a test and in the Remote test server, where the list is the session's own drawing and the calls that change what is open say there is no window.

this[int]

Gets a drawing open by its place in the list, which is ordered by file name.

Methods

Add(string)

Starts a new drawing and shows it, as QNEW does: from the template, named Drawing1.dwg and then on, with no file of its own until it is saved.

Close(CadDocument)

Closes a drawing that has no changes unsaved, as the x of its row does: it leaves the list, and the next drawing is shown, or the start screen where it was the last. Nothing is asked and nothing is saved.

CloseAndDiscard(CadDocument)

Closes a drawing and throws away its changes not saved, as the x of its row does once the question is answered Don't save.

CloseAndSave(CadDocument)

Saves a drawing to its file, as Ctrl+S does, then closes it. A drawing that cannot be closed is not saved.

GetEnumerator()

Gets an enumerator over the drawings open, in the order of the list; the list does not change under it.

Open(string)

Opens a DWG or DXF file and shows it, or shows it where it is open already, as File > Open does with the file read at once. Each extension is told of the drawing and the line "Opened plan.dxf: 12 entities, 3 layers." goes to the command line.