Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
6,043 Posts
671 Kudos
Registered: ‎09-13-2004
Post 21 of 25

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
13 Posts
0 Kudos
Registered: ‎06-08-2012
Post 22 of 25

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*
6,043 Posts
671 Kudos
Registered: ‎09-13-2004
Post 23 of 25

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
13 Posts
0 Kudos
Registered: ‎06-08-2012
Post 24 of 25

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*
6,043 Posts
671 Kudos
Registered: ‎09-13-2004
Post 25 of 25

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
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!