Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP Error - Can you help?

18 REPLIES 18
Reply
Message 1 of 19
Anonymous
764 Views, 18 Replies

LISP Error - Can you help?

Can anyone tell me what is wrong with my LISP routine? I have been banging my head trying to find the error, but cant. The error I am getting is :"error: AutoCAD variable setting rejected: "osmode" nil". The error occurs when CLR is initiated.

LISP is:

(defun GCL ()
(setq OSM (getvar "osmode"))
(setq CLY (getvar "clayer"))
)

(defun OFF ()
(setq OSM (getvar "osmode"))
(setvar "osmode" 0)
)

(defun CLR ()
(setvar "osmode" OSM)
(setvar "clayer" CLY)
)

(defun PT ()
(setq PT1 (getvar "lastpoint"))
)

Thank you greatly in advance for your help.
18 REPLIES 18
Message 2 of 19
mid-awe
in reply to: Anonymous

Try it this way instead:
[code]
(defun CLR ()
(IF (/= (GETVAR "OSMODE") OSM)
(SETVAR "OSMODE" OSM)
)
(IF (/= (GETVAR "CLAYER") CLY)
(SETVAR "CLAYER" CLY)
)
)
[/code]
Message 3 of 19
Anonymous
in reply to: Anonymous

In the CLR routine, where are you setting a value for the variable OSM,
before you attempt to use the variable?

All the functions you posted look like subroutines. Where is the command
function?

--
R. Robert Bell


wrote in message news:5389226@discussion.autodesk.com...
Can anyone tell me what is wrong with my LISP routine? I have been banging
my head trying to find the error, but cant. The error I am getting is
:"error: AutoCAD variable setting rejected: "osmode" nil". The error occurs
when CLR is initiated.

LISP is:

(defun GCL ()
(setq OSM (getvar "osmode"))
(setq CLY (getvar "clayer"))
)

(defun OFF ()
(setq OSM (getvar "osmode"))
(setvar "osmode" 0)
)

(defun CLR ()
(setvar "osmode" OSM)
(setvar "clayer" CLY)
)

(defun PT ()
(setq PT1 (getvar "lastpoint"))
)

Thank you greatly in advance for your help.
Message 4 of 19
Anonymous
in reply to: Anonymous

They are contained in the menu file. I have created image menus, and each of these subcommands are to be used within the image menu definitions. For example, this menu item inserts a detail bubble with attributes as well as a detail line at the same insertion point as the detail bubble. I wanted it to turn off osnaps, set the correct layer, insert the blocks, then reset the osnap and layer settings.

(GCL)(OFF)^C^C-layer;m;NOTES;color;2;;;-i;m:/_blocks/text/detail_bubble_line;\1;1;\-i;m:/_blocks/text/detail_bubble;(PT);1;1;0;\\(CLR)
Message 5 of 19
Anonymous
in reply to: Anonymous

I get this error:

error: AutoCAD variable setting rejected: "OSMODE" nil
Message 6 of 19
Anonymous
in reply to: Anonymous

