Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with exporting point locations to text file

25 REPLIES 25
SOLVED
Reply
Message 1 of 26
Cadastrophe1911
4237 Views, 25 Replies

Help with exporting point locations to text file

Hi all... Im trying to come up with a lisp that will export x and y coords to a txt or cvs file. However, I need the lisp to export in this format

 

Units       Inch

WPT      1     0     0     ( X=0 Y=0)

WPT      2     1     1     (X=1  Y=1)

WPT      3     2     2

 

 

I need to be able to set my zero with move origin and the export the points.

 

This is for a post for a CNC Hole Popper

 

 

25 REPLIES 25
Message 21 of 26


@Cadastrophe1911 wrote:

Why am i getting this error

....:
Command: drill20
; error: bad argument type: 2D/3D point: "29.31"


Sorry about that -- the (trans) should be applied to the point before extracing coordinates, not to the extracted coordinates.  Change this:

 

      (trans (rtos (car x) 2 4) 0 1) "\t" ; X coordinate <--- edit precision
      (trans (rtos (cadr x) 2 4) 0 1); Y coordinate <--- edit precision

 

to this:

 

      (rtos (car (trans x 0 1)) 2 4) "\t" ; X coordinate

      (rtos (cadr (trans x 0 1)) 2 4); Y coordinate

Kent Cooper, AIA
Message 22 of 26

(defun C:drill20 (/ ptfile inc ptlist);
 
  (setq
  ptfile (open "C:/TEMP/PTFILE.TXT" "w"); <---- edit file path & name
  inc 0
  ptlist
    (mapcar
      '(lambda (x) (cdr (assoc 10 (entget x)))); Point locations
      (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "POINT"))))); all Point entities in drawing
    ); mapcar & ptlist
); setq
(write-line "Units\tInch" ptfile)
(foreach x ptlist
  (write-line
    (strcat
      "WPT\t"
      (itoa (setq inc (1+ inc))) "\t"
      (rtos (car (trans x 0 1)) 2 4) "\t" ; X coordinate
      (rtos (cadr (trans x 0 1)) 2 4); Y coordinate
    ); strcat
    ptfile
  )
(princ))


  (close ptfile)

); end defun

 

 

 

 

 

 

 

That works.. do i have my PRINC in the right place and format???? it still gives the nil

Message 23 of 26


@Cadastrophe1911 wrote:

(defun C:drill20 (/ ptfile inc ptlist);
....

    (mapcar
      '(lambda (x) (cdr (assoc 10 (entget x)))); Point locations
....

      (rtos (car (trans x 0 1)) 2 4) "\t" ; X coordinate
      (rtos (cadr (trans x 0 1)) 2 4); Y coordinate
....

(princ))

  (close ptfile)

); end defun 

 

That works.. do i have my PRINC in the right place and format???? it still gives the nil


The (princ) should be the last thing before the final closing right parenthesis.

 

It also occurred to me that it could be streamlined just slightly by translating each point's location from World to Current CS only once, instead of separately for each of the X & Y coordinates.  Try this:
 

(defun C:drill20 (/ ptfile inc ptlist);
  (setq
    ptfile (open "C:/TEMP/PTFILE.TXT" "w")
    inc 0
    ptlist
    (mapcar
      '(lambda (x) (trans (cdr (assoc 10 (entget x))) 0 1)); locations translated to current CS
      (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "POINT"))))); all Point entities in drawing
    ); end mapcar & ptlist
  ); end setq
  (write-line "Units\tInch" ptfile)
  (foreach x ptlist
    (write-line
      (strcat
        "WPT\t" ; WPT + tab
        (itoa (setq inc (1+ inc))) "\t" ; sequence number + tab
        (rtos (car x) 2 4) "\t" ; X coordinate + tab
        (rtos (cadr x) 2 4); Y coordinate
      ); end strcat
      ptfile
    ); end write-line
  ); end foreach

  (close ptfile)

  (princ)

); end defun

Kent Cooper, AIA
Message 24 of 26

Works Great...Smiley Very Happy thanks

Message 25 of 26


@Cadastrophe1911 wrote:

Works Great... thanks



You're welcome.  I also learned something I didn't know from this exercise:  it probably wouldn't even have occurred to me to wonder before whether the code for a Tab character in a text string in a .DWG file would translate correctly into a Tab in a .TXT file.  So I had to try it out, and now I know that it does [though whether I'll ever have further use for that information is another question...].

Kent Cooper, AIA
Message 26 of 26
mihai_bantas
in reply to: Kent1Cooper

Hello ,

What do i want to ask ... can you change the code in this way, without numbering WPT 1,2,3...

 

MYTEXT A, 1.00, 2.00, MYTEXT Z    ( where X =1.00 and Y=2.00, are coordinates of selected point)

MYTEXT NEW, 4.00, 5.00, MYTEXT OLD

MYTEXT RED, 6.00, 8.00, MYTEXT GREEN

MYTEXT GOOD, 10.00, 12.00, MYTEXT BAD

 

I HAVE TO SELECT MANUAL ONLY FOUR POINTS.....BUT MUST ADD MY VALUES (in the selected order of points) BEFORE AND AFTER THE COORDINATE OF THE SELECTED POINT.

 

Thank you in advance for the time spent on this problem that has been giving me headaches for some time.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost