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...

The Properties Window

Properties control an object's behavior. You can query or control properties of AutoCAD entities, such as the color or linetype of a Line object, using the Color or Linetype properties. The Properties window displays an object's design-time properties. You can change design-time properties while you develop your application. Changing properties during development has no effect on what you do in the IDE. However, any of these property changes could affect how well (and sometimes whether) your...

Description

Gets or sets the horizontal and vertical alignments of the attribute. For a list of the values for the AcAlignment enumeration, see Appendix B. Gets or sets whether the text is backward. Gets or sets whether the attribute has the same value in every occurrence. AutoCAD doesn't prompt for a value of constant attributes. Gets or sets the field length of the attribute. Gets or sets the height of the attribute. Gets or sets the horizontal alignment of the attribute. Gets the insertion point of 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...

Exiting a Sub or Function Procedure

Using the Exit statement immediately exits a Sub or Function procedure. The syntax is simple Public Sub SubName() Public Function FunctionName() As Object It is useful to exit a Sub or Function procedure when a condition has been met and you don't want to execute any remaining code. This provides a means of exiting the procedure as soon as the condition is met.

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.

AcHatch Style

The following constants can be values for the HatchStyle property of the AcadHatch object. Specifies standard style or normal. This option hatches inward from the outermost area boundary. If AutoCAD encounters an internal boundary, it turns off hatching until it encounters another boundary. Fills the outermost areas only. This style also hatches inward from the area boundary, but it turns off hatching if it encounters an internal boundary and doesn't turn it back on again. Ignores internal...

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.

Combining Statements on a Single Line

Typically, you place only one statement on a line of source code. But sometimes combining more than one statement on a single line can make your code more readable, especially in AutoCAD. Consider these six lines of code StartPoint(0) 0 StartPoint(1) 0 StartPoint(2) 0 EndPoint(0) 1 EndPoint(1) 1 EndPoint(2) 0 You can make them more readable by placing similar statements on the same line StartPoint(0) 0 StartPoint(1) 0 StartPoint(2) 0 EndPoint(0) 1 EndPoint(1) 1 EndPoint(2) 0 Each statement is...

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...

Name Data Type Description

MenuFileName String The path and file name of the menu file to be loaded. BaseMenu Boolean This optional parameter determines whether the menu group is loaded as a base or partial menu. If it's set to True, then the menu group is loaded as a base menu. Otherwise, the menu group is loaded as a partial menu. The default is False. Using the Load method with the BaseMenu parameter set to True equates to executing the MENU command inside the AutoCAD application and selecting a file through the...

Name Returns Description

Creates an AcadBlock object and adds it to the collection. Parameters InsertionPoint As Variant and Name As String. The InsertionPoint parameter is a set of 3-D WCS coordinates that specify where the AcadBlock object will be added. Once the AcadBlock has been created, you can add subentities to it. Returns the object at the given index in the collection. Parameter Index As Variant (Integer or String). If the Index value is a String, it must match an existing block definition.

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...

Layout and Plot Configurations

Being able to draw on the screen is great, but eventually you'll want a hard-copy printout of your design. For most businesses, this is a requirement as part of the customer-deliverable product. AutoCAD provides a number of methods to create through code plots of your drawing that the user normally generates using the AutoCAD Plot dialog box interface. This chapter covers the following topics Examining the Plot and PlotConfiguration objects Previewing and plotting a drawing Understanding the...

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.

Acad DimAligned Object Properties

The AcadDimAligned 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, all override the value of the DIMALTZ system variable. Gets or sets whether leading zeros in alternative dimension values are suppressed. The initial...

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...

Inserting Blocks with Attributes

Depending on the setting of the ATTREQ system variable, AutoCAD can automatically handle retrieving and setting attribute values as user inputs. But if you use the InsertBlock method to insert a block reference, you are responsible for setting attribute values. The following example inserts a block and sets several attribute values by locating the appropriate Tag identifiers. It uses the Affirmations block defined earlier. Public Sub TestInsertAndSetAttributes '' get block input from user With...

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....

Acad Preferences Object Properties

