Autocad Document Object in Visual Studio

Moving up the object model tree, AcadApplication has a property Documents which returns a collection of the open Documents in Autocad. Clicking Application in the clickable Object Model, in the ActiveX Reference Guide, then Documents, leads us to the Documents property. There is some sample code, but no list of properties and methods, which is confusing if we are looking for the Documents object. Sometimes the Property returns an Object with the same name and sometimes the name is different. The property of AcadApplication called Documents returns an AcadDocuments object but you look it up as Documents. Go back to the object model and directly click on Documents, or navigate the tree view in the Objects section to Documents.

clickable object model

The Documents (plural) collection has the minimum number of methods and properties, it is almost the same list as the plain VBA Collection object.
DOCS.ADD starts a new drawing
DOCS.ITEM switches between dwgs already open.
DOCS.OPEN opens an existing drawing.
DOCS.COUNT returns number of open drawings.

Clicking on the ADD Method in the Documents Collection bumps you to the generic ADD page under Methods and you have to find the text that applies to the DOCS object.

ADD takes a name parameter that is the template file to use for a new drawing. if no path is used, it looks in the template folder. you can use either a DWT or a DWG file. if the file is not in the template folder you have to give a complete path.

OPEN is a method in both Documents and Document. It works about the same in each, but Documents has a ReadOnly option that Document does not have.

CLOSE also is a method in both DOCS and DOC. in DOCS it will close all. It has a flag to save changes.

ITEM finds open drawings by either index number or name. The name is the name on the drawing tab plus the extension.

Everything you need to open, create and save drawings is under DOCS or DOC.

the DOCUMENT (single) object is the gateway to all the autocad drawing objects. It has many more properties and methods, including SAVE for previously saved files and SAVEAS for new drawings. It also has a property SAVED to indicate unsaved changes.

Every object in autocad, both the drawing entities and the drawing properties, inherit a prototype object called AcadObject. The actual drawing entities further inherit an object called AcadEntity. In the Objects section of the ActiveX Reference Guide you can find these two prototype objects and their lists of methods and properties under IAcadObject and IAcadEntity. AcadObject has a brief list of methods. AcadEntity has an extensive list of properties and methods. There is also a list of the containers or collection names where these objects are kept – ModelSpace, PaperSpace, Block, SelectionSet and Group. Its the ADDxxx Methods of these primary collection objects that create the drawing. Click on ModelSpace in the object model to see them.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.