Author Topic: Draw circles from coordinates in selected text file  (Read 4172 times)

0 Members and 1 Guest are viewing this topic.

chvnprasad

  • Guest
Draw circles from coordinates in selected text file
« on: August 24, 2014, 02:43:41 AM »
I Need a lisp to draw circles from coordinates in selected text file


Text file:

9485142.9518559594,5166531.8181330599
9484362.5073601492,5166805.4889352201
9484285.1593047995,5166818.7789066397
9484230.7121146191,5166825.8073841901
9484159.8337314799,5166836.7660814496

reltro

  • Guest
Re: Draw circles from coordinates in selected text file
« Reply #1 on: August 24, 2014, 03:26:52 AM »
hey cvnp...

Im not sure how u want to draw a circle just out of coordinates, without radius or somethig similar...

diameter?
radius?
2 Points?
3 Points?


But, to read coordiantes form a file, this may help:

Code - Auto/Visual Lisp: [Select]
  1. (defun foo (/ f l lst)
  2.     (setq f (open "D:\\Circles.txt" "r")) ;;change the Path to point ur file!
  3.     (while (setq l (read-line f))
  4.         (setq lst (cons (read (strcat "(" (vl-string-translate "," " " l) ")")) lst))
  5.     )
  6.     (close f)
  7.     (reverse lst)
  8. )
  9.  

greets reltro

ChrisCarlson

  • Guest
Re: Draw circles from coordinates in selected text file
« Reply #2 on: August 24, 2014, 11:44:56 AM »
Does the text file change or is this a one time scenario ?

chvnprasad

  • Guest
Re: Draw circles from coordinates in selected text file
« Reply #3 on: August 28, 2014, 11:18:43 AM »
Text file content is changinh regularly, but path file location and name is constant and circle radius need to be constant (ex; 10).

reltro

  • Guest
Re: Draw circles from coordinates in selected text file
« Reply #4 on: August 28, 2014, 11:23:58 AM »
Text file content is changinh regularly, but path file location and name is constant and circle radius need to be constant (ex; 10).

If the file has changed u need to update the allready drawn circles?

ChrisCarlson

  • Guest
Re: Draw circles from coordinates in selected text file
« Reply #5 on: August 28, 2014, 11:47:07 AM »
Code - Auto/Visual Lisp: [Select]
  1. Code includes lines from http://www.cadtutor.net/forum/showthread.php?44768-Entmake-Functions
  2.  
  3. (defun c:ccoord (/ _ readfile pt01)
  4. (initget (+ 1 64))
  5. (setq rad (getdist "\nSpecify Radius: "))
  6.  (defun _readfile (filename / circles file result line)
  7.     (cond ((and (eq 'str (type filename)) (setq file (open filename "r")))
  8.            (while (setq line (read-line file)) (setq result (cons line result)))
  9.            (close file)
  10.            (reverse result)
  11.           )
  12.     )
  13.   )
  14.         (if (setq lst (_readfile "C:/Circles.txt"))
  15.                 (progn (vl-load-com)
  16.                         (foreach cen lst       
  17.                                 (entmakex
  18.                                         (list
  19.                                                 (cons 0 "CIRCLE")
  20.                                                 (cons 10 cen)
  21.                                                 (cons 40 rad)
  22.                                         ) ;end list                    
  23.                                 ); end entmakex
  24.                         ) ; end foreach
  25.                 ); end progn
  26.                 (alert "FILE NOT FOUND!")
  27.         ); end if      
  28.   (princ)
  29. ); end function

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Draw circles from coordinates in selected text file
« Reply #6 on: August 28, 2014, 01:02:32 PM »
Another:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:txt2cir ( / c f r )
  2.     (setq r '(40 . 10.0)) ;; Circle radius
  3.     (if (and (setq f (getfiled "" "" "txt" 16)) (setq f (open f "r")))
  4.         (progn
  5.             (while (setq c (read-line f))
  6.                 (setq c (read (strcat "(10 " (vl-string-translate "," " " c) ")")))
  7.                 (if (and (vl-every 'numberp c) (< 2 (length c) 5))
  8.                     (entmake (list '(0 . "CIRCLE") c r))
  9.                 )
  10.             )
  11.             (close f)
  12.         )
  13.     )
  14.     (princ)
  15. )

For a static filename, change:
Code - Auto/Visual Lisp: [Select]
  1. (setq f (getfiled "" "" "txt" 16))
To:
Code - Auto/Visual Lisp: [Select]
  1. (setq f "C:\\YourFilename.txt")

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Draw circles from coordinates in selected text file
« Reply #7 on: August 28, 2014, 01:09:08 PM »
Nice Lee  8)
Code - Auto/Visual Lisp: [Select]
  1. (setq c (read (strcat "(10 " (vl-string-translate "," " " c) ")")))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Draw circles from coordinates in selected text file
« Reply #8 on: August 28, 2014, 01:10:07 PM »
Cheers Ron - though reltro did suggest something similar earlier in the thread, so I can't take all the credit  :angel:

ChrisCarlson

  • Guest
Re: Draw circles from coordinates in selected text file
« Reply #9 on: August 28, 2014, 01:11:17 PM »
Suppose I should have tested mine before....it's entering in a bad DXF code.