It sounds a lot like the variable for the current Osnap modes wasn't set
somehow, before it was called for to reset OSMODE. That would make that
variable come back as nil, but it won't let you set OSMODE to nil -- only
numerical values (if Osnap is off, that's zero rather than nil).

Make sure the subroutine that sets that variable has been run before this
one that's trying to use it.

--
Kent Cooper


wrote...
I get this error:

error: AutoCAD variable setting rejected: "OSMODE" nil
Message 7 of 19
Anonymous
in reply to: Anonymous

In any of the menu definitions, the GCL and OFF routines are run first, which is supposed to turn off osnaps (osnaps are typically on at this point), then it runs the series of commands, then runs CLR, which turns the osnaps back on. I tried what MiD-AwE wrote, and I still get the same error. Im not sure what Im doing wrong, do you have any ideas on what I can change to eliminate this error?
Message 8 of 19
Anonymous
in reply to: Anonymous

You need to make sure OSM and CLY are set to a legitimate value. Like:

(defun CLR ()
(IF (AND (NUMBERP OSM) (/= (GETVAR "OSMODE") OSM))
(SETVAR "OSMODE" OSM)
)
(IF (AND CLY (/= (GETVAR "CLAYER") CLY))
(SETVAR "CLAYER" CLY)
)
)
Message 9 of 19
Anonymous
in reply to: Anonymous

But if they're using (getvar) to set them from the System Variables they're
now trying to set back, I'm having a hard time figuring out how they could
be illegitimate values. Unless something else is messing with them in
between...?
--
Kent Cooper


"Allen Johnson" wrote...
You need to make sure OSM and CLY are set to a legitimate value. Like:

(defun CLR ()
(IF (AND (NUMBERP OSM) (/= (GETVAR "OSMODE") OSM))
(SETVAR "OSMODE" OSM)
)
(IF (AND CLY (/= (GETVAR "CLAYER") CLY))
(SETVAR "CLAYER" CLY)
)
)
Message 10 of 19
Anonymous
in reply to: Anonymous

Now I get:

(CLR) nil
Message 11 of 19
mid-awe
in reply to: Anonymous

I'm guessing that you are possibly using a function name as a global variable name elsewhere in you code (anywhere in your acad.lsp, acaddoc.lsp, etc.).

First off, you should set Globals with UNIQUE naming Like *OSM* as the help files suggest. This is because if you happen to have a function named CLR and you attempt to use CLR as a variable name you may get an error. I say "you may" but chances are you will.

I have some similar functions that I wrote for the same purpose, I imagine. If you like, try them: Use (GV) at the beginning of your code to Get Variables, use (SV) at the end of your code to reSet Variables.
[code]
(DEFUN GV () ;GET VARS
(SETQ *CMD* (GETVAR "CMDECHO")
*OSM* (GETVAR "OSMODE")
*OTM* (GETVAR "ORTHOMODE")
*CLY* (GETVAR "CLAYER")
*CLR* (GETVAR "CECOLOR")
*SNA* (GETVAR "SNAPANG")
*TXS* (GETVAR "TEXTSTYLE")
*ATD* (GETVAR "ATTDIA")
*ATR* (GETVAR "ATTREQ")
*PLRM* (GETVAR "POLARMODE")
*SNM* (GETVAR "SNAPMODE")
*PEA* (GETVAR "PEDITACCEPT")
*PLW* (GETVAR "PLINEWID")
*PLG* (GETVAR "PLINEGEN")
*DMS* (GETVAR "DIMSTYLE")
)
(PRINC)
)

(DEFUN SV () ;SET VARS
(IF (/= (GETVAR "OSMODE") *OSM*)
(SETVAR "OSMODE" *OSM*)
)
(IF (/= (GETVAR "ORTHOMODE") *OTM*)
(SETVAR "ORTHOMODE" *OTM*)
)
(IF (/= (GETVAR "CLAYER") *CLY*)
(SETVAR "CLAYER" *CLY*)
)
(IF (/= (GETVAR "CECOLOR") *CLR*)
(SETVAR "CECOLOR" *CLR*)
)
(IF (/= (GETVAR "SNAPANG") *SNA*)
(SETVAR "SNAPANG" *SNA*)
)
(IF (/= (GETVAR "TEXTSTYLE") *TXS*)
(SETVAR "TEXTSTYLE" *TXS*)
)
(IF (/= (GETVAR "attdia") *ATD*)
(setvar "attdia" *ATD*)
)
(IF (/= (GETVAR "AttReq") *ATR*)
(SETVAR "AttReq" *ATR*)
)
(IF (/= (GETVAR "PolarMode") *PLRM*)
(SETVAR "PolarMode" *PLRM*)
)
(IF (/= (GETVAR "SnapMode") *SNM*)
(SETVAR "SnapMode" *SNM*)
)
(IF (/= (GETVAR "PEDITACCEPT") *PEA*)
(SETVAR "PEDITACCEPT" *PEA*)
)
(IF (/= (getvar "PLINEWID") *PLW*)
(SETVAR "PLINEWID" *PLW*)
)
(IF (/= (GETVAR "PLINEGEN") *PLG*)
(SETVAR "PLINEGEN" *PLG*)
)
(IF (/= (GETVAR "DIMSTYLE") *DMS*)
(COMMAND "DIMSTYLE" "R" *DMS*)
)
(IF (/= (GETVAR "CMDECHO") *CMD*)
(SETVAR "CMDECHO" *CMD*)
)
(PRINC)
)
[/code]

Hope this helps.
Message 12 of 19
Anonymous
in reply to: Anonymous

In the context of a menu macro, most of those subroutines are unneeded. I
*wouldn't* advise turning of OSnaps in the macro (the user might want them),
and there is no need for the (pt) routine. Running OSnaps can be overridden
at a prompt using the "NONe" override.

So that leaves only the CLayer save/restore as useful subrs.

(defun i:GetCL () (setq *OrgLayer* (getvar "CLayer")))
(defun i:SetCL () (setvar "CLayer" *OrgLayer*) (setq *OrgLayer* nil))

^C^C(i:GetCL)._-Layer;_make;NOTES;_color;2;;;+
._-Insert;M:/_Blocks/Text/Detail_Bubble_Line;_scale;1\\+
._-Insert;M:/_Blocks/Text/Detail_Bubble;_non;@;1;1;0;\\+
(i:SetCL)

--
R. Robert Bell


wrote in message news:5389247@discussion.autodesk.com...
They are contained in the menu file. I have created image menus, and each
of these subcommands are to be used within the image menu definitions. For
example, this menu item inserts a detail bubble with attributes as well as a
detail line at the same insertion point as the detail bubble. I wanted it
to turn off osnaps, set the correct layer, insert the blocks, then reset the
osnap and layer settings.

(GCL)(OFF)^C^C-layer;m;NOTES;color;2;;;-i;m:/_blocks/text/detail_bubble_line;\1;1;\-i;m:/_blocks/text/detail_bubble;(PT);1;1;0;\\(CLR)
Message 13 of 19
Anonymous
in reply to: Anonymous

Sometimes in my quest for perfection, I make simple things more difficult than they have to be 😉 I never knew the @ symbol referenced the last point. I learn something new every day. And I never thought to simply use the _non command. Thank you for that.

Now I get this error:
(i:SetCL) ; error: AutoCAD variable setting rejected: "CLayer" nil

Does it have anything to do with the nil at the end of the setq string?
Message 14 of 19
Anonymous
in reply to: Anonymous

They could be non-local variables called in other functions, or, in one of his menus, he forgot to set it?
Message 15 of 19
Anonymous
in reply to: Anonymous

(clr) returns the value of the last function. To get a "quiet" exit, add a (princ) at the end:

(defun CLR ()
(IF (AND (NUMBERP OSM) (/= (GETVAR "OSMODE") OSM))
(SETVAR "OSMODE" OSM)
)
(IF (AND CLY (/= (GETVAR "CLAYER") CLY))
(SETVAR "CLAYER" CLY)
)
(PRINC)
)
Message 16 of 19
Anonymous
in reply to: Anonymous

No.

Did you run the i:GetCL routine at the beginning of the macro?

A "safer" version of i:SetCL would be:

(defun i:SetCL () (and *OrgLayer* (setvar "CLayer" *OrgLayer*)) (setq
*OrgLayer* nil) (princ))

--
R. Robert Bell


wrote in message news:5389411@discussion.autodesk.com...
Sometimes in my quest for perfection, I make simple things more difficult
than they have to be 😉 I never knew the @ symbol referenced the last
point. I learn something new every day. And I never thought to simply use
the _non command. Thank you for that.

Now I get this error:
(i:SetCL) ; error: AutoCAD variable setting rejected: "CLayer" nil

Does it have anything to do with the nil at the end of the setq string?
Message 17 of 19
Anonymous
in reply to: Anonymous

Yes. Here is my code:

(i:GetCL)^C^C-layer;m;_NOTES;color;2;;;-i;m:/_blocks/text/detail_bubble_line;_non;\1;1;\-i;m:/_blocks/text/detail_bubble;_non;@;1;1;0;\\(i:SetCL)

All the PRINC changed was that it stopped the "error: AutoCAD variable setting rejected: "CLayer" nil" error from showing, now it only returns: (i:SetCL), but still does not reset the layer.
Message 18 of 19
Anonymous
in reply to: Anonymous

Move the (i:GetCL) beyond the ^C^C.

Also, run (i:GetCL) from the command line, then check to see the variable is
set, e.g.:

Command: !*OrgLayer*


--
R. Robert Bell


wrote in message news:5389486@discussion.autodesk.com...
Yes. Here is my code:

(i:GetCL)^C^C-layer;m;_NOTES;color;2;;;-i;m:/_blocks/text/detail_bubble_line;_non;\1;1;\-i;m:/_blocks/text/detail_bubble;_non;@;1;1;0;\\(i:SetCL)

All the PRINC changed was that it stopped the "error: AutoCAD variable
setting rejected: "CLayer" nil" error from showing, now it only returns:
(i:SetCL), but still does not reset the layer.
Message 19 of 19
Anonymous
in reply to: Anonymous

Moving the (i:GetCL) beyond the ^C^C seemed to do the trick. It all works now!

Thank you all so much for your assistance. I greatly appreciate your help.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report