Not with AutoCAD alone, but you can do this using the
AcadXTransactionManager class from AcadX.arx.
- alfred -
In article <f1282...@WebX.maYIadrTaRb>, farn...@hotmail.com says...
within vb:
ThisDrawing.StartUndoMark
'<do your code>
ThisDrawing.EndUndoMark
where i'm used to have these statements within general functions which run at
the beginning and at the end of application-specific functions, also
controlling setvar's and settings like activelayer, activeucs, ...
- alfred -
In article <f128...@WebX.maYIadrTaRb>, farn...@hotmail.com says...
> Then I can undo it from VBA? Could u show me a small example?
>
- alfred -
In article <f128...@WebX.maYIadrTaRb>, farn...@hotmail.com says...
> Sorry, I still don't get it. I tried putting marks as u mentioned. Then how do I undo? By using sendCommand? Cus send command doesn't work until I stop VBA from running.
>
===============================
Mike Tuersley
PhD @ CADalyst's AutoCAD Clinic
http://www.cadonline.com
James
Option Explicit
Function area_circle_intersect(oC1 As AcadCircle, oC2 As AcadCircle) As
Double
' assumption: circles are in same XY plane in WCS
' Disclaimer: this routine is provided as an example only. It is not
guaranteed
' to run correctly or to be fit for any given service.
' USE AT YOUR OWN RISK
Dim cen1 As Variant, cen2 As Variant
Dim r1 As Double, r2 As Double
Dim x1 As Double, x2 As Double
Dim y1 As Double, y2 As Double
Dim dcen As Double, rmin As Double, rmax As Double
Const pi As Double = 3.14159265
cen1 = oC1.Center: cen2 = oC2.Center
x1 = cen1(0): x2 = cen2(0)
y1 = cen1(1): y2 = cen2(1)
r1 = abs(oC1.Radius): r2 = abs(oC2.Radius) ' just in case negative
radii are possible
If r1 > r2 Then
rmin = r2
rmax = r1
Else
rmin = r1
rmax = r2
End If
dcen = Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2) 'dist between centers
If dcen >= rmin + rmax Then 'circles too far apart to share any area
area_circle_intersect = 0
ElseIf (rmin + dcen) <= rmax Then 'smaller circle completely inside
bigger circle
area_circle_intersect = pi * rmin ^ 2
Else 'circles intersect at 2 points
'formula from
http://mathworld.wolfram.com/Circle-CircleIntersection.html
area_circle_intersect = r1 ^ 2 * acos((dcen ^ 2 + r1 ^ 2 - r2 ^ 2) /
(2 * dcen * r1)) _
+ r2 ^ 2 * acos((dcen ^ 2 + r2 ^ 2 - r1 ^ 2) / (2 * dcen * r2)) _
- 0.5 * Sqr((-dcen + r1 + r2) * (dcen + r1 - r2) * (dcen - r1 + r2)
* (dcen + r1 + r2))
End If
End Function
Function acos(X As Double) As Double
'from VBA help section on "derived math functions"
acos = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
End Function
Sub circle_area_example()
Dim circle1 As AcadCircle, circle2 As AcadCircle
Dim cen1(0 To 2) As Double, cen2(0 To 2) As Double
Dim r1 As Double, r2 As Double
'experiment with different radii, x and y values
cen1(0) = 0 'x of first circle
cen1(1) = 0 'y of first circle
cen2(0) = 67 'x of second circle
cen2(1) = 0 'y of second circle
r1 = 50 'radius of first circle
r2 = 20 'radius of second circle
Set circle1 = ThisDrawing.ModelSpace.AddCircle(cen1, r1)
Set circle2 = ThisDrawing.ModelSpace.AddCircle(cen2, r2)
MsgBox "Intersection area = " & area_circle_intersect(circle1, circle2)
End Sub