1. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

This function returns the distance between two given points. Originally posted here by Ed Jobe.
Code:
```
Public Function XYZDistance(Point1 As Variant, Point2 As Variant) As Double
'Returns the distance between two points
Dim dblDist As Double
Dim dblXSl As Double
Dim dblYSl As Double
Dim dblZSl As Double
'Calc distance
dblXSl = (Point1(0) - Point2(0)) ^ 2
dblYSl = (Point1(1) - Point2(1)) ^ 2
dblZSl = (Point1(2) - Point2(2)) ^ 2
dblDist = Sqr(dblXSl + dblYSl + dblZSl)
'Return Distance
XYZDistance = dblDist
End Function```

2. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

For information about creating an ActiveX instance of Excel (or any other Office app) that properly closes all of its objects and doesn't leave a process running...see this thread.

3. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

Accessing Nested Block References

Use this trick to access a nested block reference which is normally not accessible using the model/paper space iterations or selection set filters.

Code:
```
Public Function getNestedBlockRef(ByVal strBlkRefName As String) As AcadBlockReference
For Each objBlk In ThisDrawing.Blocks
For Each objEnt In objBlk
If TypeOf objEnt Is AcadBlockReference Then
If StrComp(objEnt.Name, strBlkRefName, vbTextCompare) = 0 Then
Set getNestedBlockRef = objEnt
Exit Function
End If
End If
Next
Next
Set getNestedBlockRef = Nothing
End Function```

4. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

Originally Posted by rcrabb
Code:
```Function Arccos(X) As Double
Arccos = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
End Function```
This may be nit-picking a bit but shouldn't this function include these lines to avoid Div/0 error:
Code:
```Function Arccos(X) As Double
If Round(X, 8) = 1# Then Arccos = 0#: Exit Function 'modify precision to suit
If Round(X, 8) = -1# Then Arccos = Pi: Exit Function 'modify precision to suit and address "Pi"
Arccos = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
End Function```

5. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

It originally started way back when, in GW/PC basic, when it was just a 'friendlier' way to do it. But it also seems a bit more natural now; if dealing with classes or collections, where the original instance may not be counted

6. Login to Give a bone

## Re: AutoCAD VBA Tips & Tricks

Hello,
I read your comment,also have a look of the link which you have provided.Well nice article,i must say.I appreciate your thought for sharing such tips and solutions at the community.This type of information would so helpful to the students like best tutorials.Please try to share more about this in future,it is really very knowledgeable.Thank you for sharing such a nice comment.

Page 2 of 2 First 12

#### Posting Permissions

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