mcad_m Posted October 29, 2015 Share Posted October 29, 2015 Dear all, I am new user of this forum. I have download a autolisp to generate CSV file by selecting text in a sequence. It was working earlier fine. But after formatting my pc it gives an error. Pls help any one. (defun c:Csv-S() (setq r1(ssget)) (setq p1(ssget "p" (list (cons 0 "TEXT")))) (setq f(open "c:\\code.csv" "w")) (setq m1 1) (setq ind 0) (repeat (sslength p1) (setq r3(ssname p1 ind)) (setq p2(entget r3)) (setq p3(cdr (assoc 11 p2))) (setq s1(cdr (assoc 1 p2))) (setq x(rtos(car p3) 2 4)) (setq y(rtos(cadr p3) 2 4)) (setq z(rtos(caddr p3))) (setq m11(itoa m1)) (setq L1(strcat S1 "," x "," y "," s1 "," "F")) (write-line L1 f) (setq ind(+ 1 ind)) (setq m1(+ 1 ind))) (close f) (alert "Hi -CODE.txt- is Exported in C drive \n Please Open in Excel") (princ)) CSV-IN.LSP Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted October 29, 2015 Share Posted October 29, 2015 (edited) Try This :- (defun c:test (/ a f i obj pnt) (if (setq a (ssget '((0 . "text")))) (progn (setq f (open "c:\\code.csv" "w")) (repeat (setq i (sslength a)) (setq obj (entget (ssname a (setq i (1- i))))) (setq pnt (cdr (assoc 11 obj))) (write-line (strcat (cdr (assoc 1 obj)) "," (rtos (car pnt) 2 3) "," (rtos (cadr pnt) 2 3) "," (rtos (caddr pnt) 2 3) "," "F" ) f ) ) (close f) (alert "Hi -CODE.txt- is Exported in C drive \n Please Open in Excel" ) ) ) (princ) ) Edited October 30, 2015 by satishrajdev Quote Link to comment Share on other sites More sharing options...
mcad_m Posted October 30, 2015 Author Share Posted October 30, 2015 Thanks for replying but still it is not working. Quote Link to comment Share on other sites More sharing options...
tombu Posted October 30, 2015 Share Posted October 30, 2015 Thanks for replying but still it is not working. How is it not working? Does it load? Does it run? Does it create the file? Did code.txt already exist before it was run? Post what it return to the command line error or otherwise. A link to where you downloaded the file would be useful. satishrajdev's code is a lot cleaner than yours, but without any prompts or comments it's hard to know what you're expecting the code to do. Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted October 30, 2015 Share Posted October 30, 2015 Sorry, By mistake i put "f:\\code.csv" instead of "c:\\code.csv" as per my settings and forgot to replace that I have updated the code check now. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 30, 2015 Share Posted October 30, 2015 With a few tweaks (untested): (defun c:test ( / csv des enx idx sel ) (setq csv "C:\\code.csv") ;; CSV to be created (will be overwritten if exists) (if (setq sel (ssget '((0 . "TEXT")))) (if (setq des (open csv "w")) (progn (repeat (setq idx (sslength sel)) (setq enx (entget (ssname sel (setq idx (1- idx))))) (write-line (strcat (cdr (assoc 1 enx)) "," (apply 'strcat (mapcar '(lambda ( x y ) (strcat (rtos x 2 3) y)) (cdr (assoc (if (= 0 (cdr (assoc 72 enx)) (cdr (assoc 73 enx))) 10 11) enx)) '("," "," ",F") ) ) ) des ) ) (close des) ) (princ (strcat "\nUnable to open \"" csv "\" for writing.")) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
mcad_m Posted October 30, 2015 Author Share Posted October 30, 2015 Now it is working well. Thanks for help. Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted October 30, 2015 Share Posted October 30, 2015 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.