export drawing titles from layouts to csv/excel - drawing list

export drawing titles from layouts to csv/excel - drawing list

HAYDENRX9APH
Contributor Contributor
1,419 Views
11 Replies
Message 1 of 12

export drawing titles from layouts to csv/excel - drawing list

HAYDENRX9APH
Contributor
Contributor

Hi all,

I am trying to write a lisp to export the layout names + drawing name (mtext at same coordinates in the paperspace - first point is x = 795, y = 41     second point in window x = 696, y = 26 ) to a csv file . this is essentially just exporting a drawing list for me.

 

I am essentially trying to modify one of leemacs from memory but am really struggling on where to next. Would be greatly appreciated if anyone could fill in the blanks or give some info.

 

 

(defun c:csvlist ( / des dim enx idx sel txt )
   (if (and (setq sel (ssget '((0 . "MTEXT"))))))
            (setq des (open (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".csv") "a"))
       )
       (progn
                   (setq lay (getvar 'ctab'))
                   (setq txt (ssget "_W" '(795 41) '(696 26))
               )
           )
           (while (or dim txt)
               (write-line
                   (strcat
                       (cond ((car  lay)) ("")) ","
                       (cond ((car  txt)) (""))
                   )
                   des
               )
               (setq txt (cdr txt)
                     lay (cdr lay)
               )
           )
       )
   )
   (if (= 'file (type des)) (close des))
   (princ)
)

 

ive got to many brackets in there somewhere which I cant locate (how can i find where the break is??? ive checked in lisp console but cant work it out)

 

thanks again

 

0 Likes
Accepted solutions (1)
1,420 Views
11 Replies
Replies (11)
Message 2 of 12

komondormrex
Mentor
Mentor
Accepted solution

check the following

 

(defun c:csvlist ( / des mtext_sset full_dwg_name)
	(setq mtext_sset (ssget "_x" (list '(0 . "mtext")
					      			   '(-4 . "<and")
						  					 '(-4 . ">,>,*") (list 10 696 26)
						  					 '(-4 . "<,<,*") (list 10 795 41)
					      			   '(-4 . "and>")
								 )
					 )
	)
   	(if (and mtext_sset
   	         (setq des (open (setq full_dwg_name (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".csv")) "a"))
   	    )
   	    (progn
   				(write-line full_dwg_name des) 
   	    		(foreach mtext (vl-remove-if 'listp (mapcar 'cadr (ssnamex mtext_sset)))
   					(write-line (strcat (cdr (assoc 410 (entget mtext))) "," (getpropertyvalue mtext "text")) des)  
   	    		)
   		)
   	)
   	(if (= 'file (type des)) (close des))
   	(princ)
)

 

 

 

 

0 Likes
Message 3 of 12

HAYDENRX9APH
Contributor
Contributor

Thanks for that - I have run it and returns -

 

Command: CSVLIST
; error: no function definition: WRITE_LINE

I have added (vl-load-com) at the start of the lisp but it didnt help

0 Likes
Message 4 of 12

komondormrex
Mentor
Mentor

oops, change it to write-line. 

0 Likes
Message 5 of 12

HAYDENRX9APH
Contributor
Contributor

thanks for that. fires up and creates the csv but errors and says ; error: no function definition: VLA-REMOVE-IF

is this because it cant find the setq of 'listp?

 

(foreach mtext (vla-remove-if 'listp (mapcar 'cadr (ssnamex mtext_sset)))
0 Likes
Message 6 of 12

komondormrex
Mentor
Mentor

nope, it's just hasty fingers... 

should read as vl-remove-if. check update in message 2.

0 Likes
Message 7 of 12

HAYDENRX9APH
Contributor
Contributor

ahh excellent thankyou!!

it write out as this {\T0.9;*drawing name*}

 

is there a way to write it without the {\t0.9} and removeing all the parentheses ?

 

I tried looking at the code and cant work out - thinking maybe it has something to do with the -4 or this bit..? are you able to explain why so i can hopefully understand too

 

(cdr (assoc 1 (entget mtext)))) des)

0 Likes
Message 8 of 12

Sea-Haven
Mentor
Mentor

It is much easier to export layout details when you use a Title block then just get the block attribute or attributes. No position needed. Use a ssget 

(setq ss (ssget "X" '((0 . "INSERT")(cons 2 "yourtitleblock")(cons 410 (getvar 'ctab)))))

 

0 Likes
Message 9 of 12

HAYDENRX9APH
Contributor
Contributor

agreed - unfortunately we do not use the drawing title as an attribute

0 Likes
Message 10 of 12

HAYDENRX9APH
Contributor
Contributor

actually - it is writing in the csv file that the text tracking width is set to 0.9!!

how to i change it to make it strictly the string and not the text width details etc

0 Likes
Message 11 of 12

komondormrex
Mentor
Mentor

yeah, it take mtext string with all formatting. check update in message 2. maybe it'll help.

0 Likes
Message 12 of 12

HAYDENRX9APH
Contributor
Contributor

great work thankyou so much..!!

0 Likes