Setting Margins

Set the margins for your document by setting the LeftMargin, RightMargin, TopMargin, or BottomMargin property of the PageSetup object for the document, as shown in the following example oDocument.PageSetup.LeftMargin InchesToPoints(0.5) oDocument.PageSetup.RightMargin InchesToPoints(0.5) oDocument.PageSetup.TopMargin InchesToPoints(0.5) oDocument.PageSetup.BottomMargin InchesToPoints(0.5) Note The value supplied to the XXXMargin properties must be in points. If you want to supply the values in...

AcadPViewport Object

The AcadPViewport object represents rectangular objects created in paper space that display views. The functionality of this object is slightly different from what is used in the AutoCAD user interface. In ActiveX Automation, the ActiveSpace property (of the Document object) is used to control the TILEMODE system variable. Also, the MSpace property (also of the Document object) is the equivalent of both AutoCAD's MSPACE and PSPACE commands. In addition, the ActiveX Automation user is required...

Input Methods and Dialogs

All the AutoCAD input methods require that the user interact with the AutoCAD drawing or command window. To use these methods from a VBA UserForm, either hide the form before you call the input methods or set the UserForm to modeless operation. If you don't, an error will occur. This is because modal forms maintain the application focus while they're visible. As long as a modal VBA form is visible, there's no way for the user to get to the AutoCAD drawing or command window. UserForms can be...

Acad Toolbar Object Properties

As well as the common Application property and the Count property, the AcadToolbar object supports the following properties. Gets whether and where the toolbar is docked. This property's value is read-only. For a list of possible values for the AcToolbarDockStatus enumerated type, see Appendix B. Gets or sets the number of rows if the toolbar is floating. Gets the height of the toolbar. This property's value is read-only. Gets or sets the toolbar's help string. Specifies whether the toolbar...

Editing with Methods

AutoCAD VBA editing methods edit differently from properties. Methods generally change an entity's shape, size, and position or create a new entity based on the original. Properties, on the other hand, tend to change the appearance of the object boundary lines, which represent the objects on the screen or on the plotter. Unlike Visual LISP VBA provides no equivalent functions for (vlax-method-applicable-p) for making sure an object exposes a specific method. For this reason, for each object...

Event Driven vs Procedural Programming

When a traditional procedural application runs, it follows a predetermined path that controls the portions and sequence of code executed. It starts with the first line of code and progresses from the top down, calling each procedure when needed, until reaching the end of the code. This predetermined path is the major difference between procedural and event-driven applications. Event-driven applications do not have a predetermined destiny. Different sections of code are executed based upon the...

Acad MenuGroup Object Properties

As well as the common Application property, the AcadMenuGroup object supports the following properties. Gets the name of the file in which the menu group is located. This property's value is read-only. Gets the AcadPopupMenus collection for the menu group. Gets the name of the menu group. The name is limited to 32 characters and can't contain spaces or punctuation marks. This property's value is read-only. Gets the parent of the AcadMenuGroup object. This property's value is read-only. Gets the...

Overview of AutoCad Vba Commands

AutoCAD provides a number of commands to access the VBA editor and execute VBA code. Table 1-2 summarizes the commands that you can enter at the AutoCAD command prompt. VBALOAD Loads a VBA (.dvb) project file into AutoCAD memory. If you are going to edit your project, you may want to click the Visual Basic Editor option. This puts you inside the VBA editor for immediate editing. VBAIDE Opens the VBAIDE. If you have loaded a project, this opens the VBA editor so you VBAUNLOAD Unloads the current...

Adding and Removing Items

You can add individual entities to and remove individual entities from a group by using the AppendItem and RemoveItem methods (see Table 12-11 for parameter details). These methods take an array of entities as a parameter. Both methods raise exceptions if they're unable to append or remove all the entities in the array. So if you try to append three items and one of them is already a member of the group, an error is raised and none of the items will be appended. Table 12-11. The AppendItem and...

Name Returns Description

GetWindowToPlot Gets the coordinates that define the portion of the layout to plot, the units of which depend on the values of the PaperUnits property. The coordinates of the window are taken from the origin. For these coordinates to be used for the plot, the PlotType property must be set to acWindows. Parameters LowerLeft As Variant and UpperRight As Variant. (Both parameters are two-element arrays of Doubles.) RefreshPlotDeviceInfo Updates the plot, canonical media, and plot-style table...

Using External References

External references, or Xrefs, are blocks that are not permanently loaded into the current drawing file. Instead, Xrefs refer to an external drawing file for their geometry (which is how they get their name). External references share many properties and methods with simple blocks, and for many purposes you can treat them as simple blocks. But sometimes you might also need to use external references' special capabilities. This section explains the following Xref methods

Name Data Type Description

LowerLeftCorner Variant A two-element array of doubles specifying in paper units the X and Y values, measured from the origin, for the lower-left corner of the window to be plotted UpperRightCorner Variant A two-element array of doubles specifying in paper units the X and Y values, measured from the origin, for the upper-right corner of the window to be plotted The following example illustrates how to implement this method by retrieving a window to plot from the user and then plotting that part...

List Box

