Author Topic: Need help to write radius and center point of selected circle in a file  (Read 1783 times)

0 Members and 1 Guest are viewing this topic.

Vikram

  • Newt
  • Posts: 50
I'm trying to write a lisp where user selects the circles in the drawing and the radius and center coordinates of these circles are written in a file. So far I have done this much. (I actually tried to merge 2 different lisps but I'm a newbie and don't have much experience with AutoLisps )

Code: [Select]
(defun c:XY (/ fp p)
  (setq fp (open (strcat (getvar "dwgprefix")(vl-filename-base (getvar "dwgname")) ".pnt") "w"))
  (setq nbs 0)
  (while (setq PickObject (nentsel "\n Pick a Circle to Get Entity Data: "))
  (progn
(if
(/= nil (osnap (cadr PickObject) "_cen"))
(progn
(setq CenterPoint (osnap (cadr PickObject) "_cen"))
(setq NeaPoint (osnap (cadr PickObject) "_nea"))
(setq Radius (distance CenterPoint NeaPoint))
(setq Diameter (* 2 Radius))
(write-line (strcat "\n Radius: " (rtos Radius 2 2) " | " "Diameter: " (rtos Diameter 2 2) " | " "CenterPoint: " (rtos CenterPoint 2) ) fp)
)
(princ "\n Error! Picked Object don't has Radius! Try Again!")
)
)
(princ "\n Error! Null Selection!")
)
(close fp)
(princ))
{code}
   
)

To get Radius I used this lips but I don't know how to get center coordinates of the circle from this lisp.
Code: [Select]
{code}
(defun c:gcad (/ PickObject CenterPoint NeaPoint Radius Diameter);Get Circle Arc Data
;;; Written by Rogerio Zanini - 31.mar.2010
;;; Based in threat from (thanks to All):
;;; http://forums.augi.com/showthread.php?t=113352
(if (and
(princ "\n Show Radius and Diameter from Arcs (Lwpolyline and Polyline Included) and Circles...")
(setq PickObject (nentsel "\n Pick an Arc or Circle to Get Entity Data: "))
)
(progn
(if
(/= nil (osnap (cadr PickObject) "_cen"))
(progn
(setq CenterPoint (osnap (cadr PickObject) "_cen"))
(setq NeaPoint (osnap (cadr PickObject) "_nea"))
(setq Radius (distance CenterPoint NeaPoint))
(setq Diameter (* 2 Radius))
(princ (strcat "\n Radius: " (rtos Radius 2 2) " | " "Diameter: " (rtos Diameter 2 2)))
)
(princ "\n Error! Picked Object don't has Radius! Try Again!")
)
)
(princ "\n Error! Null Selection!")
)
(princ))
{code}

 

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Need help to write radius and center point of selected circle in a file
« Reply #1 on: January 25, 2021, 12:00:45 PM »
Give this a shot.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ txt opn int sel ent get)
  2.   ;; Tharwat - 25.Jan.2021      ;;
  3.   (and
  4.     (setq txt (getfiled "Save as." (getvar 'DWGPREFIX) "txt" 1))
  5.     (setq opn (open txt "w"))
  6.     (princ
  7.       "\nSelect circles to expor Radius & Center values to txt file : "
  8.     )
  9.     (setq int -1
  10.           sel (ssget '((0 . "CIRCLE")))
  11.     )
  12.     (write-line "Radius\tCenter point" opn)
  13.     (while (setq int (1+ int)
  14.                  ent (ssname sel int)
  15.            )
  16.       (setq get (entget ent))
  17.       (write-line
  18.         (strcat (rtos (cdr (assoc 40 get)) 2 2)
  19.                 "\t"
  20.                 (apply 'strcat
  21.                        (mapcar '(lambda (q) (strcat (rtos q 2 4) " "))
  22.                                (cdr (assoc 10 get))
  23.                        )
  24.                 )
  25.         )
  26.         opn
  27.       )
  28.     )
  29.     (close opn)
  30.   )
  31.   (princ)
  32. )
  33.  

Vikram

  • Newt
  • Posts: 50
Re: Need help to write radius and center point of selected circle in a file
« Reply #2 on: January 26, 2021, 01:38:09 AM »
Hey Tharwat thanks for the help and it worked! Just one more thing is I don't want Z coordinate in it. Just X and Y written in this way
 X205.23 Y504.89

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Need help to write radius and center point of selected circle in a file
« Reply #3 on: January 26, 2021, 05:53:13 AM »
Hey Tharwat thanks for the help and it worked! Just one more thing is I don't want Z coordinate in it. Just X and Y written in this way
 X205.23 Y504.89
Here you go.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ txt opn int sel ent get)
  2.   ;; Tharwat - 26.Jan.2021      ;;
  3.   (and
  4.     (setq txt (getfiled "Save as." (getvar 'DWGPREFIX) "txt" 1))
  5.     (setq opn (open txt "w"))
  6.     (princ
  7.       "\nSelect circles to expor Radius & Center values to txt file : "
  8.     )
  9.     (setq int -1
  10.           sel (ssget '((0 . "CIRCLE")))
  11.     )
  12.     (write-line "Radius\tCenter point" opn)
  13.     (while (setq int (1+ int)
  14.                  ent (ssname sel int)
  15.            )
  16.       (setq get (entget ent))
  17.       (write-line
  18.         (strcat
  19.           (rtos (cdr (assoc 40 get)) 2 2)
  20.           "\t"
  21.           (apply 'strcat
  22.                  (mapcar '(lambda (j k) (strcat k (rtos j 2 4) " "))
  23.                          (mapcar '+ (cdr (assoc 10 get)) '(0. 0.))
  24.                          '("X" "Y")
  25.                  )
  26.           )
  27.         )
  28.         opn
  29.       )
  30.     )
  31.     (close opn)
  32.   )
  33.   (princ)
  34. )
  35.  

Vikram

  • Newt
  • Posts: 50
Re: Need help to write radius and center point of selected circle in a file
« Reply #4 on: January 26, 2021, 02:21:05 PM »
It worked! thanks for your time  :-D

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Need help to write radius and center point of selected circle in a file
« Reply #5 on: January 26, 2021, 03:31:43 PM »
It worked! thanks for your time  :-D

You're welcome anytime.