error: autocad variable setting rejected "clayer" "0-wndr"

error: autocad variable setting rejected "clayer" "0-wndr"

HAS140
Explorer Explorer
5,873 Views
13 Replies
Message 1 of 14

error: autocad variable setting rejected "clayer" "0-wndr"

HAS140
Explorer
Explorer

Im receiving the above referenced error on a lisp routine, which up until now, I have never experienced. Its a routine to insert doors into a drawing. The routine previously allowed doors to be inserted on any layer named *-wndr.  (see attached pic of dialog box generated by the lisp, note the message at the top of the dialog box regarding "*-WNDR" layer) It will now only insert on "0-wndr" layer.  If I go in the code and rename "wndr" (toward the bottom of the script) the same error comes up with the new layer name I assign it, essentially looking for the '0". I don't know what changed (I did not make any edits to the routine).  Here is the code. 

Thank you in advance.

 

Here is the code:

;===================================================================================;
; Error Handler Function ;
;===================================================================================;
(defun drerr (errormsg) ; If an error (such as CTRL-C) occurs
; while this command is active...
(if (/= errormsg "bad argument type: lselsetp nil")
(alert (strcat "\nError: " errormsg))
(alert "Error: Failure in wall/point selections.")
)
(setvar "osmode" orOSMODE)
(setvar "pickbox" orPICKBOX)
(setvar "aperture" orAPERTURE)
(setvar "cecolor" curCOLOR)
(command "undo" "end")
(princ)
(setq *error* olderr) ; restore old *error* handler
(princ)
)

;===================================================================================;
; Main Program ;
;===================================================================================;


(defun c:dr (/
dcl_id
what_next
)
(setq dcl_id (load_dialog "dr.dcl"))
(new_dialog "dr" dcl_id)

(action_tile "H" "(progn (mode_tile \"OFFCORN\" 0)(setq insert \"h\")(set_tile \"C\" \"0\"))")

(action_tile "C" "(progn (mode_tile \"OFFCORN\" 1)(setq insert \"c\")(set_tile \"H\" \"0\"))")

;(action_tile "OFFCORN" "(if (not (numberp offcorn))(progn(set_tile \"error\" \"Must be a real number > 0.\")(mode_tile \"OFFCORN\" 2)))")

(action_tile "DRSIZE" "(setq drsize (atof (get_tile \"DRSIZE\")))")

;(action_tile "LEAFANGLE" "(setq leafangle (get_tile \"LEAFANGLE\"))")

(action_tile "LEAFANGLE" "(progn (setq leafangle (get_tile \"LEAFANGLE\"))(set_tile \"slider_value\" leafangle))")

(action_tile "pickpoints" "(done_dialog 4)")
(if (null doortype)(progn (set_tile "S" "1")(setq doortype "s")))
(if (null insert)(progn (set_tile "H" "1")(setq insert "h")))
(if (not (null offcorn))(set_tile "OFFCORN" (rtos offcorn))(progn(set_tile "OFFCORN" "6")(setq offcorn 6)))
(if (not (null drsize))(set_tile "DRSIZE" (rtos drsize))(progn(set_tile "DRSIZE" "30")(setq drsize 30)))
;(if (null leafangle)(setq leafangle"45"))
(if (not (null leafangle))(set_tile "LEAFANGLE" leafangle)(setq leafangle"45"))
(set_tile "slider_value" leafangle)
(if (= doortype "d")(set_tile "D" "1")(set_tile "S" "1"))
(if (= insert "c")(progn (set_tile "C" "1")(set_tile "H" "0")(mode_tile "OFFCORN" 1)))
(if (= insert "h")(progn (set_tile "H" "1")(mode_tile "OFFCORN" 0)(set_tile "C" "0")))
(if (and (= insert "h")(null offcorn))(mode_tile "OFFCORN" 2))

(setq what_next (start_dialog))
(cond
((= what_next 4)
(getpnts)
)
((= what_next 0)
(prompt "\nuser cancelled dialog")
)

)

(unload_dialog dcl_id)
)

