kam1967 Posted November 29, 2010 Posted November 29, 2010 (edited) Hi. I am trying to extra layer data, including the lineweight onto an excel format. I added the lineweight information into the lisp routine, but I am definitely doing something wrong, as it continues to give me an error. Thank you in advance! Here is the routine that was modified to include the lineweight.. (defun c:LA2EXCEL (/ nm lnm llnm nam name opf ln lname color ltype lna lnamea colora ltypea,line_wt,description) ; ;I added line_wt in the line above ; (setq nm (getvar "dwgname")) (setq lnm (strlen nm)) (setq llnm (- lnm 3)) ;(setq lay_alst (entget (tblobjname "LAYER" "LAYER-NAME"))) ;(setq line_wt (cdr (assoc 370 lay_alst))) (setq lay_alst (entget (tblobjname "LAYER" "LAYER-NAME"))) ; ;I added this line below (setq line_wt (cdr (assoc 370 lay_alst))) ;I added this line above ; (setq nam (substr nm 1 llnm)) (setq name (strcat nam "csv")) (setq opf (open name "w")) (setq ln (tblnext "layer" T)) (setq lname (cdr (assoc 2 ln))) (setq color (cdr (assoc 62 ln))) (setq ltype (cdr (assoc 6 ln))) (setq stat (cdr (assoc 70 ln))) (cond ((= stat 1)(setq state "FROZEN")) ((= stat 2)(setq state "FROZEN IN NEW VPORT")) ((= stat 4)(setq state "LOCKED")) ((< color 0)(setq state "OFF")) ((>= color 0)(setq state "ON")) ) (write-line "Layer Name,Color,Linetype,Condition,Line_wt,Description" opf) (write-line (strcat lname "," (rtos (abs color) 2 0) "," ltype "," state) opf) (while (setq lna (tblnext "layer")) (setq lnamea (cdr (assoc 2 lna))) (setq colora (cdr (assoc 62 lna))) (setq ltypea (cdr (assoc 6 lna))) (setq stata (cdr (assoc 70 lna))) (cond ((= stata 1)(setq statea "FROZEN")) ((= stata 2)(setq statea "FROZEN IN NEW VPORT")) ((= stata 4)(setq statea "LOCKED")) ((< colora 0)(setq statea "OFF")) ((>= colora 0)(setq statea "ON")) ) (write-line (strcat lnamea "," (rtos (abs colora) 2 0) "," ltypea "," statea) opf) ) (close opf) (alert (strcat "File " name " created in current folder")) (princ) ) hanks! Edited November 30, 2010 by kam1967 Format code - added line_wt and layer description Quote
The Buzzard Posted November 29, 2010 Posted November 29, 2010 kam1967, Welcome to the forum. Could you please edit your post and use code tags. See here: http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines Quote
Lee Mac Posted November 29, 2010 Posted November 29, 2010 (edited) Quickly hacked together, but should work: (defun c:LayerInfo ( / GetLayerState dxf f l w ) ;; © Lee Mac 2010 (defun GetLayerState ( bit colour ) ( (lambda ( s ) (setq s (strcat s (apply 'strcat (mapcar '(lambda ( b s ) (if (= b (logand bit b)) s "")) '(1 2 4) '("FROZEN;" "FROZEN IN NEW VPORT;" "LOCKED;") ) ) ) ) (substr s 1 (1- (strlen s))) ) (if (minusp colour) "OFF;" "ON;") ) ) (setq dxf (lambda ( x l ) (cdr (assoc x l)))) (if (setq f (open (strcat (getvar 'DWGPREFIX) (cadr (fnsplitl (getvar 'DWGNAME))) ".csv") "a")) (progn (write-line "Layer Name,Color,Linetype,Lineweight,Status" f) (while (setq l (tblnext "LAYER" (null l))) (setq l (entget (tblobjname "LAYER" (dxf 2 l)))) (write-line (strcat (dxf 2 l) "," (itoa (abs (dxf 62 l))) "," (dxf 6 l) "," (if (minusp (setq w (/ (dxf 370 l) 100.))) "DEFAULT" (rtos w 2 2)) "," (GetLayerState (dxf 70 l) (dxf 62 l)) ) f ) ) (close f) (princ "\n--> Layer Info Written <--") ) (princ "\n** Error Opening File **") ) (princ) ) Writes file in same location as drawing. Edited November 29, 2010 by Lee Mac Quote
Lee Mac Posted November 29, 2010 Posted November 29, 2010 You might also be interested in this. Quote
kam1967 Posted November 29, 2010 Author Posted November 29, 2010 (edited) Thank you, Lee Mac for your quick reply. In testing the routine you've just provided, it seem to have generated the layers 4 different times. For instance, if I have 15 layers, it generated 60 layers. The lineweights for the first 45 lines are "default". Only the last 15 layers have the lineweight information. It's probably not a problem, but when you have 500 layers or more, it might be difficult to track. Anyhow, I need to expand this program to include other layer information (see layer info needed.jpg file). Here is what I need help with... 1) This current program does not extract out the lineweight and the layer description. If at all, I'd like to be able to extract out the entire layer information - including the vp layer info (see attached file) 2) If you know of a program or routine to import all that information back into Autocad, that would be awesome! I know it's a lot to ask and you're probably really busy. Hopefully you'll be able to work on the first part this week. I would be happy just to get #1 done, actually. Thanks again Lee! [ATTACH]24881[/ATTACH] Edited November 30, 2010 by kam1967 Additional programming request and adjustment to suggested routine Quote
Lee Mac Posted November 29, 2010 Posted November 29, 2010 I'm not sure whether I did it right - but I highlighted the texts and hit the quote button. If it's still wrong, please advise. Thanks. Use the 'code' button to format code, the 'quote' button to quote posts Quote
kam1967 Posted November 30, 2010 Author Posted November 30, 2010 Lee Mac - I wonder if you could read the last post. I would like to also extract the layer description. If you can help, that would be great. Thanks again. Quote
Lee Mac Posted November 30, 2010 Posted November 30, 2010 Lee Mac - I wonder if you could read the last post. I would like to also extract the layer description. If you can help, that would be great. Thanks again. Will do - I'll see what I can do when I get a minute later today Quote
Lee Mac Posted December 1, 2010 Posted December 1, 2010 Hi Kam1967, This program should suit your needs http://www.cadtutor.net/forum/showthread.php?54830-Layer-Extractor 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.