Author Topic: export coordinates from rectangles and polylines within to excel  (Read 697 times)

0 Members and 1 Guest are viewing this topic.

Juergen

  • Mosquito
  • Posts: 2
export coordinates from rectangles and polylines within to excel
« on: December 03, 2019, 05:34:07 AM »
Hi forum users,

i have that lsp file to select
all rectangles within circles that write the
coords from the rectangle and the
circle to an csv file.

What I need to, is an file that do
the same wiht polylines within.

See my attachment files.

Thanks for help.

Code: [Select]
(defun c:koords ( / int sel ent pts crd inc ins cir lst csv opn lwp)
  ;;----------------------------;;
  ;; Tharwat - 18.Feb.2019 ;;
  ;;----------------------------;;
  (and (princ "\nSelct visible rectangles :")
       (setq int -1 sel (ssget '((0 . "LWPOLYLINE"))))
       (while (setq ent (ssname sel (setq int (1+ int))))
         (setq pts nil crd nil)
         (and (setq pts (mapcar 'cdr (vl-remove-if-not '(lambda (p) (= (car p) 10)) (entget ent))))
              (setq inc -1 ins (ssget "_WP" pts '((0 . "CIRCLE"))))
              (while (setq cir (ssname ins (setq inc (1+ inc))))
                (setq crd (cons (cdr (assoc 10 (entget cir))) crd))
                )
              (setq lst (cons (list pts crd) lst))
              )
         )
       ;(setq csv (getfiled "Save csv file" "" "csv" 1))
(setq csv (getfiled "Save csv file" "c:/Users/jschmidthammer/Desktop/" "csv" 1))

       (setq num 0 opn (open csv "w"))
       (mapcar '(lambda (grp) (setq lwp t)
                  (mapcar '(lambda (l)
                             (if lwp (progn (write-line (strcat "LWpolyline (" (itoa (setq num (1+ num))) ")") opn) (setq lwp nil))
                               (mapcar '(lambda (str) (write-line str opn)) '("" "Circles"))
                               )
                             (mapcar '(lambda (pt)
                                        (write-line (strcat (rtos (car pt) 2) " " (rtos (cadr pt) 2)) opn))
                                     l
                                     )
                             )
                          grp
                          )
                  (write-line "" opn)
                  )
               lst
               )
       (close opn)
       )
  (princ)
  )

roy_043

  • Water Moccasin
  • Posts: 1783
  • BricsCAD 18
Re: export coordinates from rectangles and polylines within to excel
« Reply #1 on: December 03, 2019, 10:52:17 AM »
select all rectangles within circles
Contrary to what you say it would seem the code selects all circles within rectangles. Why the triple post?

BIGAL

  • Bull Frog
  • Posts: 457
  • 30 + years of using Autocad
Re: export coordinates from rectangles and polylines within to excel
« Reply #2 on: December 03, 2019, 09:49:41 PM »
Sounds like better to do a boundary is circle or plines, then objects within, choose blocks, arcs, circle, lines, hatch etc.
Do all or pick 1 at a time.
A man who never made a mistake never made anything

Juergen

  • Mosquito
  • Posts: 2
Re: export coordinates from rectangles and polylines within to excel
« Reply #3 on: December 11, 2019, 02:21:01 AM »
Hi, roy_043!

It's right, the code selects all circles within rectangles,
but what I mean is that I can select all rectangles not
one by one.

The triple post comes because there are always errors
at the uploading.

Did you check my attached files?
Here it is clear what I mean exactly.

Thanks for help.

roy_043

  • Water Moccasin
  • Posts: 1783
  • BricsCAD 18
Re: export coordinates from rectangles and polylines within to excel
« Reply #4 on: December 11, 2019, 09:41:24 AM »
Sorry, but you have caught me at the wrong time. I am more and more reluctant to help people who have zero interest in learning how to write Lisp code themselves.

Source of the original code:
https://www.cadtutor.net/forum/topic/66838-coordinates-from-rectangles-and-circles-inside