Jump to content
EspElement

Change layer from command line

Recommended Posts

EspElement

To all,

 

I am new here. I am excited about the opportunity to learn more about ways to run my AutoCAD. I am not new to AutoCAD I just haven't used it as much in past years and haven't explored new quick commands.

 

At one point I had a layer command that I could select a line, type in the layer I wanted (with no extra prompts required) and it would change. The best part is if the layer didn't exist it would automatically create it (without prompting me Y/N).

 

Using LAYMCH in the command line is very close. However I have to press N for name, then enter the layer. If it is a new layer, it prompts me Y/N.

 

I know there is a better way around this! I am all about making things easier and this is one of them. I am sure someone knows what I am looking for.

 

Thank you in advance.

 

Regards

Josh

Share this post


Link to post
Share on other sites
ReMark

It sounds like you may have used a macro or a lisp routine. Ring any bells?

Share this post


Link to post
Share on other sites
EspElement

Actually, I am getting into .lisp files now. However back when I did this I didn't work with .lisp or macros. I am not sure if it was something special that was embedded in our specific AutoCAD. It was AutoCAD Mechanical 2010.

 

Would I have to recreate this post in the .lisp location to see if someone can help me creating this to auto enter the N and or Y/N?

 

Thank you

Regards

Share this post


Link to post
Share on other sites
ReMark

The command could have been part of the program or someone in the company you worked in at the time created it.

 

Yes, I would repost the question as a call for assistance in developing a lisp routine. For all either one of us knows this has already been done by someone else and is available for the downloading. Either way you're covered.

Share this post


Link to post
Share on other sites
CyberAngel

Surely it would be easier and less error prone to use the dropdown layer list to change an object's layer, rather than typing in a layer name.

Share this post


Link to post
Share on other sites
Dadgad

Welcome to the forum. :)

How about MATCHPROP?

Or if you use your QUICK PROPERTIES palette changing layers is very easy on the fly.

Share this post


Link to post
Share on other sites
ReMark

Example of a simple macro. The macro starts a line on a newly defined layer.

 

^C^C_-layer;make;pipe;color;red;;;line;endpoint;

Share this post


Link to post
Share on other sites
EspElement

Dadgad - Actually I was just speaking to a fellow here about quick properties. I do not use it currently because I like to make my right click enter and/or repeat last command. However they have a long click option for it I may explore. Also, I love the MATCHPROP command and this is perfect when the particular layer is available for me to match it with.

 

CyberAngel - you know, it seems like it. However my new company has about 50-100 layers and it is very hard to find them sometimes.

 

ReMark - Thank you, I will have to explore this. I like the idea of starting a sketch on a particular layer that is not the one I am on.

 

Thank you all. I will post if I have more questions/concerns.

 

Regards

Josh

Share this post


Link to post
Share on other sites
MSasu

You may adjust this example to suit your needs:

;;; Change to New Layer (31-V-2012)
(defun c:CNL( / itemToChange theLayer assocList )
(while (and (setq itemToChange (ssget "_:S:E"))
            (setq theLayer (getstring "\nName of layer:")))
 (setq assocList (entget (ssname itemToChange 0)))
 (if (not (tblsearch "LAYER" theLayer))
  (entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord")
                  (cons 2 theLayer) '(70 . 0) '(62 . 7) '(6 . "Continuous")))
 )
 (entmod (subst (cons 8 theLayer)
                (assoc 8 assocList)
                assocList))
)
(princ)
)

Share this post


Link to post
Share on other sites
Dadgad
Dadgad - Actually I was just speaking to a fellow here about quick properties. I do not use it currently because I like to make my right click enter and/or repeat last command. However they have a long click option for it I may explore. Also, I love the MATCHPROP command and this is perfect when the particular layer is available for me to match it with.

 

CyberAngel - you know, it seems like it. However my new company has about 50-100 layers and it is very hard to find them sometimes.

 

ReMark - Thank you, I will have to explore this. I like the idea of starting a sketch on a particular layer that is not the one I am on.

 

Thank you all. I will post if I have more questions/concerns.

 

Regards

Josh

 

 

Time sensitive right click is definitely great, why settle for less, do it all.

 

When using the QUICK PROPERTIES feature, it is a good idea to take 10 minutes and go through the whole list.

Right click in the border and select CUSTOMIZE to tweak it, SETTINGS defines how it displays mostly.

You can go through the numerous types of entities and select for each different type, whatever information you think might be valuable for you as defaults for that specific item type.

 

In that way it displays only the information that you want it to, unlike the PROPERTIES which just shows you everything and cannot be customized.

 

If you want it to it will collapse automatically, remain static, or be cursor location dependent, or you may want it to be transparent or translucent, until you MOUSE over it.

Lots of great things you can do with it. I always use it, would be lost without it.

 

You probably already know, but you can use your SPACEBAR to repeat a command too. :)

