Jump to content
cat3appr

Layers draw order ; first last

Recommended Posts

cat3appr

hi

I have several drawings based on hatches and some lines.

I always want the hatch layer to appear last, in the very background, then line 1 second last, line 2 3rd last, and so on... based on layer ( i think)

 

is there a way to set and lock the priority of layers, in this manner?

Share this post


Link to post
Share on other sites
BIGAL

This may help and does not use draw order, assign an elevation to each layer in the order required I have found this to work as a simple method.

 

I have something I do all the time and it has 4 draworders but I just know the order to make it work.

Share this post


Link to post
Share on other sites
Cad64

I just did a quick search and found the lisp routine below. Just edit the code to set your layer order as you want it, then load and run the routine.

 

;;; OrderByLayer.lsp
;;; By 3wood 2015.12.24
;;; Change the layer name and add more layers to suit.
;;; The first layer will be sent to front and the last layer sent to back.
(defun C:OrderByLayer ()
 (command "._DRAWORDER" (ssget "_A" '((8 . "Layer1"))) "" "_B")
 (command "._DRAWORDER" (ssget "_A" '((8 . "Layer2"))) "" "_B")
 (command "._DRAWORDER" (ssget "_A" '((8 . "Layer3"))) "" "_B")
 (command "._DRAWORDER" (ssget "_A" '((8 . "Layer4"))) "" "_B")
 (command "._DRAWORDER" (ssget "_A" '((8 . "Layer5"))) "" "_B")
 (command "._DRAWORDER" (ssget "_A" '((8 . "Layer6"))) "" "_B")
 )

Share this post


Link to post
Share on other sites
cat3appr
I just did a quick search and found the lisp routine below. Just edit the code to set your layer order as you want it, then load and run the routine.

 

;;; OrderByLayer.lsp
;;; By 3wood 2015.12.24
;;; Change the layer name and add more layers to suit.
;;; The first layer will be sent to front and the last layer sent to back.
(defun C:OrderByLayer ()
 (command "._DRAWORDER" (ssget "_A" '((8 . "Layer1"))) "" "_B")
 (command "._DRAWORDER" (ssget "_A" '((8 . "Layer2"))) "" "_B")
 (command "._DRAWORDER" (ssget "_A" '((8 . "Layer3"))) "" "_B")
 (command "._DRAWORDER" (ssget "_A" '((8 . "Layer4"))) "" "_B")
 (command "._DRAWORDER" (ssget "_A" '((8 . "Layer5"))) "" "_B")
 (command "._DRAWORDER" (ssget "_A" '((8 . "Layer6"))) "" "_B")
 )

 

thanks Cad64, so how to use it... i only understand that i should replace " Layer1" with my named layer, but what is ssget"_A" and ((8. ? what do i do with A and 8? is it possible to have an example with 2 layers?

Share this post


Link to post
Share on other sites
cat3appr
This may help and does not use draw order, assign an elevation to each layer in the order required I have found this to work as a simple method.

 

I have something I do all the time and it has 4 draworders but I just know the order to make it work.

 

I went to layer property of the hatch and assigned elevation -1 . all the other layer's properties have elevation 0, so this should keep that hatch layer always behind, correct?

But after saving the DWG and re opening it, the hatch wasn't in the back ... so i guess something is not right

Edited by cat3appr

Share this post


Link to post
Share on other sites
cat3appr

ok i've attached the drawing i'm working on.

 

If you open the layers, HATCH layer should always be in the back, and is not, even after assigning a negative elevation.

 

Layers: Overage and Overage+5 should be on top layer Hatch but below AS-Laid Pipeline Line...

 

How to do this in an automatic way?

example.dwg

Share this post


Link to post
Share on other sites
SLW210

Opens correctly here in AutoCAD 2018, I tried in AutoCAD 2011, but it said drawing was created in newer version, I converted it back to 2010 and got that it had 8 errors and needed recovered, it then opened correctly in AutoCAD 2011. What Version of AutoCAD are you using?

 

Could it be your graphics card or driver?

 

Error when opening.

8 Errors.png

Share this post


Link to post
Share on other sites
Cad64
thanks Cad64, so how to use it... i only understand that i should replace " Layer1" with my named layer, but what is ssget"_A" and ((8. ? what do i do with A and 8? is it possible to have an example with 2 layers?

 

The only things you have to edit in the code are the layer names. Everything else stays the same. You said you want your hatch layer at the very back, so that layer name should be at the bottom of the list, then arrange your other layers in the order you want them to display above the hatch layer. See below.

 

;;; OrderByLayer.lsp 
;;; By 3wood 2015.12.24 
;;; Change the layer name and add more layers to suit. 
;;; The first layer will be sent to front and the last layer sent to back. 
(defun C:OrderByLayer ()   
(command "._DRAWORDER" (ssget "_A" '((8 . "Top_Layer"))) "" "_B")   
(command "._DRAWORDER" (ssget "_A" '((8 . "Middle_Layer"))) "" "_B")   
(command "._DRAWORDER" (ssget "_A" '((8 . "Hatch_Layer"))) "" "_B")
)

Share this post


Link to post
Share on other sites
cat3appr
Opens correctly here in AutoCAD 2018, I tried in AutoCAD 2011, but it said drawing was created in newer version, I converted it back to 2010 and got that it had 8 errors and needed recovered, it then opened correctly in AutoCAD 2011. What Version of AutoCAD are you using?

 

Could it be your graphics card or driver?

 

Error when opening.

 

Thanks SLW, I use CAD MAP 2015, what sort of mistakes did you get?

Graphic card is fine, it's fine, it can be anything else then.. windows, heating system etc.. :) I just need to organize some layers, if it can be easily done, ok, or else i just leave them as they are :)

Share this post


Link to post
Share on other sites
SLW210

Displays in correct order here in AutoCAD. Maybe it's a MAP issue. You need to update your profile or include what you are using in your question.

Share this post


Link to post
Share on other sites
cat3appr
The only things you have to edit in the code are the layer names. Everything else stays the same. You said you want your hatch layer at the very back, so that layer name should be at the bottom of the list, then arrange your other layers in the order you want them to display above the hatch layer. See below.

 

;;; OrderByLayer.lsp 
;;; By 3wood 2015.12.24 
;;; Change the layer name and add more layers to suit. 
;;; The first layer will be sent to front and the last layer sent to back. 
(defun C:OrderByLayer ()   
(command "._DRAWORDER" (ssget "_A" '((8 . "Top_Layer"))) "" "_B")   
(command "._DRAWORDER" (ssget "_A" '((8 . "Middle_Layer"))) "" "_B")   
(command "._DRAWORDER" (ssget "_A" '((8 . "Hatch_Layer"))) "" "_B")
)

 

Nope, something is not right. I copy&pasted your code, substituted the layers name with my layers name and i ordered by descending order, wit HATCH being on the bottom.

 

I loaded the LISP, and in fact it recognized the orderbylayer command, which appeared, so I did , enter, on that, and I got the following message:

 

Enter object ordering option {Above project/Under object/Front/Back } : _B

 

I couldn't interact, I gave ok and nothing happened... I tried by giving " Above" "Under".... but no feedback.

 

What leaves me skeptic is that I shouldn't prompt anything, the code already organizes the layers that finds by the order in the code... so why it asks for other things?

 

SOmething is wrong with the way the code is built then. I'd like something that after being run, it fixes the layers on the given order.. I don't want to give other instructions.

Share this post


Link to post
Share on other sites
Cad64
Posted (edited)

I already tested the code before posting it and it works perfectly. You shouldn't be prompted for anything. You should just type the command, hit enter and that's it.

 

Here are some things to check:

1. When you changed the layer names, did you remove the quotes around the names?

2. Did you accidentally delete a parenthesis?

3. Did you accidentally misspell any of the layer names? If the layer names in the code are not spelled exactly the same as the layer names in your drawing, or if the layer names in the code do not exist in the drawing, you will get an error. The layer names need to match exactly.

 

Double check your layer name list and if you're still having problems, post your code in your next reply.

Edited by Cad64

Share this post


Link to post
Share on other sites
cat3appr
I already tested the code before posting it and it works perfectly. You shouldn't be prompted for anything. You should just type the command, hit enter and that's it.

 

Double check your layer name list and if you're still having problems, post your code in your next reply.

 

Thanks Cad64, well it doesn't work, so, something is not right :)

Actually it got worse, it doesn't even recognize the name of the command.

 

I checked everything, layer names are fine, i didn't change a thing from your code. Please see the attached drawing with the layer naming, and see how i applied your code, by simply substituting the layer names.

 

If it works for you , please can you check the one I edeted for my layers and see if it works in the attached dwg? if it does, please can you upload it back with the working lisp?

 

many thanks!

Alex

example drawing layers.dwg

orderbylayer.txt

Share this post


Link to post
Share on other sites
Cad64

Ok, first things first. In order for a lisp routine to work, it has to be saved with a .lsp extension. You had it saved with a .txt extension. I have changed the file extension.

 

Next, you added the word "Code:" at the top of the routine. You can't add comments to a lisp routine unless you precede the comment with at least one semicolon. I have removed the word "Code:" from the routine.

 

You also removed the quotes from the layer names. All layer names must have quotes around them. I have added the quotes around the layer names.

 

Try the attached. This should work.

orderbylayer.lsp

Share this post


Link to post
Share on other sites
cat3appr
Ok, first things first. In order for a lisp routine to work, it has to be saved with a .lsp extension. You had it saved with a .txt extension. I have changed the file extension.

 

Next, you added the word "Code:" at the top of the routine. You can't add comments to a lisp routine unless you precede the comment with at least one semicolon. I have removed the word "Code:" from the routine.

 

You also removed the quotes from the layer names. All layer names must have quotes around them. I have added the quotes around the layer names.

 

Try the attached. This should work.

 

Yes it works very well thans :) when i write the command, it gets executed right away but it still comes up with the attached request... anyway, as far as it works, it's great.

 

Little problem now that i didn't think about before... can we make the lisp to function within a specific block of the drawing?

See the DWG i sent you, and on which the LISP works fine, it is a file background that gets cut and inserted by a software to a chart, which will be the main drowing. I tried to use the lisp on the chart and it didn't work, so i had to open up the block and execute it from within the block.

Problem is that the cad i have is particularly rusty, or maybe is the PC.. it takes minutes for the block to load. Now, I don't have time to fix the PC or CAD, ( and maybe these are not fixable ) so the easiest way is to make the LISP to work on a specific block within the main drawing. is this possible?

Screenshot - 3_2_2018 , 12_38_55 PM.png

Share this post


Link to post
Share on other sites
Cad64

can we make the lisp to function within a specific block of the drawing?

 

Now you're going beyond my ability. I do ok with simple routines but if you need to add more functionality like working inside a block, you will need to consult with one of the programmer's in the lisp section. You should start a new thread here: http://www.cadtutor.net/forum/forumdisplay.php?21-AutoLISP-Visual-LISP-amp-DCL and tell them what you're trying to do. You might also want to provide a link back to this thread so they can see what has already been discussed.

Share this post


Link to post
Share on other sites
cat3appr

ok thank you!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×