• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Visual LISP, AutoLISP and General Customization

    Reply
    *Expert Elite*
    Kent1Cooper
    Posts: 4,078
    Registered: ‎09-13-2004

    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
    Please use plain text.
    Contributor
    Posts: 13
    Registered: ‎06-08-2012

    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

    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,078
    Registered: ‎09-13-2004

    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
    Please use plain text.
    Contributor
    Posts: 13
    Registered: ‎06-08-2012

    Re: Help with exporting point locations to text file

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

    Works Great...:smileyvery-happy: thanks

    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,078
    Registered: ‎09-13-2004

    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
    Please use plain text.