Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
Kent1Cooper
Posts: 5,868
Registered: ‎09-13-2004
Message 21 of 25 (195 Views)

Re: Help with exporting point locations to text file

06-11-2012 02:54 PM in reply to: Cadastrophe1911

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
Contributor
Cadastrophe1911
Posts: 13
Registered: ‎06-08-2012
Message 22 of 25 (191 Views)

Re: Help with exporting point locations to text file

06-11-2012 03:13 PM in reply to: Kent1Cooper

(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

*Expert Elite*
Kent1Cooper
Posts: 5,868
Registered: ‎09-13-2004
Message 23 of 25 (177 Views)

Re: Help with exporting point locations to text file

06-12-2012 07:23 AM in reply to: Cadastrophe1911

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
Contributor
Cadastrophe1911
Posts: 13
Registered: ‎06-08-2012
Message 24 of 25 (172 Views)

Re: Help with exporting point locations to text file

06-12-2012 08:34 AM in reply to: Kent1Cooper

Works Great...:smileyvery-happy: thanks

*Expert Elite*
Kent1Cooper
Posts: 5,868
Registered: ‎09-13-2004
Message 25 of 25 (167 Views)

Re: Help with exporting point locations to text file

06-12-2012 09:13 AM in reply to: Cadastrophe1911

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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.