AJRight Posted May 6, 2013 Posted May 6, 2013 Hey guys, as the title suggests, I need to restrict access to particular lisps we are testing for use across the office however, during this "testing" phase only certain users are permitted to run this routine. Currently in the code posted below (I am "ajr") it keeps passing a false value on the user check. I think I am on the right track but, I can't figure out why I am still getting a false value. Any ideas? Any help is appreciated as always and thanks ahead of time. (defun c:lolwat (/ X blk ) (cond (= "ajr" (getvar "loginname")) (initget 1 "Yes NO") (setq ansr (getkword "\nIs this a UT Job? <Yes or NO>:")) (cond (= ansr "NO") (GON) (GFRS) (command "qsave" ) (GON) ;FOR UT JOBS ONLY PER TLD REQUEST (GDSTRY) ;FOR UT JOBS ONLY PER TLD REQUEST );;cond (GON) (GFRS) (command "qsave" ) ;(GON) ;(GDSTRY) (foreach x (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "INSERT") (410 . "MODEL"))))) (setq blk (cdr (assoc 2 (entget x)))) (if (assoc 1 (tblsearch "block" blk)) (command "_.xref" "_bind" blk)) );;; end foreach (princ) (command "-layer" "s" "0" "") (command "-purge" "all" "" "N" "") (command "audit" "y") (command "zoom" "e") (PDF) (command "saveas" "" (strcat "c:\\Record_Drawings\\" (getvar "dwgname"))) (prompt "\n Drawings Prepared. Check Output Folder.") (princ) );;; cond (prompt "\n Are you sure you should be using this?") (prompt "\n Access Denied.") (princ) );;defun Quote
Tharwat Posted May 6, 2013 Posted May 6, 2013 The loginname is case-sensitive so e.g Ajr is not the same as ajr besides that , you need to add one more paren for the cond function and of course don't forget to close this paren in its correct location (cond [color=red][b]([/b][/color](= "ajr" (getvar "loginname")) Quote
AJRight Posted May 6, 2013 Author Posted May 6, 2013 DUH! Wow I really should have seen that. Something so simple... Thank you Tharwat my good sir. Quote
alanjt Posted May 6, 2013 Posted May 6, 2013 So, is anything supposed to happen if the user says yes? Quote
Tharwat Posted May 6, 2013 Posted May 6, 2013 DUH! Wow I really should have seen that. Something so simple... Thank you Tharwat my good sir. You're welcome Quote
AJRight Posted May 6, 2013 Author Posted May 6, 2013 So, is anything supposed to happen if the user says yes? Good point. Hadn't tried it yet. I see I am missing more. My gosh this is sloppy. Its a dirty adaptation of a routine I already made and apparently its a lot dirtier than I originally thought. Quote
Tharwat Posted May 6, 2013 Posted May 6, 2013 Good point. Hadn't tried it yet. I see I am missing more. My gosh this is sloppy. Its a dirty adaptation of a routine I already made and apparently its a lot dirtier than I originally thought. What does that guy (gosh function) do ? Quote
AJRight Posted May 6, 2013 Author Posted May 6, 2013 It allows one to make quick archive files and PDFs for clients. It gets rid of any grease on the drawings, binds all the xrefs, purges, audits, does a save as, and PDFs the drawing. Now that I have this sort of working I am noticing I can't get the true scenario not to display the false answer. For example if you look at the code in the original post it always displays the deny message even though the condition was met. I know its because the exiting paren for the defun is after it but, I don't know where to put the deny message where it won't display if the condition is true. Quote
alanjt Posted May 6, 2013 Posted May 6, 2013 (edited) Good point. Hadn't tried it yet. I see I am missing more. My gosh this is sloppy. Its a dirty adaptation of a routine I already made and apparently its a lot dirtier than I originally thought. (defun c:test (/ ansr) (if (= "ajr" (getvar "loginname")) (progn (initget 1 "Yes No") (setq ansr (getkword "\nIs this a UT Job? [Yes/No]:")) (cond ((eq ansr "No") ;; DO STUFF ) ((eq ansr "Yes") ;; DO STUFF ) ) ) (princ "\n Are you sure you should be using this?\n Access Denied.") ) (princ) ) Edited May 6, 2013 by alanjt Quote
Tharwat Posted May 6, 2013 Posted May 6, 2013 Maybe this would be more accurate since that it is case-sensitive . (= (strcase "ajr") (strcase (getvar "loginname"))) Quote
alanjt Posted May 6, 2013 Posted May 6, 2013 Maybe this would be more accurate since that it is case-sensitive . (= (strcase "ajr") (strcase (getvar "loginname"))) (= "AJR" (strcase (getvar "loginname"))) Quote
BlackBox Posted May 6, 2013 Posted May 6, 2013 (defun c:test (/ ansr) (if (= "ajr" (getvar "loginname")) (progn (initget 1 "Yes No") (setq ansr (getkword "\nIs this a UT Job? [Yes/No]:")) ) (cond ((eq ansr "No") ;; DO STUFF ) ((eq ansr "Yes") ;; DO STUFF ) ) (princ "\n Are you sure you should be using this?\n Access Denied.") ) (princ) ) ; error: too many arguments: (IF (= "ajr" (GETVAR "loginname")) (PROGN (INITGET 1 "Yes No") (SETQ ANSR (GETKWORD "\nIs this a UT Job? [Yes/No]:"))) (COND ((EQ ANSR "No")) ((EQ ANSR "Yes"))) (PRINC "\n Are you sure you should be using this?\n Access Denied.")) _$ This is how I might approach this: (defun c:FOO (/ option) (if (= "AJR" (strcase (getvar 'loginname))) (progn (initget "Yes No") (cond ((or (setq option (getkword "\nIs this a \"UT\" Job [Yes/No]<Yes>: ") ) (setq option "Yes") ) ;;<-- user entered yes, or right clicked / hit enter ) ((= option "No") ;;<-- user entered no ) ) ) (prompt "\n** Access Denied **") ) (princ) ) Quote
alanjt Posted May 6, 2013 Posted May 6, 2013 ; error: too many arguments: (IF (= "ajr" (GETVAR "loginname")) (PROGN (INITGET 1 "Yes No") (SETQ ANSR (GETKWORD "\nIs this a UT Job? [Yes/No]:"))) (COND ((EQ ANSR "No")) ((EQ ANSR "Yes"))) (PRINC "\n Are you sure you should be using this?\n Access Denied.")) _$ This is how I might approach this: (defun c:FOO (/ option) (if (= "AJR" (strcase (getvar 'loginname))) (progn (initget "Yes No") (cond ((or (setq option (getkword "\nIs this a \"UT\" Job [Yes/No]<Yes>: ") ) (setq option "Yes") ) ;;<-- user entered yes, or right clicked / hit enter ) ((= option "No") ;;<-- user entered no ) ) ) (prompt "\n** Access Denied **") ) (princ) ) Baaaaah, farts. I had my progn paren in the wrong place. *fixed* FYI (or (setq option (getkword "\nIs this a \"UT\" Job [Yes/No] <Yes>: ") ) (setq option "Yes") ) will always return T. Could be one this way (progn) only required if more than one line for that portion, of course. (initget 0 "Yes No") (if (eq (setq option (getkword "\nIs this a \"UT\" Job [Yes/No] <Yes>: ")) "No") (progn ;; blah blah for NO ) (progn ;; blah blah for nil or YES ) ) Quote
BlackBox Posted May 6, 2013 Posted May 6, 2013 FYI (or (setq option (getkword "\nIs this a \"UT\" Job [Yes/No] <Yes>: ") ) (setq option "Yes") ) will always return T. Could be one this way (progn) only required if more than one line for that portion, of course. (initget 0 "Yes No") (if (eq (setq option (getkword "\nIs this a \"UT\" Job [Yes/No] <Yes>: ")) "No") (progn ;; blah blah for NO ) (progn ;; blah blah for nil or YES ) ) Too funny... I ripped that from another routine's IF statement (which then CONDitionally acted, allowing for Yes/Nil or No)... Not really sure why I nested it within the COND statement. Original snippet culled: ;; snip (initget "Yes No") (if (or (setq option (getkword "\nAre bowties cool [Yes/No]<Yes>: ") ) (setq option "Yes") ) (cond ((= option "Yes") ;;<-- user entered yes, or right clicked / hit enter ) ((= option "No") ;;<-- user entered no, fire them ) ) ) ;; snip ... I've always been partial to COND, but I might like your adaptation better. Quote
AJRight Posted May 6, 2013 Author Posted May 6, 2013 Should have been paying more attention to my Emails..... I have been bashing my head against the desk following some of the suggestions because I kept getting what BlackBox already pointed out "too many arguments". I am just learning to try and encorporate cond into my code more as per a suggesstion made by a co-worker and from reading several threads. So I'm not overly familiar with its syntax thus why I had so much trouble earlier. But, thank you all so much for your help. I'll make the changes again and post the revised code. Thanks again! Quote
AJRight Posted May 6, 2013 Author Posted May 6, 2013 It works! Thanks guys for all your help. Now I just need to build a list of user initials that are allowed that can be updated externally from this routine. Perhaps I can make another routine that this routine we have been working on will load and check the passed value. Here's the working code (setvar "CMDECHO" 0) (setvar "BINDTYPE" 0) (defun c:lolwat (/ X blk ansr ) (if (= "TLD" (strcase (getvar 'loginname))) (progn (initget "Yes No yes no YES NO") (cond ((or (setq option (getkword "\nIs this a \"UT\" Job [Yes/No]<NO>: ") );;; set q (setq option "NO") ;;<-- user entered no, or right clicked / hit enter (GON) (GFRS) (command "._qsave" ) (GON) ;FOR UT JOBS ONLY PER TLD REQUEST (GDSTRY) ;FOR UT JOBS ONLY PER TLD REQUEST );;; no - ansr );;; 1st paren OR ((= option "YES") (GON) (GFRS) (command "._qsave" ) (GON) (GDSTRY) );;; yes - ansr (princ "TEST") );;; cond (foreach x (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "INSERT") (410 . "MODEL"))))) (setq blk (cdr (assoc 2 (entget x)))) (if (assoc 1 (tblsearch "block" blk)) (command "_.xref" "_bind" blk)) );;; end foreach (princ) (command "-layer" "s" "0" "") (command "-purge" "all" "" "N" "") (command "audit" "y") (command "zoom" "e") (PDF) (command "saveas" "" (strcat "c:\\Record_Drawings\\" (getvar "dwgname"))) (prompt "\n Drawings Prepared. Check Output Folder.") (princ) );;; progn (prompt "\n Are you sure you should be using this?\n **Access Denied **") ) ;;; if (princ) );;; defun Quote
neophoible Posted May 7, 2013 Posted May 7, 2013 It works! Are you sure it works the way you intend? It looks to me like you will always fulfill the OR condition for "NO" (and never get to "YES"), because (setq option "NO") is always non-nil. Also, even if you had your parentheses different for the or, it looks like you would be doing the following in either case, YES or NO: (GON) (GFRS) (command "._qsave" ) (GON) (GDSTRY) And is there some language reason that you don't just use the much simpler "Yes No" version in the initget like was shown above? It would cover the entire gambit of full & partial Yes & No entries, but always return only "Yes", "No" or nil. Quote
AJRight Posted May 7, 2013 Author Posted May 7, 2013 (edited) Are you sure it works the way you intend? It looks to me like you will always fulfill the OR condition for "NO" (and never get to "YES"), because is always non-nil. I haven't messed with it today but I should take that setq out and just put another conditional statement like ; snip ((= option "NO" ) ; do something ) ;snip Also, even if you had your parentheses different for the or, it looks like you would be doing the following in either case, YES or NO: Again, you're right. I need to remove those last two calls from the yes condition. And is there some language reason that you don't just use the much simpler "Yes No" version in the initget like was shown above? It would cover the entire gambit of full & partial Yes & No entries, but always return only "Yes", "No" or nil. No, I had no idea that was the case. I guess that is what I get for following somewhat dated tutorials while learning LISP. Thanks for clarifying Edited May 7, 2013 by AJRight Had to move code tags around Quote
neophoible Posted May 7, 2013 Posted May 7, 2013 BTW, FWIW, I like cond statements because you can do things like this: (cond ( (not (member (strcase (getvar 'loginname)) list_of_valid_names)) (prompt "\n Are you sure you should be using this?\n **Access Denied **") ) ; handle invalid user first ( (initget “Yes No”) ) ; always returns nil ( (= “Yes” (getkword "\nIs this a \"UT\" Job [Yes/No] <No>: ")) ; Do YES stuff ) ; check hard value first (T ; only thing left is “No”/nil, both=NO ; Do NO stuff ) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.