marbenorallo Posted May 19, 2011 Share Posted May 19, 2011 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 Quote Link to comment Share on other sites More sharing options...
alanjt Posted May 19, 2011 Share Posted May 19, 2011 getpoint or grread Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 19, 2011 Share Posted May 19, 2011 ? (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) ) Quote Link to comment Share on other sites More sharing options...
Nardino Posted May 19, 2011 Share Posted May 19, 2011 Lee Mac I am amazed and impressed on how fast you can come up with these lisp files. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 19, 2011 Share Posted May 19, 2011 I've had too much practice... Thanks mate Quote Link to comment Share on other sites More sharing options...
marbenorallo Posted May 20, 2011 Author Share Posted May 20, 2011 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 Quote Link to comment Share on other sites More sharing options...
MarcoW Posted May 20, 2011 Share Posted May 20, 2011 (edited) 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 May 20, 2011 by MarcoW Had a question myself Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 20, 2011 Share Posted May 20, 2011 @ 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 Quote Link to comment Share on other sites More sharing options...
marbenorallo Posted May 20, 2011 Author Share Posted May 20, 2011 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 20, 2011 Share Posted May 20, 2011 Hi Marbs, Search my site for my 'Point Manager' program, it will do (most of) what you want. Lee Quote Link to comment Share on other sites More sharing options...
marbenorallo Posted May 20, 2011 Author Share Posted May 20, 2011 Hi Lee, What is the address of your site for Point Manager program ? I want to learn LISP . Regards, Marbs Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 20, 2011 Share Posted May 20, 2011 Hi Lee, What is the address of your site for Point Manager program ? I want to learn LISP . Regards, Marbs Here it is . http://lee-mac.com/ptmanager.html Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 20, 2011 Share Posted May 20, 2011 Hi Lee, What is the address of your site for Point Manager program ? I want to learn LISP . Oops! Sorry about that : http://lee-mac.com/ptmanager.html Thanks Tharwat Quote Link to comment Share on other sites More sharing options...
marbenorallo Posted May 20, 2011 Author Share Posted May 20, 2011 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 20, 2011 Share Posted May 20, 2011 You're welcome Marbs, enjoy my site Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.