Jump to content

coordinates.


marbenorallo

Recommended Posts

Hi All,

I am new in this forum, and I would like to ask how to

get the x,y,z coordinates of the cursor and print and

save it to a txt file by using LISP. I am using autocad 2011.

Any help is appreciated.

 

Regards,

Marbs

Link to comment
Share on other sites

?

 

(defun c:test ( / fn fo pt )
 (if
   (and
     (setq fn (getfiled "" "" "txt" 1))
     (setq fo (open fn "w"))
   )
   (progn
     (while (setq pt (getpoint "\nPick Point: "))
       (write-line (apply 'strcat (mapcar 'strcat (mapcar 'rtos (trans pt 1 0)) '("," "," ""))) fo)
     )
     (close fo) (startapp "notepad" fn)
   )
 )
 (princ)
)

Link to comment
Share on other sites

Hi Lee,

Thank you very much for the quick reply, the code is working, but how can I insert the directory in the LISP code, for example : I want to save the txt file to:

C:\Documents and Settings\Administrator\My Documents\My Coordinates

with a file name coordinates.txt , so that every time I ran the LISP program it will not ask me the file name and where will I save .

 

Thanks in advance ,

Marbs

Link to comment
Share on other sites

Hi Marbenorallo,

 

Just add the path like this:

(defun c:test (/ fn fo pt)
 (if
   (and
     (setq fn "C:\\Documents and Settings\\Administrator\\My Documents\\My Coordinates\\Coordinates.txt")
     (setq fo (open fn "w")); (make "w" --> "a" and it will append
   ) ;_and
    (progn
      (while (setq pt (getpoint "\nPick Point: "))
 (write-line (apply 'strcat (mapcar 'strcat (mapcar 'rtos (trans pt 1 0)) '("," "," ""))) fo)
      ) ;_while
      (close fo)
      (startapp "notepad" fn)
    ) ;_progn
 ) ;_if
 (princ)
) ;_defun

 

Mind the "w" wich will make the file "coordinates.txt" overwrite itself everytime you use the program.

If you change that to "a" then the existing file stays and the coordinates will be appended to the file.

 

@ Lee: hope you don't mind, I don't want to "step on your toes" (english?)

 

Would you be so kind and explain me / us this part:

(apply 'strcat (mapcar 'strcat (mapcar 'rtos (trans pt 1 0)) '("," "," 
"")))

 

Trans I can understand but twice "mapcar" in combination with al the ","...

I know you format it to string with delimeters but I need to understand the code.

Edited by MarcoW
Had a question myself
Link to comment
Share on other sites

@ Lee: hope you don't mind, I don't want to "step on your toes" (english?)

 

No worries :)

 

Would you be so kind and explain me / us this part:

(apply 'strcat (mapcar 'strcat (mapcar 'rtos (trans pt 1 0)) '("," "," 
"")))

 

Sure, here is a step-by-step of the expressions evaluated inside-out, (using an example point of (1.2 1.3 1.4) ):

 

_$ (setq pt '(1.2 1.3 1.4))
(1.2 1.3 1.4)
_$ (trans pt 1 0)
(1.2 1.3 1.4)
_$ (mapcar 'rtos (trans pt 1 0))
("1.2" "1.3" "1.4")
_$ (mapcar 'strcat (mapcar 'rtos (trans pt 1 0)) '("," "," ""))
("1.2," "1.3," "1.4")
_$ (apply 'strcat (mapcar 'strcat (mapcar 'rtos (trans pt 1 0)) '("," "," "")))
"1.2,1.3,1.4"

Hopefully this clarifies things, but let me know if you need further explanation :)

Link to comment
Share on other sites

Hi MarcoW,

The lisp code you gave is exactly what I want. Thank you very much. I have one more question regarding coordinates. How can I get the coordinates of selected lines, polylines, arc and block and print the coordinates to a txt file .

 

Regards,

Marbs

Link to comment
Share on other sites

Hi Lee,

What is the address of your site for Point Manager program ?

I want to learn LISP .

 

 

Regards,

Marbs

Link to comment
Share on other sites

Hi Lee,

The address you gave is very informative.

I can learn a lot from this site.

LISP is magic.

Thank you very much .

 

Regards,

Marbs

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...