The ListBox control, shown in Figure 3-17, allows a selection from a standard group of possible responses. The difference between the ListBox control and the ComboBox control is the ListBox control displays more than a single choice at a time in a list format. Also, you can't type values into a ListBox control. The following example illustrates how to populate a ListBox control and then respond to the Click event Private Sub UserForm_Activate() With ListBox1 .AddItem Item 1 .AddItem Item 2...

Note When a paper space layout becomes active it is renamed Paperspace

Use the IsLayout and IsXRef properties to identify the block definition type. If both of these properties are False, then the Block object is a simple block. Users usually create simple block definitions using the Block Definition dialog box, as shown in Figure 13-1. Use the BLOCK command to open it. Figure 13-1. Creating simple block definitions with the Block Definition dialog box Figure 13-1. Creating simple block definitions with the Block Definition dialog box All of the GUI's...

The Options Dialog

The Options dialog box, shown in Figure 1-11, lets you customize the IDE's look and feel, including syntax color scheme, source code font, and tab spacing. To open the Options dialog box, choose Tools > Options. This section covers the most commonly used options. For most developers, the default settings are fine. However, you should consider changing two settings on the Editor tab Auto Syntax Check and Require Variable Declaration. When the Auto Syntax Check option is checked, syntax errors...

AcColor

The following constants can be values for these properties AutoSnapMarkerColor property of the PreferencesDrafting object The Color property of all Drawing Objects, Group, Layer, and LabelTemplate objects The DimensionLineColor property of the Dim3PointAngular, DimAligned, DimAngular, DimArcLength, DimDiametric, DimRadial, DimRadialLarge, DimRotated, Leader, and Tolerance objects The ExtensionLineColor property of the Dim3PointAngular, DimAligned, DimAngular, DimArcLength, DimOrdinate, and...

AcCell Type

The following constants are possible return values for the GetCellType method of an AcadTable object. Also, they can be values for the CellType property or the SetCellType method of an AcadTable object. AcColor (and the ColorIndex property of the AcCmColor pbject) The following constants can be values for these properties The AutoSnapMarkerColor property of the AcadPreferencesDrafting object The Color property of the AcadEntity object (and all derived objects) and the AcadGroup and AcadLayer...

Offsetting Objects

The Offset method creates a new object with boundaries offset a specified distance from an existing object's boundaries. You can apply this method to the Arc, Circle, Ellipse, Line, LightweightPolyline, Polyline, Spline, and Xline objects. This method returns an array of the newly created object(s). Even though this array frequently contains only one object of the same type as the object from which it is offset, this is not always this case, as seen in the example below. varObjectArray...

Acad Viewports Collection

The AcadViewports collection contains all the viewports in the drawing. Although this collection inherits a Delete method, you can't actually delete this collection. If you need to delete a specific viewport, use the DeleteConfiguration method or the Delete method of the AcadViewport object. The number of viewports you can have active at one time is controlled by the MAXACTVP system variable. However, there can be only one instance of the AcadViewports collection, which is predefined for each...

Description

In addition to the properties inherited from the AcadEntity object and the common Application property, the AcadBlock object supports the following properties. Gets the number of items in the block. This property is readonly. Determines whether the block is a layout block. This property's value is read-only. If the values for IsLayout and IsXref are both False, then the block is a simple block. Determines whether the block is an Xref block. This property's value is read-only. Gets the plot...

AcadUCSs Collection Methods

