DrawOrder lisp Routine

DrawOrder lisp Routine

nbawden
Advocate Advocate
12,819 Views
10 Replies
Message 1 of 11

DrawOrder lisp Routine

nbawden
Advocate
Advocate

I found the following lisp routine over on the AUGI forums which was created by user alanjt

 

(defun c:Test (/ layerList data ss)
  (foreach layer '("Water" "Gas" "Electric" "Text" "Dimensions")
    (if (and (setq data (tblsearch "LAYER" layer)) ; layer exists
             (zerop (logand 4 (cdr (assoc 70 data)))) ; layer unlocked
             (setq ss (ssget "_X" (list (cons 8 layer)))) ; layer has objects
        )
      (command "_.draworder" ss "" "_front")
    )
  )
  (princ)
)

After looking around this lisp is almost exactly what I am after - except for one thing.

I would really like to be able to set all of the the specified layers to have their Draw Order below another specified layer.

Could any lisp gurus help out with this tweak?

0 Likes
Accepted solutions (2)
12,820 Views
10 Replies
Replies (10)
Message 2 of 11

ВeekeeCZ
Consultant
Consultant
Accepted solution
(defun c:Test (/ data ss en sr)
  (if (and (setq en (car (entsel "\nSelect object on reference layer: ")))
           (setq sr (ssget "_X" (list (assoc 8 (entget en))))))
    (foreach layer '("Water" "Gas" "Electric" "Text" "Dimensions")
      (if (and (setq data (tblsearch "LAYER" layer)) ; layer exists
               (zerop (logand 4 (cdr (assoc 70 data)))) ; layer unlocked
               (setq ss (ssget "_X" (list (cons 8 layer)))) ; layer has objects
               )
        (command "_.draworder" ss "" "_u" sr ""))))
  (princ)
)
Message 3 of 11

nbawden
Advocate
Advocate

Thanks - this lisp works - but out of interest how would I tweak this lisp so that the layer being set in front of the others is fixed (hard coded) and not user selected?

0 Likes
Message 4 of 11

ВeekeeCZ
Consultant
Consultant
Accepted solution

@nbawden wrote:

Thanks - this lisp works - but out of interest how would I tweak this lisp so that the layer being set in front of the others is fixed (hard coded) and not user selected?


I've simplified the code a little bit for you...

 

(defun c:Test (/ ss sr)
  (if (and (setq ss (ssget "_A" (list '(8 . "Water,Gas,Electric,Text,Dimensions") 	(cons 410 (getvar 'ctab)))))
           (setq sr (ssget "_A" (list '(8 . "ReferenceLayer1,ReferenceLayer2")		(cons 410 (getvar 'ctab)))))
           )
    (command "_.draworder" ss "" "_a" sr ""))
  (princ)
)

_a stands for "Above", previous "_u" is for "Under"... 

Message 5 of 11

nbawden
Advocate
Advocate

Works a treat - thanks Smiley Happy

0 Likes
Message 6 of 11

Anonymous
Not applicable

When I use this lisp, it asks me to select objects, ok. But then everything on the screen disappears. I don't know enough about lisp to read the routine and know what is happening. Any advice? Thanks.

0 Likes
Message 7 of 11

devitg
Advisor
Advisor
0 Likes
Message 8 of 11

Anonymous
Not applicable

This doesn't do anything.  Is there an update for AutoCAD Map 2019?


@ВeekeeCZ wrote:
(defun c:Test (/ data ss en sr)
  (if (and (setq en (car (entsel "\nSelect object on reference layer: ")))
           (setq sr (ssget "_X" (list (assoc 8 (entget en))))))
    (foreach layer '("Water" "Gas" "Electric" "Text" "Dimensions")
      (if (and (setq data (tblsearch "LAYER" layer)) ; layer exists
               (zerop (logand 4 (cdr (assoc 70 data)))) ; layer unlocked
               (setq ss (ssget "_X" (list (cons 8 layer)))) ; layer has objects
               )
        (command "_.draworder" ss "" "_u" sr ""))))
  (princ)
)

 

0 Likes
Message 9 of 11

dlanorh
Advisor
Advisor

@Anonymous wrote:

This doesn't do anything.  Is there an update for AutoCAD Map 2019?


@ВeekeeCZ wrote:
(defun c:Test (/ data ss en sr)
  (if (and (setq en (car (entsel "\nSelect object on reference layer: ")))
           (setq sr (ssget "_X" (list (assoc 8 (entget en))))))
    (foreach layer '("Water" "Gas" "Electric" "Text" "Dimensions")
      (if (and (setq data (tblsearch "LAYER" layer)) ; layer exists
               (zerop (logand 4 (cdr (assoc 70 data)))) ; layer unlocked
               (setq ss (ssget "_X" (list (cons 8 layer)))) ; layer has objects
               )
        (command "_.draworder" ss "" "_u" sr ""))))
  (princ)
)

 


If you don't have these layers (red items above) in your drawing it won't

 

I am not one of the robots you're looking for

0 Likes
Message 10 of 11

pat_cooper54dkt
Observer
Observer

Is there a way to incorporate using a wild card? I have multiple layers all beginning with "PHA"  and want them all sent to the back.

Thanks,

0 Likes
Message 11 of 11

devitg
Advisor
Advisor

@pat_cooper54dkt 

 

Please upload the LSP you are using or want to modify , and a sample.dwg

 

 

 

0 Likes