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

How do i record my insertionpoint to a txt file?

3 REPLIES 3
Reply
Message 1 of 4
The_Caddie
351 Views, 3 Replies

How do i record my insertionpoint to a txt file?

 

defun C:PNT2FILE()


      (if(setq f(open "C:/test.txt" "w"))

       (write-line (getpoint "\nChoose Inspoint: ") f))

(close f)
)

 

Above is my code as is now however it fails to record to the textfile could somboy elaborate

 

3 REPLIES 3
Message 2 of 4
pbejse
in reply to: The_Caddie

 

(defun c:CNT2FILE (/ f pt)
  (cond
    ((and
       (setq f (open "C:/test.txt" "w"))
       (setq pt (getpoint "\nPick point:"))
       (write-line (vl-string-trim "()" (vl-prin1-to-string pt)) f))))
  (close f))

 

 if you want mulitple points and

 

(defun c:CNT2FILE  (/ f pt p2)
  (cond
    ((and
       (setq f (open "C:/test2.txt" "w"))
       (setq pt (getpoint "\nPick point:"))
       (while (setq
                pt2 (getpoint pt "\nChoose Inspoint: ")
                pt  pt2)
    
           (write-line
             (vl-string-trim "()" (vl-prin1-to-string pt2))
           f)
         )))
    )
  (close f))

 

Message 3 of 4
Kent1Cooper
in reply to: The_Caddie


@The_Caddie wrote:

 

defun C:PNT2FILE()
      (if(setq f(open "C:/test.txt" "w"))
       (write-line (getpoint "\nChoose Inspoint: ") f))
(close f)
)

Above is my code as is now however it fails to record to the textfile could somboy elaborate


The (write-line) function wants a text string to send, so it doesn't like a point list.  If you don't mind having the parentheses included, you can simply change (write-line) to (princ), which has a send-it-to-a-file option, and doesn't require what you send to be a text string, so there's no conversion needed:

 
(defun C:PNT2FILE()
  (if (setq f (open "C:/test.txt" "w"))
     (princ (getpoint "\nChoose Inspoint: ") f)

  )
  (close f)
)

Kent Cooper, AIA
Message 4 of 4
pbejse
in reply to: Kent1Cooper


@Kent1Cooper wrote:
If you don't mind having the parentheses included, ..

Hence the conversion  Smiley Happy

 

But you are so right about  "princ" (send ot a file option)

 

Thank you for that Kent

 

 

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

Post to forums  

Autodesk Design & Make Report

”Boost