The AcadUCSs collection inherits all the methods of the AcadObject object. It also supports the following methods. Creates a member object and adds it to the collection. Parameters Origin As Variant,XAxisPoint As Variant, YAxisPoint As Variant,and Name As String. The Origin parameter specifies where the UCS is to be added. The XAxisPoint parameter specifies a point on the positive X-axis of the UCS. The YAxisPoint parameter specifies a point on the positive Y-axis of the UCS. (The Z-axis...

AcDim HorizontalJustification

The following constants can be values for the HorizontalTextPosition property of the dimension objects that support it (all except AcadDimOrdinate). The text is centered along the dimension line between the extension lines. The text is next to the first extension line. The text is next to the second extension line. The text is above and aligned with the first extension line. The text is above and aligned with the second extension line.

The Object and Procedure Boxes

The Object box (the left half of Figure 1-7) lists all the objects and controls in your project. The Procedure box (the right half of Figure 1-7) lists all the procedures and events implemented in your application. When you select an object from the Object box, the procedures associated with that object appear in the Procedure box. Figure 1-8 shows that after you choose a procedure, the IDE adds its basic framework to your code window, where you write your source code. When a procedure or event...

Groups

AutoCAD allows you to have a more permanent form of selection set called a group. Just like SelectionSet objects, Group objects associate an arbitrary set of entities into a collection that you can use all at once in many operations. You can associate entities with any number of groups, and you can have any number of entities in a single group. By default, when an entity that belongs to a group is selected, all the other members of the group are automatically selected as well. The behavior is...

Acad PopupMenu Object

The AcadPopupMenu object represents an AutoCAD cascading menu of which there are two types pull-down menus, which are accessed from the AutoCAD menu bar, and shortcut menus, which are accessed by pressing Shift and right-clicking. A pop-up menu is a collection of menu items that includes AcadPopMenuItems, separators, and submenus, which can be added to the collection using the AddMenuItem, AddSeparator, and AddSubmenu methods. To create a new pull-down menu, use the Add method to add a new...

The Num Customlnfo Method

To iterate through all the custom property fields set in a drawing you will need to know how many fields there are in the drawing. The NumCustomInfo method returns that value. The method has no parameters, but has the following syntax The number of custom property fields defined in this drawing The following example illustrates using the NumCustomInfo method and the GetCustomByIndex method (discussed next) to iterate through each custom property field defined in the drawing Public Sub...

Connecting to a Microsoft Access Database

Most AutoCAD developers use Microsoft Access to create the database structure file, and then they use the Microsoft ActiveX Data Objects (ADO) library through VBA to access the .mdb file created by Access. You can use the same approach (and quite often the same code) to work with other data sources, such as Microsoft SQL Server, Oracle, DB2, and even Microsoft Exchange. This section details the steps necessary to connect to and access the data contained in a database file in a Microsoft Access...

Do Until Loop and Do Loop Until

There are two other loop structures Do Until Loop and Do Loop Until. These loops run while the condition is False (zero) rather than True (nonzero). Do Until Loop has the following syntax Do Loop Until has the following syntax Do < statements> Loop Until < condition> This example compares Do While Loop to Do Until Loop, iterating an ADO database recordset collection until they reach the recordset's end of file (EOF) marker. This is the result for Do While Loop Debug.Print...

User Interaction and the Utility Object

To program truly powerful AutoCAD applications and macros, you need to be able to interact with the user. The AutoCAD Automation model provides the Utility and SelectionSet objects to do just that. Chapter 12 discusses the SelectionSet object. This chapter discusses the Utility object, which contains a number of methods for obtaining user input via the AutoCAD command line and graphics screen, such as picking points, entering distances and angles, and picking a single entity. In addition to...

Writing Statements on Multiple Lines

To write a long statement on more than one line, use the line continuation character, which is a space followed by an underscore ( _). Writing your code this way makes it more readable both in print and on the screen. This example shows the line continuation character in action (AcadRegion(0), AcadSpline) 'concatenate a long string value Mypath Application.Path & My Custom Folders VBA Programs & _ Program 1 DVB Files Note Don't place comments after the line continuation character on the...

Accessing and Iterating Groups

The Groups collection is accessed via a Document object. In this code, ThisDrawing is used as the active document To set a reference to an existing Group object, use the Item method of the Groups collection Dim objGroup As AcadGroup Set objGroup objGroups.Item(My Group) The parameter of this method is either a number representing the position of the desired Group object within the Groups collection or a string representing the name of the desired Group object. If you use an index number, it...

AcDim ArrowheadType

The following constants can be values for these properties The Arrowhead1Type and Arrowhead2Type properties of the dimension objects that support them (all except AcadDimOrdinate and AcadDimRadial) The Arrowhead1Type property of the AcadTolerance object The ArrowheadType property of the AcadDimRadial and AcadLeader objects The arrowhead is the default determined by the dimension style. The arrowhead is a closed empty triangle. The arrowhead is a closed triangle with the dimension line inside....

Contents

About the About the Technical chapter 1 The VBA Integrated Development Environment Visual Basic Windows, Events, and Event-Driven vs. Procedural Programming 2 Developing Your Applications Starting the Exploring the User The Project The Code The Properties The Object and Procedure The Immediate The Options Dialog Managing Project Creating, Opening, and Saving Projects 10 Adding, Saving, and Removing Files 12 Adding ActiveX Controls and Code Components 13 The Object VBARUN and the Macros Dialog...

Starting the Editor

One of the first questions that you will face is How do I enter source code (structured commands) or develop a user interface (forms or dialog boxes) The answer is the IDE, a graphical user interface you use to develop applications. It is similar to development environments provided in other applications, such as Microsoft Access and Microsoft Excel. To display the VBAIDE, choose Tools > Macro > Visual Basic Editor or press Alt+F11. Alternatively, you can start the editor by typing VBAIDE...

Acad Preferences Object

The AcadPreferences object specifies the current AutoCAD setting, holding all the options from the Options dialog box that reside in the Registry. Consult this dialog box from the Tools menu for a list of all the current settings, most of them being accessed using the AcadPreferences object. Options that reside in the drawing can be found through the AcadDatabasePreferences object. The AcadPreferences object can be referenced from the Preferences property on the AcadApplication object. The...

The Author Property

The Author property specifies the drawing author's name object.Author Table 21-1 shows the Author property's parameter. Table 21-1. The Author Property Parameter Table 21-1. The Author Property Parameter Here's an example of setting the Author property ThisDrawing.SummaryInfo.Author Joe Sutphin

AcDim Fit

The following constants can be values for the Fit property of the dimension objects that support it (all except AcadDimOrdinate). Text and arrowheads are placed inside the extension lines. Arrowheads are placed inside the extension lines. The text is placed outside the arrowheads. Text is placed inside the extension lines. The arrowheads are placed outside the extension lines. This option places the text and arrowheads in the best-fit location given the space available.

AcVertical Alignment

The following constants can be values for the VerticalAlignment property of the AcadAttribute, AcadAttributeReference, and AcadText objects. Align on the baseline. Note that the baseline isn't the same as the bottom. The baseline is defined at a level partway between the bottom position and the middle position. Align at the middle. This is midway between the bottom and the top positions.

Creating a New Layer

You can create as many layers as needed using the criterion illustrated in Table 6-1. The Add method is used to create a Layer object and to add it to the Layers collection. Set LayerObject LayerCollection.Add(LayerName) The name for the new layer. If the parameter isn't a valid layer name, an exception will be raised. If you attempt to add a new layer with the same name as an existing layer, a reference to the existing Layer is returned. The following example retrieves a layer name from the...

Changing the Menu

As I pointed out earlier, AutoCAD 2000 and later allow you to completely replace the current menu bar with a new menu group by loading it as the base menu. The individual menus that the menu bar displays are contained in the MenuBar collection. You can add, rearrange, and remove menus within a menu group from the menu bar, and it's this modification of the menu bar that you'll consider next. AutoCAD 2006 introduces the concept of work spaces, which are stored in the current .cui file. Work...

Adding a User Form to Your Application

If your application requires a user interface or dialog with the user, you need to add a UserForm. A UserForm, or dialog box, is a window in which several bits of information can be gathered or displayed at once. A login dialog box is a simple example of a form, whereas the AutoCAD Select File dialog box in Figure 3-1 represents a more complex application example. Figure 3-1. The Select File dialog box To add a UserForm to your project, select Insert UserForm. Alternatively, you can use a...

Returns Description

Saves the document as specified by the parameters. Parameters FileName As String and FileType As AcMenuFileType. For a list of possible values for the AcMenuFileType enumeration, see Appendix B. Sends a command string from a VB or VBA application to the document to be processed. If the drawing specified isn't active, it will be made active. This method processes any AutoCAD command-line function, including LISP expressions. This method is generally synchronous. Only when responding to user...

Scroll Bar

Use ScrollBar controls to allow the user to easily change values based on clicking the up and down arrows of the control (see Figure 3-25). Typically a ScrollBar increases or decreases counting values within a TextBox control. This control contains a slider bar indicating its relative position to the minimum and maximum values. The slider also allows the user to quickly make very large changes to the value. Figure 3-24. A UserForm with a MultiPage control Figure 3-24. A UserForm with a...

Acad DimRadial Object Properties

The AcadDimRadial object inherits all the properties of the AcadEntity object, the AcadObject object, and the AcadDimension object, as well as the common Application property. It also supports the following properties. Gets or sets the rounding of alternative units if the AltUnits property is turned on. This property and the two that follow override the value of the DIMALTZ system variable. Gets or sets whether leading zeros in alternative dimension values are suppressed. The initial value for...

The VBA Integrated Development Environment VBAIDE

W ithin AutoCAD, you develop VBA programs in the Visual Basic for Applications (VBA) Integrated Development Environment (IDE). As it does with the Visual LISP IDE, Autodesk provides the VBAIDE as an integral part of many of its products, including AutoCAD. Unlike the Visual LISP IDE, however, Microsoft licenses the VBAIDE to Autodesk for inclusion in its products. Therefore, its features are from Microsoft, not Autodesk. This chapter explores the VBAIDE environment's facets and shows you how to...

IlI

Location C WINNT system32 stiJole2.tlb Language Standard Figure 19-1. The References dialog box The following example illustrates starting Microsoft Excel programmatically Public Sub StartExcel(App As Excel.Application, Visible As Boolean) 'handle errors inline On Error Resume Next Set App GetObject(, Excel.Application) 'depends on application 'check to see if application is running If Err Then 'no, application will need to be started Err.Clear Set App 'depends on application 'check to see if...

Deleting Toolbars and Toolbar Buttons

You can delete both toolbars and toolbar buttons with the Delete method. I covered a lot of material in this chapter. The part of the AutoCAD object model that represents the menu and toolbar structure is quite complicated. The information in this chapter should provide you with a sound basis for modifying menus and toolbars. For details of every property and method of the menu structure objects, please consult Appendix A.

Acad LineType Object Properties

The AcadLineType object inherits all the properties of the AcadObject object, as well as the common Application property. It also supports the following properties. Gets or sets a text description of the linetype object. This can be up to 47 characters long and can contain text or a series of characters to represent the linetype pattern itself (using underscores, dots, dashes, and spaces). Gets or sets the name of the linetype definition. Note Because this object inherits from AcadObject, it...

Variable Scope and Lifetime

If you declare a variable in a procedure, only code in that procedure can access it. This is known as local scope. But sometimes you'll want procedures throughout a module or throughout the application to access one of your variables. Visual Basic lets you specify this broader scope when you declare your variables. All procedures, variables, constants, and so on, have a scope, also called a lifetime. Where you declare them determines when and from where you can access them. You can declare...

Introduction to Arrays

An array is a variable that can hold multiple values of the same data type, each value placed into a separate compartment. In contrast, a normal variable can hold only one value. Tip If you need to store an array of different kinds of values, create an array of Variants. You can work with arrays as a whole or by using an index value to access each element. AutoCAD uses arrays for 3-D WCS coordinates. Arrays are nothing more than a collection of values treated as a single unit, analogous to a...

Working with Services and Other APIs

Like applications, services are processes that run within the operating-system-protected namespaces. Unlike applications, though, services normally don't provide a graphical interface and are instead intended for under-the-hood purposes such as monitoring, logging, reacting, or protecting other system resources. Many services are very useful for making sure the overall environment is known. One service you might be interested in using is the Active Directory Service Interfaces (ADSI) object for...

Acad Views Collection

The AcadViews collection contains all the views in the drawing. Although this collection inherits a Delete method, you can't actually delete this collection. If you need to delete a specific view, use the Delete method of the AcadView object. There is no limit to the number of views you can create in your drawing. However, there can be only one instance of the AcadViews collection, which is predefined for each drawing. You can make multiple references to it by using the Views property of the...

Connectivity Automation Objects

The dbConnect feature added in AutoCAD 2000 provides a powerful means for linking drawing entities to external data sources such as Excel spreadsheets, Access databases, and other ODBC data sources. It also provides a means for automatically labeling entities using Leader callouts with special control over the text labeling that is driven directly by linked values in the external data source. This functionality is provided through a special API called Connectivity Automation Objects, or CAO....

Adding Menu Items to the Shortcut Menu

The shortcut menu accessed by pressing Shift and right-clicking is a menu within the AutoCAD base menu group. The Boolean ShortcutMenu property of a PopupMenu object is set to True if the menu is a shortcut menu. You can add menu items to the shortcut menu in precisely the same way as you do to a drop-down menu, as I discussed earlier in this chapter. The following code sample adds a Zoom Extents menu item to the shortcut menu Public Sub AddMenuItemToShortcutMenu() Dim objMenuGroup As...

Acad Dictionary Object Properties

In addition to the properties inherited from the AcadObject object and the common Application property, the AcadDictionary object supports the following properties. Gets the number of items in the dictionary. This property's value is read Gets or sets the name of the dictionary. Note Because this object inherits from AcadObject, it supports the Modified event.

Acad Trace Object Properties

The AcadTrace object inherits all the properties of the AcadEntity and AcadObject objects, as well as the common Application property. It also supports the following properties. Gets or sets the coordinate of a single vertex in the object. This will replace an existing vertex for the specified object. Use standard array-handling techniques to process the values contained in this property. It returns a three-element array of Doubles containing 3-D coordinates in WCS. Note that the Z coordinate...

The AngleToString Method

Use the AngleToString method to convert an angle in radians to a string representing the angle in angular units. This is useful for converting radian angles, used by most geometric properties and methods, into a form that the user can work with. This method returns a string that gives the angle in a specified unit type and precision. This method has the following syntax strAngle UtilityObject.AngleToString(Angle, Unit, Precision) Table 7-12 explains this method's parameters. Table 7-12. The...

The Summary Info Object

AutoCAD 2005 introduces the means for creating and storing properties of a drawing. Author, title, subject, and other information may be added, queried, and manipulated. Users can manipulate the standard built-in drawing properties or create custom properties specific to their needs. You may access and manipulate this feature from a command prompt, a GUI interface, or pro-grammatically. The command interface is DWGPROPS, which displays a dialog form for adding and changing drawing properties,...

The RealToString Method

Use the RealToString method to convert a double to a string representing a distance in linear units. This is useful for converting the lengths, sizes, and locations that most AutoCAD geometric properties and methods use into a form that the user can work with. This method returns a string containing the distance in a specified unit type and precision. It has the following syntax strDistance UtilityObject.RealToString(Distance, Unit, Precision) Table 7-14 explains this method's parameters. Table...

Acad Hyperlinks Collection Methods

The AcadHyperlinks collection doesn't inherit from AcadObject. It supports the following methods. Creates a named AcadHyperlink object and adds it to the collection. Parameters Name As String, Description As Variant , and NamedLocation As Variant . Gets the member object at a given index in a collection, group, or selection set. Parameter Index As Integer (An Integer of a String). If the value for Index is a String, it must match an existing object name in the collection.

Acad Xline Object Methods

The AcadXline inherits all the methods of the AcadEntity and AcadObject objects. It also supports the following method. Creates a new line by offsetting the current Xline by a specified distance, which can be positive or negative but can't be zero. If the offset is negative, this means that the line is drawn closer to the WCS origin. Parameter Distance As Double.

Acad DimAngular Object

The AcadDimAngular object represents a dimension of the angular distance between two lines or the angle of a circular arc. If you need extension lines, they'll be added automatically. The end points provided will be used as origin points for the extension lines. The AcadDimAngular object is created using the AddDimAngular method of the AcadBlock, AcadModelSpace, or AcadPaperSpace object. The AcadDimAngular object inherits all the methods of the AcadEntity and AcadObject objects. It supports no...

Acad DimAligned Object

The AcadDimAligned object represents a linear dimension, measuring the distance between two points, that's displayed parallel to the points being measured. In aligned dimensions, the dimension line is parallel to the extension line origins. The extension line origins are specified using the ExtLine1Point and ExtLine2Point properties. The AcadDimAligned object is created using the AddDimAligned method of the AcadBlock, AcadModelSpace, or AcadPaperSpace object. The AcadDimAligned object inherits...

Layer StateManager Object

The LayerStateManager object provides a set of functions for working with saved layer settings. The LayerStateManager object manipulates XRecord objects that define the properties of a layer. These XRecords are stored in the ACAD_LAYERSTATE dictionary, which is an extension dictionary in the drawing's Layers collection. (An extension dictionary is a mechanism for attaching data to objects. Every AutoCAD object can have an extension dictionary.) After you retrieve the LayerStateManager object...

Creating New Toolbars

You can create and add a new Toolbar object to the Toolbars collection through the Add method, which returns a reference to the new Toolbar object. Set ToolbarObject ToolbarsCollection.Add(ToolbarName) Table 16-12 shows the Add method's parameter. Table 16-12. The Add Method's Parameter Table 16-12. The Add Method's Parameter The identifying name of the newly created Toolbar object The following example illustrates how to create a new toolbar in the AutoCAD collection. A check is in place to...

Acad LineTypes Collection

The AcadLinetypes collection contains all the linetypes defined for a drawing. You use the Add method to add a new linetype definition to the collection, and you can select a particular linetype using the Item method. You can load an existing linetype definition using the Load method. The collection also inherits a Delete method from AcadObject, but you can't use it, as the collection can't be deleted. To remove a linetype, use the Delete method of the AcadLinetype object. There is no limit to...

Acad MenuGroups Collection

The AcadMenuGroups collection contains all the AcadMenuGroup objects, from which you can get a reference to all pop-up menus and toolbars loaded in the current AutoCAD session. To load a new menu group from a file into this collection, use the Load method. Note that you can't create new menu groups. However, you can load an existing menu group and save it out again with a new name and to new menu file. The menus and toolbars thus become available for editing. To unload a menu group from this...

AcLine Weight

The following constants can be values for these properties The Lineweight property of the AcadEntity object (and all derived objects), the Acad-DatabasePreferences, AcadGroup, and AcadLayer objects The DimensionLineweight property of the dimension objects that support it (all except AcadDimOrdinate) and the AcadLeader object The ExtensionLineweight property of the dimension objects that support it (all except AcadDimDiametric, AcadDimOrdinate, and AcadDimRadial) Draws lines in the default...

AcDim VerticalJustification

The following constants can be values for the VerticalTextPosition property of the AcadDimension object (and all derived objects) and the AcadLeader object. Centers the dimension text between the extension lines Places the dimension text above the dimension line except when the dimension line isn't horizontal and text inside the extension lines is forced horizontal Places the dimension text on the side of the dimension line farthest from the defining points Places the dimension text to conform...

Using the Add Method

Use the Blocks collection's Add method to add a new Block object. The method takes a single string parameter the new block's name. It returns a reference to the new Block object. If the parameter is not a valid block name, Add raises an exception. If you try to name a new block the same as an existing block, Add returns a reference to the existing Block object. This method has the following syntax Set BlockObject BlocksCollection.Add(InsertionPoint, BlockName) Table 13-2 explains this method's...

Acad PreferencesOpen Save Object Properties

In addition to the common Application property, the AcadPreferencesOpenSave object supports the following properties. Specifies whether an audit should be performed after a DXFIN or DXBIN interchange command is rendered. Gets or sets an interval for automatic saving. The value must be between 0 and 600. A value of 0 indicates that no automatic saving is required. The timer starts as soon as you make a change to a drawing. It is reset and restarted whenever the drawing is saved. The value for...

Acad DimArc Length Object

This is a circular-style dimension measuring the length of an arc. The AcadDimArcLength object inherits all the methods of the AcadEntity and AcadObject objects. It supports no other methods. The AcadDimArcLength object inherits all the properties of the AcadEntity object, the AcadObject object, and the AcadDimension object, as well as the common Application property. It also supports the following properties. Gets or sets the rounding of alternative units, if the AltUnits property is turned...

Acad Shape Object Properties

The AcadShape object inherits all the properties of the AcadEntity and AcadObject objects, as well as the common Application property. It also supports the following properties. Height Double Sets the height of the shape object in drawing units. InsertionPoint Variant Gets or sets the insertion point for a shape as a set of 3-D WCS coordinates. It returns a three-element array of Doubles. Name String Gets or sets the name of the object. Gets or sets the 3-D (Z-axis) normal unit vector for the...

Note AutoCAD does not support saving menu groups

As you would expect, Save saves the menu group to the file it's already associated with, and SaveAs allows you to save the menu group under a new name. MenuGroupObject.SaveAs FileName, MenuFileType Table 16-3 shows the SaveAs method's parameters. Table 16-3. The SaveAs Method's Parameters Table 16-3. The SaveAs Method's Parameters Determines whether the menu group is saved as a source or a compiled file. It must take one of the AcMenuFileType constants in Table 16-4. The full path and file name...

The Algorithm Property

The Algorithm property specifies the identifier of the encryption algorithm to be used in signing the drawing file. Table 17-2 shows the Algorithm property's parameters. Table 17-2. The Algorithm Property's Parameters Table 17-2. The Algorithm Property's Parameters The object or objects to which this property applies Long AcadSecurityParams Constants enum read-write Specifies only the following constant Here's an example of how to set the Algorithm property Dim sp As New AcadSecurityParams...

SaveAsFile Common Control Dialog Replacement for VBA

Using the SaveAsFile common control dialog adds a look of consistency to your application. The SaveAsFile dialog is part of the comdlg32.dll library ofWindows API routines and is easily accessed. The following example uses the comdlg32.dll routines to save a drawing file. Private Declare Function GetSaveFileName Lib comdlg32.dll Alias _ GetSaveFileNameA (pOpenfilename As OPENFILENAME) As Long Private Type OPENFILENAME lStructSize As Long hwndOwner As Long hInstance As Long lpstrFilter As String...

Acad Group Object Properties

In addition to the properties inherited from the AcadObject object, the AcadGroup object supports the following properties. Gets or sets the color of the group object. Use a color index number from 0 to 256 or one of the constants listed here acByBlock (where AutoCAD draws objects in the default color) or acByLayer (where AutoCAD draws objects in the color specified for the layer). For a list of possible values for the AcColor enumerated type, see Appendix B. Gets the number of items in the...

Acad View Object Properties

The AcadView object inherits all the properties of the AcadObject object, as well as the common Application property. It also supports the following properties. Gets or sets the center of the view as a set of 2D coordinates (as Doubles). The default center is (0,0). Gets or sets the viewing direction for a 3-D visualization of the drawing. This property puts the viewer in a position to look at the drawing as if looking back at the origin (0, 0, 0) from a specified point in space. It is similar...

Adding a Control to a Form

When you add a UserForm to your project, another window immediately appears. This window, called the Toolbox, is where you'll find the intrinsic, or default, ActiveX controls that are available for you to design your user interface (see Figure 3-7). Placing an ActiveX control on a form is simply a matter of clicking the control in the Toolbox and then clicking the area of the UserForm where you want to place the control. Each time you drop a new control onto a form, VBA automatically provides a...

Acad Viewports Collection Methods

The AcadViewports collection inherits all the methods of the AcadObject object. It also supports the following methods. Creates a member object and adds it to the collection. Parameter Name As String. Deletes a viewport configuration, which consists of a single viewport that has been split using the Split method. Once a viewport has been split, the resulting viewports are considered a viewport configuration and have the same name as the original viewport before the split. Parameter Name As...

The Cone

You create a 3DSolid object in the form of a cone using the AddCone method. The base of the cone is parallel with the XY plane of the WCS. Set 3DSolidObject Object.AddCone(ConeCenter, BaseRadius, Height) Table 9-2 presents the AddCone method's parameters, and Figure 9-2 shows an example of a cone in AutoCAD. Table 9-2. The AddCone Method's Parameters Table 9-2. The AddCone Method's Parameters A three-element array of doubles specifying the cone's center in A positive value representing the...

AcTable StyleOverrides

The following constants can be values for TableStyleOverrides property of an AcadTable object. 1 Indicates title-suppressed table style override for table object 2 Indicates header-suppressed table style override for table object 3 Indicates flow direction table style override for table object 4 Indicates horizontal cell margin table style override for table object 5 Indicates vertical cell margin table style override for table object 6 Indicates title row color table style override for table...

Acad DimDiametric Object

The AcadDimDiametric object represents a dimension of the diameter of a circle or arc. The position of the text, set in the TextPosition property, determines the location of the dimension line. The AcadDimDiametric object is created using the AddDimDiametric method of the AcadBlock, AcadModelSpace, or AcadPaperSpace object. The AcadDimDiametric object inherits all the properties of the AcadEntity and AcadObject objects. It supports no other methods. The AcadDimDiametric object supports all the...

Acad Viewport Object Methods

The AcadViewport object inherits all the methods of the AcadObject object. It also supports the following methods. Gets the grid spacing for the viewport. Parameters XSpacing As Double and Gets the snap spacing for the viewport. Parameters XSpacing As Double and Sets the grid spacing for the viewport. Parameters XSpacing As Double and Sets the snap spacing for the viewport. Parameters XSpacing As Double and Sets the view in a viewport to a saved view in the AcadViews collection. Para Splits a...

Acad RegisteredApplications Collection Methods

The AcadRegisteredApplications collection inherits all the methods of the AcadObject object. It also supports the following methods. Creates a member object and adds it to the collection. Parameter Name As String. Gets the member object at a given index in a collection. Parameter Index As Variant (an Integer or a String). If the Index value is a String, it must match an existing object name in the collection.

Acad DimStyles Collection Methods

In addition to the methods inherited from the AcadObject object, the AcadDimStyles collection supports the following methods. Creates an AcadDimStyle object and adds it to the collection. Parameter Name As String. Gets the member object at a given index in the collection. Parameter Index As Variant (Integer or String). If the Index value is a String, it must match an existing style definition.

Adding a Selection Set Object

Selection sets are usually added to the collection on an as-needed basis. You can create as many as you need, but they're typically transient you create them on demand and then discard them. You use the Add method see Table 12-1 for parameter details of the SelectionSets collection to create a SelectionSet object. Set SelectionSetObject Table 12-1 explains this method's parameter. Table 12-1. The Add Method Parameter Table 12-1. The Add Method Parameter Name of the newly created selection set...

Objects and Classes

An object is the creation, or instantiation, of a class. A class is a template, or definition, of a potential object. This template is used to create as many objects as needed based on a single class definition. Each object is an instance of the class. The action of creating a new object instance is referred to as instantiation. The word class refers to classifying objects. For example, the entity objects Line and Circle are instances of the AcadLine and AcadCircle classes, respectively. Visual...

Plotting Your Drawing

This section details the various means used to plot your drawings. It's a good idea to preview your drawing before you print it out. AutoCAD provides a means of previewing the active layout of your drawing using the DisplayPlotPreview method. This method displays the Plot Preview box, which must be dismissed by the user rather than through code. The drawing for which the DisplayPlotPreview method is invoked will become the active drawing and will remain so even after you've dismissed the Plot...

The Put RemoteFile Method

Use the PutRemoteFile method to upload a local file to a URL. This method returns nothing. It has the following syntax UtilityObject.PutRemoteFile UploadURL, LocalFile Table 7-21 explains this method's parameters. Table 7-21. The PutRemoteFile Method's Parameters Table 7-21. The PutRemoteFile Method's Parameters If UploadURL is a secure URL, the method displays a dialog box to ask the user for their access information such as username and password. For more extensive Web-enabled capabilities,...

Acad Plot Object Properties

As well as the common Application property, the AcadPlot object supports the following properties. Specifies whether quiet error mode is enabled. Quiet error mode logs all plot-related error messages into a log file. This is essential for certain plotting applications, such as batch plotting, that require uninterrupted application execution. When the quiet error mode is disabled, errors during printing are displayed in alert boxes. Gets or sets the number of copies to be plotted. Specifies...

The GetXXX Methods

The GetXXX methods get specific types of data from the user. These methods make AutoCAD pause until the user supplies a value at the command prompt or picks a point in the drawing window. If the user supplies the wrong type of data, such as typing a string when a number is needed, AutoCAD displays a message at the command prompt that tells them to reenter the data. The GetKeyword method gets a command line option from the user. You must call InitializeUserInput to establish the list of keywords...

Acad PreferencesUser Object Properties

As well as the common Application property, the AcadPreferencesUser object supports the following properties. Gets or sets the units that are automatically used for objects in the AutoCAD Design Center for a source drawing without assigned insert units. The value of this property is stored in the INSUNITSDEFSOURCE system variable. The initial value is acInsertUnitsUnitless. For a list of possible values for the AcInsertUnits enumerated type, see Appendix B. Gets or sets the units that are...

Acad Layers Collection Methods

In addition to the methods inherited from the AcadObject object, the AcadLayers collection supports the following methods. Creates a member object and adds it to the collection. Parameter Name As String. Gets the member object at a given index in a collection, group, or selection set. Parameter Index As Variant an Integer or a String . If the Index value is a String, it must match an existing object name in the collection.

Acad Xline Object Properties

The AcadXline object inherits all the properties of the AcadEntity and AcadObject objects, as well as the common Application property. It also supports the following properties. Gets or sets the point through which the Xline passes. It returns a set of 3-D coordinates as a three-element array of Doubles. Gets or sets the direction for the Xline through a vector. It returns a three-element array of Doubles. Gets or sets a second point on the Xline. It returns a set of 3-D WCS coordinates as a...

Saving and Retrieving Personal Preferences

Profiles are named environment configurations that allow you to load and change your entire desktop and support configurations at will. For example, you may create one for each project you work on, you may create one for each user on a shared workstation, or you may create one for each add-on application you use in AutoCAD. Profiles are saved and recalled from the Windows Registry. You can save them and export them to .arg files, but they are actually Registry export files, having the same...

Acad Solid Object Properties

The AcadSolid object inherits all the properties of the AcadEntity and AcadObject objects, as well as the common Application property. It also supports the following properties. Coordinate Variant Gets or sets the coordinate of a single vertex in the object. This will replace an existing vertex for the specified object. Use standard array-handling techniques to process the values contained in this property. It returns a three-element array of Doubles containing 3-D coordinates in WCS. Note that...

The Get CustomByIndex Method

This method retrieves the custom property field and value based upon an index value. The method returns nothing, and has the following syntax object.GetCustomByIndex Index, Key, Value Table 21-8 details this method's parameters. Table 21-8. GetCustomByIndex Method Parameters Table 21-8. GetCustomByIndex Method Parameters The index value of the custom property field this index can be from zero to the number of custom properties minus one. The name of the custom property to get. The variable to...

The IsRemote File Method

Use the IsRemoteFile method to determine whether a local file was retrieved from a URL. The OutputURL parameter contains the file's original URL. This method returns True if the file was downloaded from a URL. This method has the following syntax blnStatus UtilityObject.IsRemoteFile LocalFile, OutputURL Table 7-20 explains this method's parameters. Table 7-20. The IsRemoteFile Method's Parameters LocalFile String The file name of a local file to check. OutputURL String Output. The original URL...

The Get RemoteFile Method

Use the GetRemoteFile method to retrieve a remote file given a URL. The file is downloaded to a temporary local file with the name being passed back in the LocalFile output parameter. This method returns nothing. It has the following syntax UtilityObject.GetRemoteFile InputURL, LocalFile, IgnoreCache Table 7-19 explains this method's parameters. Table 7-19. The GetRemoteFile Method's Parameters Table 7-19. The GetRemoteFile Method's Parameters The URL from which to download the file. Output....