Hi Sirs
I am just starting learning lisp, And I am looking for a fast way to select multiple objects (usually circle) and export their coordinates and ID into a excel sheet through lisp programming.
As you might see in the attached drawing, the red circles are objects wanted. I have been trying to export their coordinates as well as their IDs in grids, e.g D28, Easting: Northing: . I still haven't found a good way to export ID for each circle.
As my code doesn't work, I wonder what's the most effective way to detect errors in lisp
Thx
Ji
Solved! Go to Solution.
Solved by Hallex. Go to Solution.
Solved by dgorsman. Go to Solution.
Solved by hgasty1001. Go to Solution.
Hi,
What do you mean by ID? circles have no ID as a property, may be you need the text inside, are they circles or blocks with attributes?.
The "attached drawing" it's not a drawing, just a pdf of no use for test.
Any way, if you are looking for the text inside circle here are some ideas and some code:
1.-Get a selection set with the circles (setq ss (ssget '((0 . "CIRCLE")))
2.-Get the radious and center of each circle in the selection set
3.-Create a list of points for use in window polygon selection and filter for text for each circle:
This will create the list of points to pass as a window polygon ("WP") option to ssget
(defun DiscretizeCircle(center radius n / ii delta px pxlist oldosmode) (setq ii 0) (setq delta (/ (* 2 pi) n)) (while (< ii n) (setq px (polar center (* delta ii) radius)) (setq pxlist (cons px pxlist)) (setq ii (+ ii 1)) ) pxlist )
This will return the first text entity found, ignoring others inside the same circle (aprox)
(defun GetTxtInsideCircle(center radius / pxlist ss txt ret) (setq pxlist (DiscretizeCircle center radius 8)) (setq pplist pxlist) (setq ss (ssget "wp" pxlist '((0 . "TEXT")))) (if ss (progn (setq txt (ssname ss 0)) (setq ret (cdr (assoc 1 (entget txt)))) ) ) ret )
4.- Now you have the text, the radious and the center of each circle
5.-Write this info to CSV file
Gaston Nunez
Kelowna - beautiful small city.
To expand a bit more, use the Visual LISP editor to check for matching parenthesis, contextual hightlighting, and to step through the code one statement at a time. All are useful for finding problems.
For the grid references of the circles, if they are not blocks with attributes you could generate a list of coordinates for each x- and y-series of defined grid values. By checking the x/y coordinates against the two lists, you can reverse engineer the appropriate grid identifier. If all the circles are supposed to be on-grid, you could also use this to filter out most other circles (provided everything is drawn accurately).
Hi,
Try this code, pay attention to change circle layer name
and circle radius, I've marked those lines within the code
Say me how it will works for you
Cheers 🙂
@macm.flais wrote:
Hi: Can i use this code to get the x, y and z coordinates of some circles in metric units? Thanks
Hi macm.flais,
change
(setq tmp (list (rtos (* rad 2) 3 3) (rtos (car cp) 3 3) (rtos (cadr cp) 3 3)))
to
(setq tmp (list (rtos (* rad 2) 2 3) (rtos (car cp) 2 3) (rtos (cadr cp) 2 3)))
Henrique