Edited by Dadgad

Share this post


Link to post
Share on other sites
EspElement

MSasu - That lisp is awesome! Does exactly what I was looking for. Thank you

 

Dadgad - You have opened my eyes to some of the new features which may allow me to do much more. Thank you

Share this post


Link to post
Share on other sites
MSasu
MSasu - That lisp is awesome! Does exactly what I was looking for. Thank you

You're welcome! Although I'm really not sure how effective this solution may be when you have long names for layers...

Share this post


Link to post
Share on other sites
MSasu

If the list of layers to chouse from isn't too big, then you may simplify the name input:

;;; Change to New Layer (31-V-2012)
(defun c:CNL( / itemToChange theLayer assocList )
(while (and (setq itemToChange (ssget "_:S:E"))
            (not (initget "Shape Axis DImensions DRawing"))
            (setq theLayer (getkword "\nName of layer (Shape/Axis/DImensions/DRawing):")))
 (setq assocList (entget (ssname itemToChange 0)))
 (setq theLayer (strcat (strcase (substr theLayer 1 1))
                        (strcase (substr theLayer 2) T)))
 (if (not (tblsearch "LAYER" theLayer))
  (entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord")
                  (cons 2 theLayer) '(70 . 0) '(62 . 7) '(6 . "Continuous")))
 )
 (entmod (subst (cons 8 theLayer)
                (assoc 8 assocList)
                assocList))
)
(princ)
)

Share this post


Link to post
Share on other sites
Dadgad
MSasu - That lisp is awesome! Does exactly what I was looking for. Thank you

 

Dadgad - You have opened my eyes to some of the new features which may allow me to do much more. Thank you

 

That does look pretty sweet Mircea! :beer:

Once you start to get up to speed with the software again, check out the LAYERS 2 toolbar, lots of good stuff there.

I am a great fan of LAYER WALK. :)

Share this post


Link to post
Share on other sites
EspElement

MSasu - How would I change this command to start with a selecting window?

Share this post


Link to post
Share on other sites
EspElement

Dadgad - Layer walk looks awesome!

Share this post


Link to post
Share on other sites
Dadgad
Dadgad - Layer walk looks awesome!

 

It is, I use it all the time when I am checking drawings, it is really nice to be able to just use your cursor arrows to scroll through all your layers.

You can also set up and save filters using wildcards, so that they will be there the next time you want to use them. :thumbsup:

Share this post


Link to post
Share on other sites
MSasu
How would I change this command to start with a selecting window?

Something like this?

;;; Change to New Layer (01-VI-2012)
(defun c:CNL(); / itemToChange itemsSet theLayer assocList )
(while (and (princ "\nSelect items to change layer...")
            (setq itemsSet (ssget))
            (setq theLayer (getstring "\nName of layer:")))
 (if (not (tblsearch "LAYER" theLayer))
  (entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord")
                  (cons 2 theLayer) '(70 . 0) '(62 . 7) '(6 . "Continuous")))
 )
 (while (> (sslength itemsSet) 0)
  (setq assocList (entget (setq itemToChange (ssname itemsSet 0))))
  (entmod (subst (cons 8 theLayer)
                 (assoc 8 assocList)
                 assocList))

  (ssdel itemToChange itemsSet)
 )
)
(princ)
)

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

×