DRAWORDER by layer

Is there a way to associate a default or absolute display order with layers? I've perused the help and can't seem to find any way to do that.

«1

Comments

  • Not built in. Describe what you want.
    If I were doing this, I would use a text file with layer names to control order, and extra or missing layers in the dwg would be put to bottom.
    You have to describe what would be convenient for you, we can make that fairly easily, but it will run when you run it, not automatically.

  • James,
    Will what you are describing actually change the Layers as viewed in the Drawing Explorer?
    Mike

  • Steve,
    in the very distant past we probably have developed a utility that is of interest to you. I was actually surprised to see it survived as a command in current BricsCAD releases. The name of the command comes remarkably close to the title of this post, in fact, verbatim... DRAWORDERBYLAYER.

    In short:
    using a tool like e.g. Notepad, the user creates a list of layer names as a text file with extension '.lst', e.g. 'MyList.lst'
    When running DRAWORDERBYLAYER, the draworder of entities residing on these layers will be set according to the order of the layer names in the list.

    The command allows to choose which list to apply, so you could e.g. have 'MyPreferredOrder.lst', 'MyReversedOrder.lst', 'MyAlternativeOrder.lst', etc.

    See: https://help.bricsys.com/hc/en-us/articles/360006661553-DrawOrderByLayer

  • Ah, bit by the "Bricscad only command" situation. Love those.

  • Anthony Apostolaros
    edited April 2020

    I've been wanting something like that for a long time. Good to know it's been there all along.

    Is there an easy way to export that list of layer names to a text file in the same folder as the dwg file?

  • There is also the dialog based OrderByLayer freeware for v13 Pro or higher.

    Video: https://youtu.be/tBTRHyDCHLQ

  • @James Maeding said:
    Not built in. Describe what you want.
    If I were doing this, I would use a text file with layer names to control order, and extra or missing layers in the dwg would be put to bottom.
    You have to describe what would be convenient for you, we can make that fairly easily, but it will run when you run it, not automatically.

    Agree, easy to do in lisp, I was just wondering if there was something built-in. By "built-in" what I mean is something that creates a durable continuous link between layers and drawing order, but what's here will work fine. I can even invoke it on drawing opening or when plotting by embedding a call in those routines.

  • @Anthony Apostolaros said:
    I've been wanting something like that for a long time. Good to know it's been there all along.

    Is there an easy way to export that list of layer names to a text file in the same folder as the dwg file?

    Repeated calls to (cdr (assoc 2 (tblnext "layer"))) will give you the layer names. Just keep calling it in a (while) till it returns nil.

    (getvar "DWGPREFIX") gets you the directory for the current drawing. Since you may have many drawings in that directory, you probably want to name your layer list file by the drawingname so as not to collide and to know which layer list file goes to which drawing. (getvar "DWGNAME") gets you the name of the actual DWG file (without the directory).

  • @Hans De Backer said:
    Steve,
    in the very distant past we probably have developed a utility that is of interest to you. I was actually surprised to see it survived as a command in current BricsCAD releases. The name of the command comes remarkably close to the title of this post, in fact, verbatim... DRAWORDERBYLAYER.

    In short:
    using a tool like e.g. Notepad, the user creates a list of layer names as a text file with extension '.lst', e.g. 'MyList.lst'
    When running DRAWORDERBYLAYER, the draworder of entities residing on these layers will be set according to the order of the layer names in the list.

    The command allows to choose which list to apply, so you could e.g. have 'MyPreferredOrder.lst', 'MyReversedOrder.lst', 'MyAlternativeOrder.lst', etc.

    See: https://help.bricsys.com/hc/en-us/articles/360006661553-DrawOrderByLayer

    Thank you!

  • SteveDaniels
    edited April 2020

    @Anthony Apostolaros said:
    I've been wanting something like that for a long time. Good to know it's been there all along.

    Is there an easy way to export that list of layer names to a text file in the same folder as the dwg file?

    Here, see if this gives you what you need:

    (DEFUN C:LISTLAYERS()
        (setq lt "")
        (while
            (setq ln (cdr (assoc 2 (tblnext "LAYER"))))
            (setq lt (strcat lt ln ","))
            )
        (setq lt (substr lt 1 (1- (strlen lt))))
        (princ lt)
        (setq dn (getvar "DWGNAME"))
        (setq fh (open (strcat (getvar "DWGPREFIX")(substr dn 1 (- (strlen dn) 4)) ".llst") "w"))
        (write-line lt fh)
        (close fh)
        (princ)
    )
    
  • Thanks, Steve. Yes, that's exactly what I had in mind. I changed "," to "\n" and ".llst" to ".lst" to suit the built-in DrawOrderByLayer command.

    One thing I don't understand: it only works once each time I open a .dwg file. The second time it creates a nearly empty .lst file, and doesn't (princ lt) either. Until I re-open the .dwg file. Re-loading the lisp file doesn't make it work again.

    It shouldn't ever be necessary to do it again, but it bothers me that I don't understand why it won't. Do you know?

  • SteveDaniels
    edited April 2020

    Yes, in fact I was going to mention that as a caution. The (tblnext) increments its position in the LAYER table each time you call it, so once you've used this function the pointer is set to the end of the table and the first call will return a nil. You can call this one as many times as you want:

        (DEFUN C:LISTLAYERS()
            (setq f T)
            (setq lt (cdr (assoc 2 (tblnext "LAYER" f))))
            (while
                (setq ln (cdr (assoc 2 (tblnext "LAYER"))))
                (setq lt (strcat lt "\n" ln))
                )
            (princ lt)
            (setq dn (getvar "DWGNAME"))
            (setq fh (open (strcat (getvar "DWGPREFIX")(substr dn 1 (- (strlen dn) 4)) ".lst") "w"))
            (write-line lt fh)
            (close fh)
            (princ)
    )
    
  • That's perfect. Thanks again.

    Now if I just rename a few layers so that their place in the alphabetical order corresponds to where I want them in the layering scheme, I can just add (command "DrawOrderByLayer") to the end of that and use it to set layering with a single command.

    And, as you suggested, I could insert that all-in-one command in front of my Save and Print commands.

  • Always wonder things like this:
    Anyone know the methodology to the order produced?
    It isn’t alphabetical, seems random.
    What defines the order in which the list is produced?

  • I tested, its the order they were created in.

  • SteveDaniels
    edited April 2020

    Yeah, I was going to say layer table order, so probably creation order.

  • How does one find the order geometry is created in?

  • @Anthony Apostolaros said:
    That's perfect. Thanks again.

    Now if I just rename a few layers so that their place in the alphabetical order corresponds to where I want them in the layering scheme, I can just add (command "DrawOrderByLayer") to the end of that and use it to set layering with a single command.

    And, as you suggested, I could insert that all-in-one command in front of my Save and Print commands.

    Not following, because they don't come out in alphabetical order. Are you going to sort them in the file? We could sort them before export in lisp, but offline's probably easier.

    If you want to indicate your draworder alphabetically, I'd suggest prepending a couple numeric digits to the meaningful layer name. Then it's both machine- and people-readable.

  • Oops. I didn't look. I just assumed it would be alphabetical order, like in the Drawing Explorer and the Entity Properties bar. The first few in the .lst file were in fact like that: 0, Defpoints, Dimensions.

    Yes, I was thinking I would give them names like 0-Hatch and zNotes. But this actually works out better for me. I won't have to rename any layers. I can just create a new template file, starting from scratch and creating the layers in the order in which I want them layered. I don't use many layers, so that won't take long.

  • If you have a standard list of layer names, then why do you need a layer name export function?

  • That's the way my ACAD.DWT is. Layers set up with colors, etc. Never worried about creation order till now!

  • In fact, I probably won't use the full function for myself. My needs are straightforward enough that if there isn't a truly internal mapping that works in the background, I can write what I want in lisp easier than using DRAWORDERBYLAYER.

  • @SteveDaniels said:
    If you have a standard list of layer names, then why do you need a layer name export function?

    Maybe I'm confused. I thought this thread was about layering -- in the English language sense (layers of paint, soil, rock, cake, etc.) -- and linking that type of layering with what Autocad calls layers, so that AC layers can be used in the same way as VectorWorks and Photoshop layers.

    Certainly that's what the DrawOrderByLayer command is about. And I never knew about that command before, so for me it was a lucky mistake.

    The reason I wanted a layer name export function was because the DrawOrderByLayer command requires a text file of layer names, but it doesn't provide a way to get such a file.

  • I do not like anything reliant on a template. Fine to start with, but then you have to be all careful not to purge all and so on.
    Its better to have a dwg with what you need and insert that in any time you need layers available.
    Then you can purgeall any time you need.
    I only say this as I bet you, @SteveDaniels are not familiar with the WTIT tool(s).
    I attached the lisp. Look at it in a text editor or BLADE to see the commands listed at the top.
    So you might have a bunch of linework that has the layer/linetypes/blocks...whatever, as your "template".
    You run WTX, say like "stuff1" for the name, and it saves it to your (getvar "tempprefix") folder. Tweak as needed in the first lines of the lisp.
    To insert that, you type ITX, and stuff1 for the name.
    Its like a permanent clipboard that saves browsing and clicks.
    It also has non-named ones, like WT and IT, where it assumes a name "temp", and overwrites if you run WT again.
    Look at the lisp. This util was voted most valuable way back, and I enhanced it a bunch so even better now, and all free.
    If you are in an office, look at the WTN and ITN commands, like a network clipboard. Tweak the path at top to choose the network folder...

  • @SteveDaniels said:
    Maybe I'm confused. I thought this thread was about layering -- in the English language sense (layers of paint, soil, rock, cake, etc.) -- and linking that type of layering with what Autocad calls layers, so that AC layers can be used in the same way as VectorWorks and Photoshop layers.

    Certainly that's what the DrawOrderByLayer command is about. And I never knew about that command before, so for me it was a lucky mistake.

    The reason I wanted a layer name export function was because the DrawOrderByLayer command requires a text file of layer names, but it doesn't provide a way to get such a file.

    A few things to mention:
    1) in the end, autocad does not order anything by layer. It orders things using a big numbered list, such that each item has a number.
    In other words, every item has an item above and below, except the very top and bottom item.
    2) Its fine to use acad layers to set the draworder, many have done that. Understand that the draworderbylayer is not modifying the layer itself. You cannot tell autocad "this layer is always on top".
    3) you can use the layers to manipulate the draw order of individual entities, at a point in time. You must repeat after adding new stuff.
    4) The tools to set draworder of entities using a layer list, requires a text file of layers, in order desired. Since you do not have that, use the util to generate the list.

    HTH

  • @James Maeding said:
    I do not like anything reliant on a template. Fine to start with, but then you have to be all careful not to purge all and so on.
    Its better to have a dwg with what you need and insert that in any time you need layers available.
    Then you can purgeall any time you need.

    My template file doesn't have any geometry in it. It just has:

    • all the settings the way I want them;
    • page setups for the 3 sheet sizes I normally use;
    • a marker at the origin in modelspace;
    • dimension entities in the 2 dimension styles I use;
    • the 19 layers I normally use; and
    • a text entity on each of those layers and in each of the 5 text styles I use.
      All those entities are inside the origin marker, so that they're never erased and their layers and styles are never purged.

    Geometry that I frequently use is in a .dwg file, and I copy it into a project file as needed. But I don't use the Wblock or Insert commands. I use F3 (CopyBase) and F2 (PasteClip).

  • The reason I wanted a layer name export function was because the DrawOrderByLayer command requires a text file of layer names, but it doesn't provide a way to get such a file.

    I took, perhaps wrongly, from your post about the template approach, that your drawings all have the same layers, ordered in the same way, or a subset of a master list. If that's the case, why export layer lists from drawings in real time? You would just manually create a master list one time and use that.

  • @James, the template approach has always been fairly effective for me (and I do purge, though not super often as I don't create a lot of leave behinds)

    I'll gladly check out your approach (and use as is or steal your ideas!)

    Thanks!

  • Anthony Apostolaros
    edited April 2020

    @SteveDaniels said:
    You would just manually create a master list one time and use that.

    Ah, yes. That's a better idea. When I originally asked about exporting layer names to a file, I was thinking about doing it just once. But when working with lisp code I tend to get confused and forget the original objective.

    But sometimes I add extra layers to a dwg file while working on it. If I add a lot of them, or if I forget to add them to the .LST file as I create them, your layer export function would come in handy. However, the automated thing I described above won't work, since those additional layers probably won't be in the right position in the .LST file.

  • @James Maeding said:
    .... You cannot tell autocad "this layer is always on top".

    Maybe I'm even more confused than I thought. Isn't that what the DrawOrderByLayer command does?
    Not really "always" as in VectorWorks and Photoshop, but immediately after each time you run the command.
    So if I'm set up to run the command automatically at the right times it has the same effect.