Hello guys and greetings from germany,
I don't know anything about creating LISPs for AutoCAD - but I'm looking for some to change the current layer (after executing a command) to a specific one and then swicht back to the current.
I need this for the following commands:
Current layer = 0 - command "_mtext" with layer = text - switch layer back to current layer after executing the command
Current layer = 0 - command "_text" with layer = text - switch layer back to current layer after executing the command
Current layer = 0 - command "_mleader" with layer = mleader - switch layer back to current layer after executing the command
Current layer = 0 - command "_insert" with layer = block - switch layer back to current layer after executing the command
I already know how to do this with the tool palette - but I don't want to work with it, cause I'm using the toolbars.
Hope you guys can help me!
Thank you for your help in advance!
Solved! Go to Solution.
Solved by ВeekeeCZ. Go to Solution.
It could work something like this:
(command "_.undefine" "mtext") (defun c:mtext ( / *error* clayer) (vl-load-com) (defun *error* (err) (setvar "clayer" clayer) (setvar "cmdecho" 1) (vla-endundomark *doc*) (cond ((not err)) ((wcmatch (strcase err) "*CANCEL*,*QUIT*")) (1 (princ (strcat "\nERROR: " err))) ) (princ) ) (or *acad* (setq *acad* (vlax-get-acad-object))) (or *doc* (setq *doc* (vla-get-ActiveDocument *acad*))) (vla-endundomark *doc*) (vla-startundomark *doc*) (setq clayer (getvar "clayer")) (setvar "cmdecho" 0) (command "_.layer" "M" "TEXT") (command "_.mtext") (setvar "cmdecho" 1) (while (> (getvar "cmdactive") 0)(command pause)) (*error* nil) )
John F. Uhden
@ibfmm wrote:
... LISPs for AutoCAD - but I'm looking for some to change the current layer (after executing a command) to a specific one and then swicht back to the current.
....
I believe the Architectural overlay program has this capability built in, but I'm not sure whether other overlay programs do.
Another approach would be to not change the current Layer before drawing something, but so that you don't have to change the current Layer back afterwards, instead change the something to the desired Layer after drawing it. In simplest terms:
(command "_.undefine" "INSERT")
(defun C:INSERT ()
(command "_.layer" "_new" "BLOCK" ""); in case it doesn't exist yet; does not make it current
(command "_.insert")
(while (> (getvar 'cmdactive) 0) (command pause))
(command "_.chprop" "_last" "" "_layer" "BLOCK" "")
); defun
Or, you could take advantage of a peculiarity I discovered some time ago -- if you give an object a Layer using (subst) & (entmod), if the Layer doesn't yet exist, it will create the Layer in the process [using default color 7 and continuous linetype], so you don't even need to account for the possibility that it's not in the drawing yet:
(command "_.undefine" "INSERT")
(defun C:INSERT ()
(command "_.insert")
(while (> (getvar 'cmdactive) 0) (command pause))
(entmod (subst (cons 8 "BLOCK") (assoc 8 (setq edata (entget (entlast)))) edata))
); defun
However, those approaches have at least one drawback that I can think of in the TEXT command. You can make more than one Text object in a single command, by picking new insertion points along the way. Those approaches would put only the last one on the designated Layer. But a more sophisticated routine could account for that [mark the last object in the drawing before starting, and change the Layer of everything newer than that when done].
Welcome to these Forums, by the way!
As an aside, I do wonder whether this is an advisable thing to do. I certainly do not want all Blocks always inserted on the same Layer. I want [in my case in architectural drawings] furniture Blocks on a furniture Layer, and plumbing-fixture Blocks on a plumbing-fixtures Layer, and so on. Nor do I always want all Text objects always on the same Layer -- one for Room Names, one for Drawing Titles, one for....
Yes, you could appreciate the myriad layers we civils use, but my pool liner people use a total of only about 4 or 5 layers and all their text is on one layer.
John F. Uhden
This is a neat trick and many organizations use it. Use LeeMac's routine as a starting point, @ВeekeeCZ posted the link for you. Although I agree with @Kent1Cooper that I do not want certain graphical entities always on the same layer, I do like my Xrefs and Viewports on their respective layers. See screencast below. Start with Lee Macs routine and post your modified version and we can help you.
Hey guys,
at first thanks for all your replies!
I took the easiest way and tried the FLay application from cadstudio.cz
After editing the Flay.tab file for my personal setup, everything worked as I wanted! Really cool!
If the specific layer doesn't exist in the drawing, the application creates it.
This is exactly what I was looking for.
A nice weekend to you all!
Hey guys,
now I have a little problem with the Flay application.
The VLX gets loaded automatically at the startup, but i need to load the TAB file manually everytime by myself!
So I tried to go another way by manipulating the makro in the toolbar, for example from
^C^C_MLEADER
to
^C^C_-LAYER;_SE;MLEADER;;_MLEADER
This works - but after executing the command, the layer won't switch back to the current (usually to layer 0).
Does somebody knows, which things I need to add to the makro, so that AutoCAD will switch back to the current layer or layer 0?
Don't know how loads the TAB file, maybe the author @vladimir_michl could explain.
About the macro - this is not the job for a macro. You need to use a LISP for that. See the examples what the other guys gave you... One modified for your MLeader
(defun c:LayMleader ( / *error* clayer) (defun *error* (err) (setvar "clayer" clayer) ; reset clayer (cond ((not err)) ((wcmatch (strcase err) "*CANCEL*,*QUIT*")) (1 (princ (strcat "\nERROR: " err)))) (princ) ) (setq clayer (getvar "clayer")) ; save the previous current layer (command "_.layer" "M" "_SE") ; set new current layer (create if it does no exist) (command "_.MLEADER") (while (> (getvar "cmdactive") 0) ; stay within the routine while the command is active (command pause)) (*error* nil) ; go to *error* which resets the current layer back )
No, FLAY loads automatically and it also automatically loads the FLAY.TAB file (the first one in AutoCAD search path). So you can use FLAY fully transparently.
Vladimir Michl, www.cadstudio.cz www.cadforum.cz
... I missed to paste the TAB file in one of the support paths from AutoCAD - now it works!
Do you know, why it doesn't work for the command "tcircle" from the express tools?
I also get the following note in the command line after typing in flay:
FLAY>> Possible unknown command(s) in the .TAB file: REVCLOUD TCIRCLE
Hitting the revcloud button in the toolbar sets my layer to revcloud like I want it - strange...
... hey everybody!
Does anybody know why the TCIRCLE command from the express tools doesn't work wit the FLay app?
TCIRCLE is technically not a command but a LISP function (C:TCIRCLE). While it is possible to process also LISP functions in the FLay reactor, I am afraid it would slow down invoking of all LISP functions.
Vladimir Michl, www.cadstudio.cz www.cadforum.cz
New FLay version 2.1 (see www.cadstudio.cz/freeware) now supports also LISP-based commands. But you will need to enable the LISP-reactor manually, by setting:
(setq FL:LISPREACTOR T)
as it slightly slows down any LISP function invoked in your AutoCAD session (see readme in FLAY.TXT).
Vladimir Michl, www.cadstudio.cz www.cadforum.cz
@FMM_MK wrote:... awesome, thank you
You might want to check to see if any of the reactor-based solutions you've chosen to use are disabling REDO, because my experience is that many of them do.
Changes made to the editor in the 'command ended' reactor has the potential to disable REDO, which I regard as a complete show-stopper.
i know this is an old thread, but does anyone know if the there is a solution like the one posted by Lee Mac, but with the ability to use alias commands? for instance, i use the "line" command for different items and need them on different layers at different times. but i'd love if i could use a custom "1" command and have that do a line that's on layer "text" and custom "2" command and have that do a line that's on layer "beam".
@mbracciahubbard wrote:
... i'd love if i could use a custom "1" command and have that do a line that's on layer "text" and custom "2" command and have that do a line that's on layer "beam".
This is pretty basic AutoLisp command-definition stuff. In very simplest terms:
(defun C:1 ()
(setvar 'clayer "text")
(command "_.line")
)
(defun C:2 ()
(setvar 'clayer "beam")
(command "_.line")
)
They can be enhanced, such as to ensure the Layer exists in the drawing, and/or if you want, to save the current Layer first and return you to that afterwards [you may not want that, if you're often likely to want to draw more on the Layer in question than just one Line command's worth].
Can't find what you're looking for? Ask the community or share your knowledge.