Jump to content

Plot each layer individually


Grrr

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

  • 1 year later...

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!

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