In addition to the common Application property, the AcadPreferences object supports the following properties. Gets the AcadPreferencesDrafting object for the application. This prop Gets the AcadPreferencesDisplay object for the application. This prop Gets the AcadPreferencesFiles object for the application. This property's Gets the AcadPreferencesOpenSave object for the application. This prop Gets the AcadPreferencesOutput object for the application. This prop Gets the AcadPreferencesProfiles...

Acad Ray Object Properties

The AcadRay 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 ray passes. It returns a set of 3-D coordinates as a three-element array of Doubles. Gets or sets the direction for the ray through a vector. It returns a three-element array of Doubles. Gets or sets the second point of the ray. It returns a set of 3-D WCS coordinates as a...

Acad Point Object Properties

The AcadPoint 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 coordinates. It returns a three-element array of Doubles containing 3-D coordinates in WCS. Gets or sets the 3-D Z-axis normal unit vector for the mesh. Gets or sets the distance an AcadPoint object is extruded above or below its elevation, in a Z-axis direction. The default is 0.0. Note Because this...

The Cylinder

You add a cylinder to a drawing using the AddCylinder method. The base of the cylinder lies in a plane parallel to the WCS XY plane. Set 3DSolidObject Object.AddCylinder CylinderCenter, Radius, Height Table 9-3 presents the AddCylinder method's parameters, and Figure 9-3 shows an example of a cylinder in AutoCAD. Table 9-3. The AddCylinder Method's Parameters Table 9-3. The AddCylinder Method's Parameters A three-element array of doubles specifying the cylinder's center in WCS coordinates A...

Autocad Dynmode Has A -3 Value

Table C-5 explains the system variables that start with d. Stores the state of the dbConnect Manager, active or not active. Indicates the status of drawing modifications using bit code. Displays the current custom dictionary's path and file name. Displays the current main dictionary's file name. Specifies the default plot style for new layers. This variable's value is also stored in the DefaultPlotStyleForLayer property of the AcadPreferencesOutput object. Specifies the default plot style for...

Acad Dictionaries Collection

The AcadDictionaries collection contains all the dictionaries in the drawing. Although this collection inherits a Delete method, you can't actually delete it. If you need to delete a specific dictionary, use the Delete method found in the AcadDictionary object. There's no limit to the number of dictionaries you can create in your drawing. However, there can be only one instance of the AcadDictionaries collection, which is predefined for each drawing. You can make multiple references to it by...

Creating New Menus

You can add a new menu, represented by a PopupMenu object, to a PopupMenus collection using the Add method. Set PopupMenuObject PopupMenusCollection.Add MenuName Table 16-8 shows the Add method's parameter. Table 16-8. The Add Method's Parameter Table 16-8. The Add Method's Parameter The identifying name of the newly created PopupMenu object The MenuName parameter may be a simple string such as VBATestMenu or one containing special characters such as an ampersand amp placed before a character...

Rotating Objects

Use the Rotate method to rotate a drawing object around a given point in the User Coordinate System's UCS XY plane. This method has the following syntax DrawingObject.Rotate BasePoint, RotationAngle Table 10-5 explains this method's parameters. Table 10-5. Rotate Method Parameters BasePoint Variant A three-element array of doubles that specifies the 3-D WCS coordinates of the point through which the axis of rotation, parallel to the Z-axis of the UCS, passes. RotationAngle Double The angle of...

AutoCAD Events

Events occur as a result of actions happening while your program is running, such as opening or saving a drawing. They allow you to write source code that will execute whenever that event occurs. Messages such as Would you like to save changes are the common results of a user action that has triggered an event. AutoCAD 2006 supports three levels of events application, document, and object. These event levels correspond to the three major areas of AutoCAD. Event handlers are Sub procedures that...

Digital Signatures

To support the Digital Signatures feature from a programming standpoint, Autodesk added in 2004 a new object called SecurityParams. This object allows you to set various security options, including drawing and properties encryption, digital signatures, and timestamps. Several options are available that provide varying levels of security, as presented in this chapter. Although it isn't possible to provide extensive details about cryptography, further details are available on the MSDN Web site...