1. Login to Give a bone

## AutoCAD VBA Tips & Tricks

Looks like it too late to start one. I wonder why there is no tips & tricks forum under programming community. It would have been a great help for the people here, especially for the beginners. Anyway I don't want to wait until it get started ( Because I don't know whether it will be started or not). I am going to post VBA programming specific tips & tricks here. I request you VBA guys to contribute and share your knowledge here.

Look very eagerly forward to see whether this thread can survive the moderator scissors .

As the thread has started growing, it would be nice to keep an index to quickly overview and access the tips. Thanks everybody for the contribution. Please do not post any copyrighted material here. Hope you leave a suitable title with each tip you submit.

AutoCAD VBA Tips & Tricks Index
[/Edit]

2. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

Why would we want to cut it out?

I think one hasn't been started before, because every snippet of code is a tip (the ones that work, that is). Therfore the entire forum is a tips-and-tricks I do have some stickeys at the top of the forum though.

3. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

maybe this is a little too "common" for this section, but I want to try to contribute!

I do a lot of automated shape drawing programs, based on user input and so forth. often in my calculations, I need to use ArcCos - which to my knowledge is unavailable (unlike ArcTan which can be used as "atan()" ... so I found this little function searching through some forums, and its been worth its weight in gold, so to speak

Code:
```Function Arccos(X) As Double
Arccos = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
End Function```
If this post sucks, feel free to mod it out

4. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

Originally Posted by rcrabb
Function Arccos(X) As Double
Arccos = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
End Function
[/code]
I have yet to use trigonometric functions in programs. Still I will keep this one for future use. Here is another tip for VBA

Changing Default Lower Bound of Arrays to 1

Using Option Base statement, you can change the default lower bound of arrays from 0 t0 1. Declare the statement in the module level. You can have only one Option Base statement inside a module. If you want to override the Option Base statement, then use 'To' clause. The following sample program will give you some clear idea of it.
Option Base 1 ' Declare on top of the module

Sub CheckBound()
Dim Array1(5)
Dim Array2(0 To 4)
MsgBox "Array1 : Lbound - " & LBound(Array1) & ", Ubound - " & UBound(Array1) & vbCrLf & _
"Array2 : Lbound - " & LBound(Array2) & ", Ubound - " & UBound(Array2)
End Sub

5. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

Retrieving an Object's Defenition Data

Sometimes we may want to use DXF code/value pairs inside VBA coding. Here is an easy way to check it out using a small bit of lisp.

Code:
`  (entget (car (entsel)))`
Simply enter that line in your command prompt and select the object when asked to do so. A familiar routine for the AutoLISP people. Very handy for all kind of AutoCAD programmers.

6. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

I never needed trig functions until recently when I needed to find the centrepoint and radius for an arc in a polyline. AutoCAD provides a Bulge factor, but you need some trig to resolve this into radius and centrepoint data.
A few clever guys helped me out, and their ideas may be useful for others.
See my thread in this section "Polylines and Mathematics" for more detail.

7. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

i've also done automated shape drawing programs based on user input, i have over 17 different shapes that i'm not too comfortable posting in its entirety online, but would be more than willing to help anyone who needs it!

just drop me a PM

8. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

Originally Posted by zoomharis
Changing Default Lower Bound of Arrays to 1
This is a poor tip, IMHO, because most modern languages use 0 as their base for their structured data. To go "backwards" to a base of 1 only serves to prolong the transition to modern techniques.

9. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

Originally Posted by RobertB
This is a poor tip, IMHO, because most modern languages use 0 as their base for their structured data. To go "backwards" to a base of 1 only serves to prolong the transition to modern techniques.
Thanks for the input, Robert. As far as you people are around here, we are not worried about making mistakes . Could you please explain us the history of using a confusing 0 as base instead of a straight forward 1? It would be really a nice piece of info to grab.

TIA

10. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

Renaming Active Drawings

Normally we can not rename a file when it is open. Here is a tricky way using VBA to rename currently active drawing from the command prompt. Please note that I have used a seperate function for validating filenames. If you know regular expressions, you can make the code compact by replacing the function with a regular experssion. See the attached DVB file.

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•