Change to layer 0 (make layer 0 current)

Change to layer 0 (make layer 0 current)

ntellery
Collaborator Collaborator
1,362 Views
19 Replies
Message 1 of 20

Change to layer 0 (make layer 0 current)

ntellery
Collaborator
Collaborator

EDIT: I'm embarrassed to report, it was just a syntax error further up in the whole .lsp file, 
A missing bracket to close one portion.  See thread for solution.
Thanks all, sorry to waste your time.

This lisp (part of a mystuff.lsp file auto loaded) worked fine in 2018 but no longer works in 2020.
(defun C:L0 () (command "-layer" "ON" "0" "m" "0" "") (command "regen")) ;;Change to layer 0 and regen
It just returns "unknown command" and does nothing.
Gemini AI (Google) suggested
(defun C:L0 () (setvar 'clayer "0"))
but it doesn't work either.   It does work just added into command line.  (setvar 'clayer "0")
Gemini suggested C:\LO but that didn't work either.  GPTchat4 wasn't much use either.

What syntax changed in 2020?  These no longer work either.  Same reason?
(defun c:U0 () (command "-units" "2" "0" "2" "4" "0" "N" ) (GRAPHSCR));;;No decimal places (Princ) US0
(defun c:U1 () (command "-units" "2" "1" "2" "2" "0" "N" ) (GRAPHSCR)) ;;;1 decimal place US1
(defun c:U2 () (command "-units" "2" "2" "2" "8" "0" "N" ) (GRAPHSCR)) ;;;2 decimal places US2

Help appreciated.

www.ausaca.blogspot.com
Do you know all about the Roof Object? Learn it's secrets
http://ausaca.blogspot.com.au/p/roof-object-video-links.html
0 Likes
Accepted solutions (1)
1,363 Views
19 Replies
Replies (19)
Message 2 of 20

Kent1Cooper
Consultant
Consultant

Is Layer 0 Frozen?  That possibility may be the only reason a REGEN might be needed.  If so, it can't be made current.  Try adding a Thawing of it first.

The hyphen prefix isn't needed when inside an AutoLisp (command) function, where the command-line version is the standard, not the dialog box.

If you use the Layer command's Set option, it will turn it on if it's off, so you don't need to turn it on.  Besides, there's no point in the Make option to set it current, since that Layer can never be Purged, so it must always exist in the drawing already.

Could you have a differently-defined LAYER command?  Possibly if you use an overlay, not just "vanilla" AutoCAD.  Using the period prefix will force use of the native command.  [And I always include the underscore so the same command can be used in other-than-English versions -- users of this Forum are from all over the world.]

The LAYER and REGEN commands can be in the same (command) function together.

 

(defun C:L0 () (command "_.layer" "_thaw" "0" "_set" "0" "" "_.regen")) ;;Change to layer 0 and regen

Kent Cooper, AIA
Message 3 of 20

Brock_Olly
Collaborator
Collaborator

Since you mentioned gemini, here's what GPT has to say..
https://chatgpt.com/share/6781482d-92ac-8002-86a5-0b3049958a92

Message 4 of 20

Kent1Cooper
Consultant
Consultant

@Brock_Olly wrote:

... here's what GPT has to say.. ....


Another demonstration of a variety of things it doesn't know [yet].

 

It suggests checking whether Layer 0 exists, but that is pointless -- it always exists, because it cannot be Purged, nor Renamed.

It does not account for the possibility that Layer 0 could be Frozen, in which case it cannot be set current [by either method below].

It suggests replacing (GRAPHSCR) with (command "GRAPHSCR"), which will do no good, because it doesn't know that (GRAPHSCR) is a legitimate AutoLisp function, as well as a command.

It suggests using (setvar 'clayer "0") to make it current.  That will not turn the Layer on if it's off, the way the Set option in a Layer command will.

 

I've pointed out these things to it at that link, and it has adjusted its recommendations.  [EDIT:  Well, it responded and adjusted when I "spoke" to it about these things, but the changes didn't stick -- I just picked the link again and it's the original with all the flaws.]

 

Kent Cooper, AIA
Message 5 of 20

paullimapa
Mentor
Mentor

U0, U1 & U2 work fine in my AutoCAD 2020...

What happens when you copy & paste each of the defun lines into your command prompt and then run it like the way I did below? 

paullimapa_0-1736529546591.png

paullimapa_1-1736529610605.png

paullimapa_2-1736529653323.png

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 6 of 20

scot-65
Advisor
Advisor
(command "-layer" "Thaw" "0" "m" "0" "")

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 7 of 20

stev98312
Enthusiast
Enthusiast

Will this work for you?

 

 

 

;; Posted 29 JAN 2021 by Kent1Cooper
;; forums.autodesk.com/t5/visual-lisp-autolisp-and-general/macro-clayer-laycur/m-p/10042610/highlight/true#M410268

;; Easy way to move objects to the 0 (zero) layer.
;; Or don't select anything and Zero layer becomes current.

(defun C:00 () ;; Zero Zero
  ; put pre-selected object(s) [if any] on Layer 0, otherwise set current Layer to 0
  (if (ssget "_I") ;if
    (command "_.chprop" "_layer" "0" "") ; then
    (command "_.layer" "_thaw" "0" "_set" "0" "") ; else
  ) ; if
  (princ)
)

 

 

EDIT: To give credit to original author of the code.

 

Steve

 

 

Message 8 of 20

ntellery
Collaborator
Collaborator

Thanks but it still returns "unknown command"
If I copy paste your (command "_.layer" "_thaw" "0" "_set" "0" "" "_.regen") into the command line it works.
(but all of them work in the command line).

Pasting at the beginning of mystuff.lsp it now works (all of them do) and my Units code is immediately above which also doesn't work so I guess there is something breaking my code above that.
Funny that my LayerMerge LMG is below and still works fine.

I've attached the whole file, it's not long and LO is near the bottom.

www.ausaca.blogspot.com
Do you know all about the Roof Object? Learn it's secrets
http://ausaca.blogspot.com.au/p/roof-object-video-links.html
0 Likes
Message 9 of 20

ntellery
Collaborator
Collaborator

yeh I tried GPTchat many months ago but it was pretty useless.
I tried to get it to create other code but it just went around in circles.
I'm figuring out that it's something in my whole code, mystuff.lsp that is breaking, not just this line.
I've posted it here to a reply.  

www.ausaca.blogspot.com
Do you know all about the Roof Object? Learn it's secrets
http://ausaca.blogspot.com.au/p/roof-object-video-links.html
0 Likes
Message 10 of 20

paullimapa
Mentor
Mentor
Accepted solution

When I try to load your lisp I get this error:

Command: (LOAD "C:/Users/PauLpc/Downloads/aMyStuff.lsp") ; error: malformed list on input

I used VS Code's bracket matching extension and found the following line missing a closing parenthesis to complete the defun which throws off everything after this:

;Rename views routine.
(defun C:RenView () (command "-ren" "View" "Street1" "1")

Add the missing closing parenthesis and see if that resolves your problem:

;Rename views routine.
(defun C:RenView () (command "-ren" "View" "Street1" "1"))

Now your lisp loads fine:

Command: (LOAD "C:/Users/PauLpc/Downloads/aMyStuff.lsp") C:LMG

So it's very important that you use a lisp editing program that has the bracket matching feature.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 11 of 20

ntellery
Collaborator
Collaborator

That was very quick, thankyou!!  Beastmode.
I was using Notepad++ and it didn't seem to pick that up.  I would have thought it would.
I'm trying to learn to use Vlide but still trying to get my head around it.

www.ausaca.blogspot.com
Do you know all about the Roof Object? Learn it's secrets
http://ausaca.blogspot.com.au/p/roof-object-video-links.html
0 Likes
Message 12 of 20

paullimapa
Mentor
Mentor

I also notice you have these 2 lines of code which represent the same sequence of commands:

(defun C:SHE () (command "SHADEMODE" "O")) 	;; 2D WIREFRAME DISPLAY
(defun C:SH  () (command "SHADEMODE" "O")) 	;; 2D WIREFRAME DISPLAY

But SH command is set aside by AutoCAD in acad.pgp to run an OS command:

paullimapa_0-1736557463663.png

So I would remove the following from your lisp code:

(defun C:SH  () (command "SHADEMODE" "O")) 	;; 2D WIREFRAME DISPLAY

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 13 of 20

ntellery
Collaborator
Collaborator

Thanks, I'll look at that as it might be handy to be able to select items and bring them with me to L0.
Turns out I'm just missing an end bracket as someone picked up when I posted the whole MyStuff.lsp.

You guys are the best.

www.ausaca.blogspot.com
Do you know all about the Roof Object? Learn it's secrets
http://ausaca.blogspot.com.au/p/roof-object-video-links.html
0 Likes
Message 14 of 20

paullimapa
Mentor
Mentor

you are welcome and I would not bother with VLIDE but jump right into what Autodesk now supports as VS Code:

https://help.autodesk.com/view/ACDLT/2024/ENU/?guid=GUID-7BE00235-5D40-4789-9E34-D57685E83875

Also install the following VS Code Extensions:

paullimapa_0-1736557673716.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 15 of 20

Kent1Cooper
Consultant
Consultant

@stev98312 wrote:

Will this work for you?

  ; put pre-selected object(s) [if any] on Layer 0, otherwise set current Layer to 0

That's my code, from >here<, except that I [coincidentally] used the same command name L0 that this Topic's OP uses.  I thought of posting it as part of my earlier suggestion, but the changing of objects to that Layer didn't seem part of what they want to do, so I included only its no-pre-selection 'else' argument.

Kent Cooper, AIA
Message 16 of 20

stev98312
Enthusiast
Enthusiast

I usually put code author credits in headers and I forgot where I got this one.

Header info added above to give proper credit.

 

Steve

Message 17 of 20

ntellery
Collaborator
Collaborator

Brilliant thanks. Visual Studio Code installed with Alisp extension.
I was just looking at learning C and into C++ and was wondering what ?compiler? coder? to use.
This will do perfectly.

www.ausaca.blogspot.com
Do you know all about the Roof Object? Learn it's secrets
http://ausaca.blogspot.com.au/p/roof-object-video-links.html
0 Likes
Message 18 of 20

paullimapa
Mentor
Mentor

you're welcome once again...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 19 of 20

Sea-Haven
Mentor
Mentor

When using Notepad++ I take it you have the LISP option ticked on under Language, when you place the mouse say at a starting bracket it should turn red scrolling down should reveal the matching closing bracket, I always check the starting Defun bracket and end of defun if no match go looking. 

SeaHaven_0-1736635354471.png

 

The other thing is you can load under Plugins the "ActiveX" plugin it allows you to run the lisp code in the editor. 

 

 

Message 20 of 20

ntellery
Collaborator
Collaborator

Thanks, I was not aware of those options but lisp is ticked so maybe I did.
I've installed ActiveX.

MyStuff.lsp was working fine until it didn't so I assume I removed that bracket and broke it sometime back. 
rookie error.

www.ausaca.blogspot.com
Do you know all about the Roof Object? Learn it's secrets
http://ausaca.blogspot.com.au/p/roof-object-video-links.html
0 Likes