Jump to content

Help required


mcad_m

Recommended Posts

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

Link to comment
Share on other sites

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 by satishrajdev
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
)

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...