Automatic layer draw order button

Automatic layer draw order button

Anonymous
Not applicable
2,827 Views
7 Replies
Message 1 of 8

Automatic layer draw order button

Anonymous
Not applicable

Hello,

 

Currently I would need to manually click an object, line, etc. Right click and hit the option "select similar" and then again right click to specify the "draw order" of the selected items. Could anyone lend me some advice on how to create a Tool Palette button that on press, rearranges the order of layers to a predefined setting?

 

For example, I'll have the following layers that are to be prioritized in a draw order..

 

Xref layer - The layer used to display the Xref of the residential site to work ontop of (always on bottom of draw order)

Low voltage cable - Displays a layer which only has Polylines depicting the low voltage cable route (always below of draw order)

High voltage cable - Displays a layer which only has Polylines depicting the high voltage cable route (always on top of draw order)

 

The Xref should always be arranged to the bottom of any draw order to be drawn on top of. The Low voltage cable polylines should always be shown below the High voltage cable polylines upon any cross overs of the two lines.


I'd like to find a way so that the above definition is automatically determined on press of a button. This would help greatly in minimizing human error amongst myself and other colleagues in the accuracy and quality of drawing work produced.

 

Thanks for any advice.

0 Likes
2,828 Views
7 Replies
Replies (7)
Message 2 of 8

rkmcswain
Mentor
Mentor

If you're considering 3rd party tools, Toolpac includes a "DrawOrder By Layer" command.

 

R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 3 of 8

pendean
Community Legend
Community Legend
Express tool CDORDER is built in (if you installed them) and lets you and your colleagues sort drawoder by object color if you want a free fix.

otherwise you probably need to be posting here for help from someone to write code for you to do what you want https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/bd-p/130
0 Likes
Message 4 of 8

ВeekeeCZ
Consultant
Consultant

U can also try THIS Lee Mac's solution.

0 Likes
Message 5 of 8

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... Could anyone lend me some advice on how to create a Tool Palette button that on press, rearranges the order of layers to a predefined setting?

.... 

The Xref should always be arranged to the bottom of any draw order to be drawn on top of. The Low voltage cable polylines should always be shown below the High voltage cable polylines upon any cross overs of the two lines.

....


Seems as simple as putting this into a command definition that can be triggered by a Tool Palette button:

 

(command

  "_.draworder" (ssget "_X" '((8 . "Xref"))) "" "_back"

  "_.draworder" (ssget "_X" '((8 . "Low voltage cable"))) "" "_front"

  "_.draworder" (ssget "_X" '((8 . "High voltage cable"))) "" "_front"

); command

 

Whatever your actual Layer names are [not sure from the Post wording]....

 

That puts the Low voltage cable Layer above everything else, then puts the High voltage cable Layer on top of that.  It assumes none of those Layers are locked.

 

It could presumably also be done in macro language in a button, but doing with a command definition also allows the option of typing it, rather than only having it available through the Tool Palette [e.g. if that one Palette isn't displayed currently, it can be faster to type in a command name than to navigate to and call up the Palette].

Kent Cooper, AIA
0 Likes
Message 6 of 8

joselggalan
Advocate
Advocate

Other solution:

 

;------------------------------------------------------------;
;Change all the features in a layer forward or backward      ;
;------------------------------------------------------------;
(defun ChgOrderLay ( Mode / eco Ent sLayer)
 (setq eco (getvar 'cmdecho))
 (setvar 'cmdecho 0)
 (cond
  ((and (setq Ent (vl-catch-all-apply 'entsel (list "\nPick entity: ")))
	(not (vl-catch-all-error-p Ent))
   )
   (setq sLayer (cdr (assoc 8 (entget (car Ent)))))
   (cond
	((setq Sel (ssget "_X" (list (cons 8 sLayer))))
	 (vl-cmdf "_.draworder" Sel "" Mode)
	 (prompt (strcat "\nChanged display order layer: \"" sLayer "\""
					 (if (= Mode "_F") " Front." " Back.") 
             )
	 )
    )
   )
  )
 )
 (setvar 'cmdecho eco)
 (princ)
)
(defun C:LyF ()(ChgOrderLay "_F")) 
(defun C:LyB ()(ChgOrderLay "_B"))

(princ)
0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:


 

....

It could presumably also be done in macro language in a button, but doing with a command definition also allows the option of typing it, rather than only having it available through the Tool Palette ....



Also, it can be called from something else, like acaddoc.lsp, so that it will be run automatically in every drawing when you open it, just in case things get out of draw order in working on drawings.  Whether or not you do something like that, it's probably a good idea to verify that something was found on each of those Layers -- without that, if either a Layer doesn't exist or there's nothing drawn on it, the (ssget) function will return nil, and the Draworder command will not proceed to ask where to put things, so the command prompt sequence will be thrown off.  Something more like:

(if (setq ss (ssget "_X" '((8 . "Xref")))) (command "_.draworder" ss "" "_back"))

(if (setq ss (ssget "_X" '((8 . "Low voltage cable")))) (command "_.draworder" ss "" "_front"))

(if (setq ss (ssget "_X" '((8 . "High voltage cable")))) (command "_.draworder" ss "" "_front"))

Kent Cooper, AIA
0 Likes
Message 8 of 8

marko_ribar
Advisor
Advisor

Related topic...

https://www.theswamp.org/index.php?topic=48047.msg530961#msg530961

 

DosLib :

http://wiki.mcneel.com/doslib/home

 

And look into attachment for sub functions by LM...

 

Regards...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes