Grrr Posted January 24, 2016 Posted January 24, 2016 Hello, I'm looking for a lisp routine that will plot each layer in a layout named "Plan1", so for N visible layers in the layout, would be created N plot files (each plot file containing only one individual layer). My goal is later to merge some of these and use them in photoshop. Quote
Tharwat Posted January 24, 2016 Posted January 24, 2016 Hello, Can you give more details about your aim pf the program ? Quote
Grrr Posted January 24, 2016 Author Posted January 24, 2016 Hi Tharwat, At the moment I'm using something like this: (setq curTAB (getvar CTAB) (setvar CTAB "Plan1") (command "-layer" "off" "*" "Y" "") (command "-layer" "on" "LAYER1,LAYER2" "") ;;;;PLOTS SPECIFIED LAYERS (COMMAND "-PLOT" "N" "" "" "" "" "N" "Y") (command "-layer" "on" "*" "") (setvar CTAB curTAB) But I don't know how to repeat this process for each layer (turn all layers off, perform plot with one layer on and do this for the next in the layerstable). Perhaps it would be nice to get the layer's plot state at first (if its "off" or "not-plotable") to skip it, so spare (empty) plot files would be avoided. Quote
Tharwat Posted January 24, 2016 Posted January 24, 2016 This should give you a push (setq lay (getvar 'CTAB)) (foreach layout (layoutlist) (setvar 'CTAB layout) (while (setq item (tblnext "LAYER" (null item))) (setq eng (entget (tblobjname "LAYER" (cdr (assoc 2 item))))) (cond ((minusp (cdr (assoc 62 eng)));; = off ;; do something ) ((eq 1 (cdr (assoc 290 eng))) ;; = Not to plot ;; do something here ) ) ) ) (setvar 'CTAB lay) Quote
Tharwat Posted January 24, 2016 Posted January 24, 2016 Grrr said: Thank you, Tharwat! Best of luck. Quote
Grrr Posted January 25, 2016 Author Posted January 25, 2016 Well, I'm stuck with this: (defun C:test (/ lay item eng fnm) (setq lay (getvar 'CTAB)) (foreach layout (layoutlist) (setvar 'CTAB layout) (while (setq item (tblnext "LAYER" (null item))) (setq eng (entget (tblobjname "LAYER" (cdr (assoc 2 item))))) (cond ((minusp (cdr (assoc 62 eng)));; = off (princ "\nThis layer is off") ;; do something ) ((eq 1 (cdr (assoc 290 eng))) ;; = Not to plot (princ "\nThis layer is not plottable") ;; do something here ) ) (command "-layer" "off" "*" "Y" "") (command "-layer" "on" eng "") ;;;;PLOTS SPECIFIED LAYERS (COMMAND "_.PLOT" "_N" "" "" "" (if (= "" (setq fnm (getstring t "\nNAME OF THE FILE <ASD>:"))) "ASD" fnm) "_N" "_Y") (command "-layer" "on" "*" "") ) ) (setvar 'CTAB lay) (princ) ) I can't find a way to incorporate these rows: (command "-layer" "off" "*" "Y" "") (command "-layer" "on" eng "") ;;;;PLOTS SPECIFIED LAYERS So now the routine turns off all layers and performs plot for each layer (without turning it on). Quote
Tharwat Posted January 25, 2016 Posted January 25, 2016 Hi, I am really did not test the codes due to the command plot , so I hope it would meet your needs Let me know how you get on with the program. (defun c:Test (/ *error* c l lst lay item eng fnm) ;; Tharwat 25.01.2016 ;; (defun *error* (msg) (if lst (foreach x lst (entmod (append (entget (tblobjname "LAYER" (car x))) (list (cadr x) (caddr x)) ) ) ) ) (if lay (setvar 'ctab lay) ) (if (and msg (not (wcmatch msg "*CANCEL*,*EXIT*,*BREAK*"))) (princ (strcat "\n ** Error : " msg " **")) ) (princ) ) (while (setq item (tblnext "LAYER" (null item))) (setq eng (entget (tblobjname "LAYER" (cdr (assoc 2 item)))) lst (cons (list (cdr (assoc 2 item)) (assoc 62 item) (assoc 290 eng)) lst ) ) (if (/= (cdr (assoc 2 l)) "DefPoints") (entmod (append eng (list (cons 290 1) (cons 62 (if (minusp (setq c (cdr (assoc 62 item)))) (- c) c ) ) ) ) ) ) ) (setq lay (getvar 'ctab)) (foreach layout (layoutlist) (setvar 'ctab layout) (while (setq l (tblnext "LAYER" (null l))) (setq eng (entget (tblobjname "LAYER" (cdr (assoc 2 l))))) (if (/= (cdr (assoc 2 l)) "DefPoints") (progn (command "_.-layer" "off" "*" "Y" "") (command "_.PLOT" "_N" "" "" "" (if (= "" (setq fnm (getstring t "\nNAME OF THE FILE <ASD>:")) ) "ASD" fnm ) "_N" "_Y" ) (command "-layer" "on" "*" "") ) ) ) ) (setvar 'ctab lay) (*error* nil) (princ) ) Quote
Grrr Posted January 25, 2016 Author Posted January 25, 2016 Thank you for the help Tharwat! But I still got this problem: The routine turns off all layers and performs plot for each layer (without turning it on), and for each layout. If this helps for the code to be easier: I don't really need it to plot for each layout (only one specified is enough). You can include all layers from the layers table - there might be a problem with the closed circuit between (cond ((minusp (cdr (assoc 62 eng)));; = off and (command "_.-layer" "off" "*" "Y" "") The main goal is to get the lines on every layer on different .pdf file. Quote
Tharwat Posted January 26, 2016 Posted January 26, 2016 Something like this? NOTE: change the name of the layout in the program as per your needs. (defun c:test (/ *error* _layout c l lst lay item eng fnm vars) ;; Tharwat 25.01.2016 ;; (setq _layout [color=magenta]"Plan1"[/color])[color=red];; <- name of layout[/color] (defun *error* (msg) (if lst (foreach x lst (entmod (append (entget (tblobjname "LAYER" (car x))) (list (cadr x) (caddr x)) ) ) ) ) (if vars (mapcar 'setvar '(ctab cmdecho clayer) vars) ) (if (and msg (not (wcmatch msg "*CANCEL*,*EXIT*,*BREAK*"))) (princ (strcat "\n ** Error : " msg " **")) ) (princ) ) (if (member _layout (layoutlist)) (progn (while (setq item (tblnext "LAYER" (null item))) (setq eng (entget (tblobjname "LAYER" (cdr (assoc 2 item)))) lst (cons (list (cdr (assoc 2 item)) (assoc 62 item) (assoc 290 eng) ) lst ) ) (if (/= (cdr (assoc 2 l)) "DefPoints") (entmod (append eng (list (cons 290 1) (cons 62 (if (minusp (setq c (cdr (assoc 62 item)))) (- c) c ) ) ) ) ) ) ) (setq vars (mapcar 'getvar '(ctab cmdecho clayer))) (mapcar 'setvar '(ctab cmdecho) (list _layout 0)) (setq l nil) (while (setq l (tblnext "LAYER" (null l))) (setq eng (entget (tblobjname "LAYER" (cdr (assoc 2 l))))) (if (/= (cdr (assoc 2 l)) "DefPoints") (progn (command "_.-layer" "off" "*" "N" "") (entmod (append eng (list (cons 290 1) (cons 62 (if (minusp (setq c (cdr (assoc 62 l)))) (- c) c ) ) ) ) ) (setvar 'clayer (cdr (assoc 2 l))) (command "_.PLOT" "_N" "" "" "" (if (= "" (setq fnm (getstring t "\nNAME OF THE FILE <ASD>:")) ) "ASD" fnm ) "_N" "_Y" ) (command "_.-layer" "on" "*" "") ) ) ) ) (princ (strcat "\nLayout < " _layout " > is not found in drawing !" ) ) ) (*error* nil) (princ) ) Quote
Grrr Posted January 26, 2016 Author Posted January 26, 2016 Tharwat, its almost there! Now your routine plots 2 layers per file (the one to be plotted and the previous layer), Like this: File 1: Layer1 File 1: Layer2, Layer3 File 2: Layer3, Layer4 File 3: Layer4, Layer5 File 4: Layer5, Layer6 ..... File N: Layer(N-1), LayerN Would it be possible to turn off the previous layer from the list ? So it would become 1 layer per file: File 1: Layer1 File 2: Layer2 ... File N: LayerN or File N: LayerN±1 ; doesn't matter the numeration, as long theres [b]1 layer for 1 file[/b] Quote
Tharwat Posted January 26, 2016 Posted January 26, 2016 My last program should print each layer that is in a drawing via iterating through the Layer Table , so if you want to pass over specific layer(s) that would be something else. Quote
Grrr Posted January 26, 2016 Author Posted January 26, 2016 test.dwgFetching info... Yes I agree, But if you test it, you will see that 2 layers stay on instead of 1 - so each created file contains 2 layers. Quote
Tharwat Posted January 26, 2016 Posted January 26, 2016 Now it is clear to me with that sample drawing , so just replace the "N" with "Y" in the following command call and try again. Sorry for the confusion. (command "_.-layer" "off" "*" [color=magenta]"N"[/color] "") Quote
Grrr Posted January 26, 2016 Author Posted January 26, 2016 Tharwat, Thank you for the effort you put for this one! This routine would be useful for anyone that transitions from AutoCAD to Photoshop, since PS cannot read PDF's layers and therefore multiple PDF's from ACAD need to be created so they would become individual layers in PS ! Quote
Tharwat Posted January 26, 2016 Posted January 26, 2016 You're welcome and good luck with your work. Quote
Aleks KR Posted June 30, 2017 Posted June 30, 2017 Hello. Really good thing you have done here. Very happy to find it and very sad that I can not make it to work correctly (. The program is working, but make all layers in one file. It is asking about the file names, but does not make them. Also if to leave the first row in the code, then the program does not start. Very need such program for work. Could you assist or give some advise? Thank you! Quote
Joakin1 Posted October 18, 2024 Posted October 18, 2024 I couldn't get the lisp to run.. it gives me the following error : ; error: syntax error PLOT-EACH-LAYER-mod.lspFetching info... 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.