Hi,
I would like to erase all the lines that are inside all the circles in the drawing.
The lines can be on any layer, color or linetype. Can someone help me with this?
I hope for you understand. Here is my drawing image.
Good day.
Stefano
Hi Stefano,
I'm not sure if this is an AutoCAD General question or a programming request. If the circles are on a different layer than the lines,
I would just turn off the layer that the circles are on and then do an erase window to erase the lines.
Escher
Stefano,
Welcome to the Exchange! To test this function, start a new drawing to see how it works. Draw a few circles and then a few lines inside and outside the circles and also a few lines crossing into the circles. The program will erase all lines that are inside or that cross into the circles.
James
Code:
(defun c:Erlic (/ Buldge Center CircleData Circles Found Lines NextRadians Number
Point PolyCircle Radians Radius Radius2 Times X)
(princ "\nErase Lines in Circles")
(if (setq Circles (ssget "_x" '((0 . "circle"))))
(progn
(command "_undo" "_begin")
(setq Buldge 0.001)
(setq Number 0)
(repeat (sslength Circles)
(setq CircleData (entget (ssname Circles Number)))
(setq Center (cdr (assoc 10 CircleData)))
(setq Radius (cdr (assoc 40 CircleData)))
(setq Radians (/ pi 6.0))
(if (> Radius (* Buldge 2.0))
(progn
(setq Radius2 (float (- Radius Buldge)))
(setq X (/ Radius2 Radius))
(setq Radians (* 2.0 (atan (/ (sqrt (- 1 (* X X))) X))))
(setq Times (fix (1+ (/ (* pi 2) Radians))))
(setq Radians (/ (* pi 2) Times))
(if (> Radians (/ pi 6.0))
(setq Radians (/ pi 6.0))
)
)
)
(setq PolyCircle nil)
(setq NextRadians (* pi 0.5))
(repeat (fix (/ (* pi 2) Radians))
(setq Point (polar Center NextRadians Radius))
(setq PolyCircle (append PolyCircle (list Point)))
(setq NextRadians (+ NextRadians Radians))
)
(if (setq Lines (ssget "_cp" PolyCircle '((0 . "line"))))
(progn
(command "_erase" Lines "")
(setq Found t)
)
)
(setq Number (1+ Number))
)
(if (not Found)
(princ "\nNo Lines found in Circles")
)
(command "_undo" "_end")
)
(princ "\nNo Circles found")
)
(princ)
)
J Briggs,
I first thought that Stefano was looking for a function that would erase all lines within circular areas. I used your function to come up with this version that erases objects using circular areas. It may be useful in some instances.
Zeanor
Here are the command prompts:
Quote:
Erase circular area
Specify center point for circular area:
Specify radius of circular area:
Erase circular area [Window/<Crossing>]:
Code:
(defun c:Erca (/ Buldge Center Circle CircleData EraseArea Found LastEnt NextRadians
Objects Point PolyCircle Radians Radius Radius2 Times X)
(princ "\nErase circular area")
(if (setq Center (getpoint "\nSpecify center point for circular area: "))
(progn
(setq LastEnt (entlast))
(princ "\nSpecify radius of circular area: ")
(command "_circle" Center pause)
(if (setq Circle (entnext LastEnt))
(progn
(setq CircleData (entget Circle))
(setq Radius (cdr (assoc 40 CircleData)))
(initget "Window Crossing")
(if (not (setq EraseArea (getkword "\nErase circular area [Window/<Crossing>]: ")))
(setq EraseArea "Crossing")
)
(command "_erase" Circle "")
(command "_undo" "_begin")
(setq Radians (/ pi 6.0))
(setq Buldge 0.001)
(if (> Radius (* Buldge 2.0))
(progn
(setq Radius2 (float (- Radius Buldge)))
(setq X (/ Radius2 Radius))
(setq Radians (* 2.0 (atan (/ (sqrt (- 1 (* X X))) X))))
(setq Times (fix (1+ (/ (* pi 2) Radians))))
(setq Radians (/ (* pi 2) Times))
(if (> Radians (/ pi 6.0))
(setq Radians (/ pi 6.0))
)
)
)
(setq NextRadians (* pi 0.5))
(repeat (fix (/ (* pi 2) Radians))
(setq Point (polar Center NextRadians Radius))
(setq PolyCircle (append PolyCircle (list Point)))
(setq NextRadians (+ NextRadians Radians))
)
(if (= EraseArea "Crossing")
(if (setq Objects (ssget "_cp" PolyCircle))
(progn
(command "_erase" Objects "")
(setq Found t)
)
)
(if (setq Objects (ssget "_wp" PolyCircle))
(progn
(command "_erase" Objects "")
(setq Found t)
)
)
)
(if (not Found)
(princ "\nNo objects found in Circular area.")
)
(command "_undo" "_end")
)
)
)
)
(princ)
)
Hi James,
I tested the program and it works fine. I would like to be able to select the circles first instead of the program selecting all the circles in the drawing. Is this possible?
Thanks,
Stefano
Zeanor,
That was a nice idea with the circular erase function. It could be modified to include other options as well; such as copy, move and rotate etc.
Hi Dante,
Your last request to have the user select the Circles instead of the program selecting the Circles was a very easy fix. All I had to do was remove the "_x" after the "(ssget" function.
Quote:
Here the program selects the Circles:
(if (setq Circles (ssget "_x" '((0 . "circle"))))
And here the user selects the Circles:
(if (setq Circles (ssget '((0 . "circle"))))
James
Code:
(defun c:Erlic2 (/ Buldge Center CircleData Circles Found Lines NextRadians Number
Point PolyCircle Radians Radius Radius2 Times X)
(princ "\nErase Lines in Circles")
(princ "\nSelect Circles to use:")
(if (setq Circles (ssget '((0 . "circle"))))
(progn
(command "_undo" "_begin")
(setq Buldge 0.001)
(setq Number 0)
(repeat (sslength Circles)
(setq CircleData (entget (ssname Circles Number)))
(setq Center (cdr (assoc 10 CircleData)))
(setq Radius (cdr (assoc 40 CircleData)))
(setq Radians (/ pi 6.0))
(if (> Radius (* Buldge 2.0))
(progn
(setq Radius2 (float (- Radius Buldge)))
(setq X (/ Radius2 Radius))
(setq Radians (* 2.0 (atan (/ (sqrt (- 1 (* X X))) X))))
(setq Times (fix (1+ (/ (* pi 2) Radians))))
(setq Radians (/ (* pi 2) Times))
(if (> Radians (/ pi 6.0))
(setq Radians (/ pi 6.0))
)
)
)
(setq PolyCircle nil)
(setq NextRadians (* pi 0.5))
(repeat (fix (/ (* pi 2) Radians))
(setq Point (polar Center NextRadians Radius))
(setq PolyCircle (append PolyCircle (list Point)))
(setq NextRadians (+ NextRadians Radians))
)
(if (setq Lines (ssget "_cp" PolyCircle '((0 . "line"))))
(progn
(command "_erase" Lines "")
(setq Found t)
)
)
(setq Number (1+ Number))
)
(if (not Found)
(princ "\nNo Lines found in Circles")
)
(command "_undo" "_end")
)
(princ "\nNo Circles selected")
)
(princ)
)