Lee Mac Posted May 27, 2009 Posted May 27, 2009 Could you perhaps post the text file you are using? Quote
SSA Posted May 28, 2009 Author Posted May 28, 2009 this is my text format, as in x y r 10 10 1 20 20 2 30 30 3 40 40 4 thanks Quote
Lee Mac Posted May 28, 2009 Posted May 28, 2009 this is my text format, as in x y r 10 10 1 20 20 2 30 30 3 40 40 4 thanks Are they separated by spaces or tabs? I say this, as, if you have copied it straight from Excel, they will be most likely separated by "tabs" and not "spaces". If it is indeed Tabs, then my LISP in #14 should work. Quote
SSA Posted May 28, 2009 Author Posted May 28, 2009 If you have copied the contents of the Excel file straight into a txt file, and the format of the data in the Excel file is: x y r as you previously mentioned, then this may work: (defun c:CirMake (/ *error* vlst ovar file nl lst) (vl-load-com) (defun *error* (msg) (if ovar (mapcar 'setvar vlst ovar)) (if (not (member msg '("Function cancelled" "quit / exit abort"))) (princ (strcat "\n<< Error: " msg " >>"))) (princ)) (setq vlst '("CMDECHO" "OSMODE") ovar (mapcar 'getvar vlst)) (mapcar 'setvar vlst '(0 0)) (if (setq file (getfiled "Select Text File to Read" "" "txt" ) (progn (setq file (open file "r")) (while (setq nl (read-line file)) (setq lst (StrBrk nl 9)) (command "_.circle" (list (distof (car lst)) (distof (cadr lst)) 0.0) (caddr lst))) (close file)) (princ "\n<!> No File Selected <!>")) (princ)) (defun StrBrk (str chrc / pos lst) (while (setq pos (vl-string-position chrc str)) (setq lst (cons (substr str 1 pos) lst) str (substr str (+ pos 2)))) (reverse (cons str lst))) ok. I've copied exactly from excel and yes it's separated by tab. When I load the file, this is how it looks like : _APPLOAD Loading C:\Auto Files trial\CirMake.lsp : STRBRK is it supposed to be like that? what should I save the text file name as? Thanks Quote
Lee Mac Posted May 28, 2009 Posted May 28, 2009 Hmm... it loads fine for me It doesn't matter what the text file is named as - as the user will select this. What are you typing to invoke the command? Quote
SSA Posted May 28, 2009 Author Posted May 28, 2009 I went to tools, load lisp or SDS application, add file, and load what does this mean? : _APPLOAD Loading C:\Auto Files trial\CirMake.lsp : STRBRK Thanks Quote
Lee Mac Posted May 28, 2009 Posted May 28, 2009 I'm not sure... are you sure that you have copied the whole thing? Try this (I have added another line to the error handler): (defun c:CirMake (/ *error* vlst ovar file nl lst) (vl-load-com) (defun *error* (msg) (if ovar (mapcar 'setvar vlst ovar)) (if (not (member msg '("Function cancelled" "quit / exit abort"))) (princ (strcat "\n<< Error: " msg " >>")) (princ "\n<< Function Cancelled >>")) (princ)) (setq vlst '("CMDECHO" "OSMODE") ovar (mapcar 'getvar vlst)) (mapcar 'setvar vlst '(0 0)) (if (setq file (getfiled "Select Text File to Read" "" "txt" ) (progn (setq file (open file "r")) (while (setq nl (read-line file)) (setq lst (StrBrk nl 9)) (command "_.circle" (list (distof (car lst)) (distof (cadr lst)) 0.0) (caddr lst))) (close file)) (princ "\n<!> No File Selected <!>")) (princ)) (defun StrBrk (str chrc / pos lst) (while (setq pos (vl-string-position chrc str)) (setq lst (cons (substr str 1 pos) lst) str (substr str (+ pos 2)))) (reverse (cons str lst))) Quote
SSA Posted May 28, 2009 Author Posted May 28, 2009 Lee Mac, I see what's the problem is. I'm using intelliCAD, maybe it's not compatible (I found that usually commands in autoCAD works in intelliCAD) I just tried it in autoCAD and it works!! Sorry I confused you. One thing, do you know how to put each circle in a different layer? Quote
Lee Mac Posted May 28, 2009 Posted May 28, 2009 Lee Mac, I see what's the problem is. I'm using intelliCAD, maybe it's not compatible (I found that usually commands in autoCAD works in intelliCAD) I just tried it in autoCAD and it works!! Sorry I confused you. One thing, do you know how to put each circle in a different layer? Ahh... I hadn't thought of compatibility issues - its great that it works though! I shall post a subsequent code to put each circle on a new layer Quote
Lee Mac Posted May 28, 2009 Posted May 28, 2009 Perhaps this? [untested] (defun c:CirMake (/ *error* lay vlst ovar cnt file nl lst) (vl-load-com) (defun *error* (msg) (if ovar (mapcar 'setvar vlst ovar)) (if (not (member msg '("Function cancelled" "quit / exit abort"))) (princ (strcat "\n<< Error: " msg " >>")) (princ "\n<< Function Cancelled >>")) (princ)) (setq lay (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)))) (setq vlst '("CLAYER" "CMDECHO" "OSMODE") ovar (mapcar 'getvar vlst) cnt 1.) (mapcar 'setvar (cdr vlst) '(0 0)) (if (setq file (getfiled "Select Text File to Read" "" "txt" ) (progn (setq file (open file "r")) (while (setq nl (read-line file)) (setq lst (StrBrk nl 9)) (vla-add lay (strcat "Circ-" (rtos cnt 2 0))) (setvar "CLAYER" (strcat "Circ-" (rtos cnt 2 0))) (command "_.circle" (list (distof (car lst)) (distof (cadr lst)) 0.0) (caddr lst)) (setq cnt (1+ cnt))) (close file)) (princ "\n<!> No File Selected <!>")) (princ)) (defun StrBrk (str chrc / pos lst) (while (setq pos (vl-string-position chrc str)) (setq lst (cons (substr str 1 pos) lst) str (substr str (+ pos 2)))) (reverse (cons str lst))) Quote
SSA Posted May 28, 2009 Author Posted May 28, 2009 You're a genius!! It works!! Thank you so much!! by the way.. I'm trying to understand the code (I'm still learning and not planning to blindly use the code as a black box). what's the best way to understand this? Do you mind explaining it to me? Thanks Quote
Lee Mac Posted May 28, 2009 Posted May 28, 2009 Thanks, I'm glad we finally got there If you already have some idea about the structure of LISP programs, i.e. how they are defined, how to set variables etc (most of this you can get from tutorial sites), then I think the best way to understand code is to break it down and dissect it, step by step - as if you are evaluating it in much the same way as a computer would. So, I would first copy this into the Visual LISP Editor in ACAD (VLIDE at command line, File> New File, then paste), you will see the colour coded functions. Then, when stepping through the program, if there is a function you do not understand, double click on it and click on the help icon to bring up the help file on it. I could also comment each line of the code for you to help you understand things better. Lee Quote
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.