(defun getpnts (/ StartPt DirPt Ang oppo hypo
wallthickness HP1 HP2 LP1
wall_lay Tsset Tline2 Trm1 Trm2 Cpoint Hpt
ANG2 layprefix door_lay blockname mirror
xscale curCOLOR in_ang l Ang
)
(setq olderr *error* *error* drerr)
(setvar "cmdecho" 0)
(command "undo" "begin")
; save system variables ;
(setq orAPERTURE (getvar "aperture")
orPICKBOX (getvar "pickbox")
orOSMODE (getvar "osmode")
curLAYER (getvar "clayer")
curCOLOR (getvar "cecolor")
)
; get door points and angles ;


(if (= insert "h")
(progn
(setvar "osmode" 33)
(setq StartPt (getpoint "\nPick corner closest to the hinge: "))
(setvar "osmode" 512)
(setq DirPt (getpoint "\nPick a point on wall toward latch: "))
(setq oppo (getpoint "\nPick a point on wall face opposite the hinge/latch:"))
(setq Ang (angle StartPt DirPt)
Ang2 (angle StartPt oppo)
Hypo (distance StartPt oppo)
HP1 (polar StartPt Ang offcorn)
LP1 (polar HP1 Ang drsize)
))
(progn
(setvar "osmode" orOSMODE)
(setq Cpoint (getpoint "\nPick the center point of opening on hinge/latch face of wall:"))
(setvar "osmode" 33)
(setq HPt (getpoint "\nPick a point close to either hinge: "))
(setvar "osmode" 512)
(setq oppo (getpoint "\nPick a point on wall face opposite the hinges:"))
(setq Ang (angle HPt Cpoint)
Ang2 (angle HPt oppo)
Hypo (distance HPt oppo)
HP1 (polar Cpoint (+ Ang pi)(/ drsize 2))
LP1 (polar HP1 Ang drsize)
)
)
)
(if (or(< Ang2 Ang)(and (< Ang (/ pi 2))(> Ang2 (* (/ 3 2) pi))))

(setq perpAng (- Ang (/ pi 2)) mirror 1))

(if (or(> Ang2 Ang)(and(< Ang2 (/ pi 2))(> Ang (* (/ 3 2) pi))))

(setq perpAng (+ Ang (/ pi 2)) mirror (- 0 1)))

(setq wallthickness (* hypo (sin (abs (- Ang Ang2)))))
; create opening points ;
; (setq HP1 (polar StartPt Ang offcorn)
; LP1 (polar HP1 Ang drsize)
;
; )
; draw and trim the opening ;
(setq sswall (ssget oppo))
(setq wall_lay (cdr (assoc 8 (entget (ssname sswall 0)))))
(setvar "clayer" wall_lay)
(setvar "pickbox" 1)
(setvar "aperture" 1)
(command "color" "bylayer")
(command "line" HP1 "per" oppo "")
(setq Tsset (ssget "L"))
(command "line" LP1 "per" oppo "")
(setq Tline2 (entlast))
(ssadd Tline2 Tsset)
(setq Trm1 (polar HP1 Ang (/ drsize 2)))
(setq Trm2 (polar Trm1 perpAng wallthickness))

(command "trim" Tsset "f" "" Trm1 Trm2 "")
; insert the door block ;
(setq layprefix (substr wall_lay 1 1))
(setq door_lay (strcat layprefix "-wndr"))
(setvar "clayer" door_lay)
(command "color" "10")

(if (= doortype "s")
(setq blockname (strcat "dr-" leafangle))
(setq blockname (strcat "2dr-" leafangle))
)

(setq xscale (* mirror drsize))
(if (= mirror -1)
(setq in_ang (+ Ang pi))
(setq in_ang Ang)
)
(setq in_ang (atof (angtos in_ang 0 4)))
(command "-insert" blockname HP1 xscale drsize in_ang)

; release selection set memory ;
(setq Tsset nil
sswall nil
Tline2 nil
)
; reset system variables ;
(setvar "osmode" orOSMODE)
(setvar "pickbox" orPICKBOX)
(setvar "aperture" orAPERTURE)
(setvar "clayer" curlayer)
(setvar "cecolor" curCOLOR)
(command "undo" "end")
(princ)
) ;end defun

0 Likes
Accepted solutions (1)
5,874 Views
13 Replies
Replies (13)
Message 2 of 14

chriscowgill7373
Advisor
Advisor

I'm trying to step through your code to find out what the error is, can you provide all the parts and pieces so that I can successfully run the code?  when I call the DR command, I'm getting a message:

 

user cancelled dialognil


Christopher T. Cowgill, P.E.

AutoCAD Certified Professional
Civil 3D Certified Professional
Civil 3D 2024 on Windows 10

Please select the Accept as Solution button if my post solves your issue or answers your question.

0 Likes
Message 3 of 14

HAS140
Explorer
Explorer

Thank you! I have attached a zip file containing what I believe is to be all off the necessary files.

 

0 Likes
Message 4 of 14

chriscowgill7373
Advisor
Advisor

stepping through makes it a whole lot easier.  You are setting the current layer to a layer that does not exist within the file you are working in.  You should modify your program to check to see if the layer exists prior to setting it current, and if not, create the layer.


