Visual LISP, AutoLISP and General Customization
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Re: Help with exporting point locations to text file
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: Help with exporting point locations to text file
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
(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
Re: Help with exporting point locations to text file
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: Help with exporting point locations to text file
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Works Great...
thanks
Re: Help with exporting point locations to text file
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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...].


