AutoCAD VBA

AutoCAD Application Object (The AutoCAD Object Model) (AutoCAD VBA)

The AutoCAD Object Model defines the hierarchical structure for all objects that AutoCAD exposes to VBA. The AutoCAD Application object sits at the top and represents the entire AutoCAD application; at the next level down you’ll find the AutoCAD Documents collection and the Document object, which include the drawing objects. Also at this level is […]

AutoCAD Document Objects (The AutoCAD Object Model) (AutoCAD VBA)

A Document object represents an AutoCAD drawing and is positioned at the level immediately below the Application object in the object model hierarchy (see Figure 5.1). Object Caption UserForm1 Find Name of Drawing Labell Enter drawing number Label2 The drawing’s name is CommandButtonl Exit 4. In the Properties window for CommandButtonl, enter x for the […]

Communicating with Message Boxes (The AutoCAD Object Model) (AutoCAD VBA)

Message boxes are a special kind of dialog box that pop up while a Windows application runs, to provide brief messages to the user. The information is often an error message about something that has gone wrong, or a warning to let you know that you’re trying to exit from an application without saving your […]

Graphical Object Spaces (The AutoCAD Object Model) (AutoCAD VBA)

All graphical objects belong to either the ModelSpace collection or the PaperSpace collection. These collections, in turn, belong to a Document object, which in turn belongs to a Documents collection. This arrangement is demonstrated in Figure 5.9. In addition to the ModelSpace and PaperSpace collections, there is also a Blocks collection. Each Block object in […]

Preferences Object (The AutoCAD Object Model) (AutoCAD VBA)

The Preferences object (Figure 5.11), contains all the settings from the pages of the AutoCAD Options dialog box (Figure 5.12). The Preferences object contains nine properties that return objects, each representing the settings for the nine pages (tabs) in the Options dialog box. I’ve ordered the objects in Figure 5.11 to match the order of […]

Sending Text to the AutoCAD Command Line (The AutoCAD Object Model) (AutoCAD VBA)

Text strings can be sent from VBA code directly to the AutoCAD command line using the Prompt method of the Utility object (which you’ll find in the object model at the end of the column of Document objects, just above the MenuBar collection). The Utility object enables your application to interact with the user via […]

VB’s String-Handling Functions (The AutoCAD Object Model) (AutoCAD VBA)

Visual Basic provides several functions dedicated solely to handling strings: Len,UCase, LCase, Left, Right, Mid, and Trim, to name just a few. Let’s briefly define the role of some of the commonly used functions. Len Function The Len function returns a Long type containing the number of characters in the string passed to it as […]

Drawing a Line (Macro-izing Line Drawing) (AutoCAD VBA)

This topic covers all you need to know about drawing lines in the AutoCAD window from VBA macros. You can draw continuous lines, dashed lines, or any other linetypes available in AutoCAD. You’ll see how to draw your lines highlighted and colored, and even how to draw parallel lines—all from code. You’ll also learn how […]

Setting Linetypes (Macro-izing Line Drawing) (AutoCAD VBA) Part 1

AutoCAD has a Linetypes collection that contains all the Linetype objects associated with the active drawing ThisDrawing. You can load as many Linetype objects as you like from the linetype library files. These files all have an extension .lin and are loaded by name into Linetype objects that become members of the Linetypes collection for […]

Setting Linetypes (Macro-izing Line Drawing) (AutoCAD VBA) Part 2

Exercise 6.1: Line Input Application In the next series of steps, you’ll code the Cancel command button and the UserForm’s Initialize event procedure. 1.    Enter Unload Me into cmdCancel’s Click event procedure. This allows users to cancel their request to select a new linetype. 2.    Enter the code shown in Listing 6.4 into the UserForm’s […]