Christopher T. Cowgill, P.E.

AutoCAD Certified Professional
Civil 3D Certified Professional
Civil 3D 2024 on Windows 10

Please select the Accept as Solution button if my post solves your issue or answers your question.

0 Likes
Message 5 of 14

HAS140
Explorer
Explorer

if I understand you correctly, you are suggesting that the "0-wndr" layer is non-existent and/or not current?

Before I had this issue, the lisp would insert the door on my A-WNDR layer which is pre-set in my .dwt file and the layer did not have to be current. I don't know how this changed in the code, I didn't touch the script. So confused

0 Likes
Message 6 of 14

chriscowgill7373
Advisor
Advisor

The program calls to set the A-WNDR layer current, it doesnt matter what the current layer is when you start the program, if the A-WNDR layer does not exist in the file, then it cant set it current, which is the reason for the error message.  Did your template file change in the new version?

 


Christopher T. Cowgill, P.E.

AutoCAD Certified Professional
Civil 3D Certified Professional
Civil 3D 2024 on Windows 10

Please select the Accept as Solution button if my post solves your issue or answers your question.

0 Likes
Message 7 of 14

HAS140
Explorer
Explorer
Do you mean the program calls to set it to 0-WNDR layer? It's not going on to my A-WNDR layer that is preset in my dwg. This is my issue. Where in the script is saying this? As I stated earlier, prior to this problem the door would be placed on any layer ending in *-WNDR and now it's forcing it to go on 0-WNDR... can you see anywhere in the script where it can be changed not look for the 0 to be in the layer?
0 Likes
Message 8 of 14

chriscowgill7373
Advisor
Advisor
Accepted solution

Your program determines the layer of the wall you select

It then strips out the rest of the name, except for the first character

It then combines that first character with the WNDR

It then sets that layer current

It then inserts the door block

It then resets all the variables back to their default values.

There is no provision for if the layer does not exist.

If the wall you select is on a layer called 0 or 0-WALL the layer the program is going to look for is going to be 0-WNDR

If that layer does not exist, your program will fail.

 

So, in your test file, what layer is your wall on?

 

In my file the wall is on A-WALL

The program strips it down to A

Then adds A-WNDR

I'm using the default template with no layers established

I error out with "error: autocad variable setting rejected "clayer" "A-wndr"

If I add the A-WNDR to my file, it works as designed

Short of having inadequate error checking in the program, the program works as it should.


Christopher T. Cowgill, P.E.

AutoCAD Certified Professional
Civil 3D Certified Professional
Civil 3D 2024 on Windows 10

Please select the Accept as Solution button if my post solves your issue or answers your question.

0 Likes
Message 9 of 14

HAS140
Explorer
Explorer
Now, that makes sense! Thank you so much for that clarification. And of course thank you for taking the time to look at this. I greatly appreciate that. I originally was trying to insert a door on somebody else's drawing and we layer nomenclature wasn't my own which is when I experienced the initial error. I then tried it on a clean drawing but was trying it on walls created on the Zero layer. For my own drawings I have always inserted doors in walls on a-wall layers. I left my office so I will give it a try in the morning. Thank you again for your help!
0 Likes
Message 10 of 14

chriscowgill7373
Advisor
Advisor

No problem.  I'll be around tomorrow when you get back in if you have any questions.


Christopher T. Cowgill, P.E.

AutoCAD Certified Professional
Civil 3D Certified Professional
Civil 3D 2024 on Windows 10

Please select the Accept as Solution button if my post solves your issue or answers your question.

0 Likes
Message 11 of 14

HAS140
Explorer
Explorer
Again, thank you for time. I'll let you know how it goes!
0 Likes
Message 12 of 14

HAS140
Explorer
Explorer

yep. All is good. Thanks again. While I have you though, there is a slight issue with one door insertion. Cant get it to properly cut in a door in a wall in X axis, with the hinge side on the top left and swinging up toward the Y axis.

It cuts the door in with the hinge on the top left, but swings the door down toward the Y axis.  All other doors work fine. I have attached a pic, see the door with the cloud.  Can you see anything in the script that would cause this?

0 Likes
Message 13 of 14

chriscowgill7373
Advisor
Advisor

can you provide your test drawing? that shows the door not working?


Christopher T. Cowgill, P.E.

AutoCAD Certified Professional
Civil 3D Certified Professional
Civil 3D 2024 on Windows 10

Please select the Accept as Solution button if my post solves your issue or answers your question.

0 Likes
Message 14 of 14

HAS140
Explorer
Explorer

sure thing, see attached

0 Likes