Guest looseLISPSsinkSHIPS Posted September 7, 2009 Posted September 7, 2009 Hi, I wrote this lisp but cant see where its going wrong? What I'm trying to achive is to have AutoCAD check for a workspace by the same name as the target logon name, the laod it if matching, otherwise if not found to then load the default workspace. Thanks- ===CODE STRATS HERE=== (defun C:MYWORKSPACE () (SETQ USR (GETVAR "LOGINNAME")) (if () (progn ; 'then' [test succeeded] (COMMAND "wscurrent" USR) (PRINC (strcat "\nWelcome " USR)) ); end progn (progn ; 'else' [test failed] (COMMAND "wscurrent" "default") (PRINC "\nWelcome, Visitor") ); end progn ); end if ); defun ===CODE ENDS HERE=== Quote
dbroada Posted September 7, 2009 Posted September 7, 2009 I'm not a LISP expert but (IF () looks wrong to me. You have nothing to evaluate. Also, code should be wrapped in the CODE tags found on the advanced reply page. Quote
MarcoW Posted September 7, 2009 Posted September 7, 2009 Hi there, Welcome to the forum !! (Ik ben ook NL maar kan hier geen nederlands schrijven) First of all it would be nice if everybody would use the code tags ie.: (defun C:MYWORKSPACE ( / USR) ; always localise the variables so they are cleared when function ends. Put ";" this before your comments: ;===CODE STRATS HERE=== ~ staRts Then: (if () You have not set what the if function should evaluate, in this case you want to know if there is a workspace that has the same name as the loginname. It should contain the evaluation like: (if (= USR wscurrent) (; after this what to do if true ); until here. (;after this what to do if not true ); until here. );end if. (princ) );end defun. You might want to read the afralisp website www.afralisp.com. (Q: is it okay to mention external websites?) Quote
Tiger Posted September 7, 2009 Posted September 7, 2009 ...You might want to read the afralisp website www.afralisp.com. (Q: is it okay to mention external websites?) Seeing as CadTutor owns Afralisp, I think it's ok In general though, yes, it is ok to mention other websites - it is not okay to advertise for another website though. Quote
alanjt Posted September 7, 2009 Posted September 7, 2009 this is a tough one since i can't see a way to access the available workspaces. right now (after revising) your routine will fail if the workspaces are not available. also, "default" is not a default workspace in autocad. for that, i suppose you could replace it with one of the defaults. however, this will attempt to set the current workspace as the same name as the loginname. if it fails, it will prompt your message of "welcome visitor". you could easily add a (progn (setvar "wscurrent" "one of the defaults") (princ "welcome visitor")) if you really wanted. if the routine is unable to set the wscurrent as the loginname, it just leaves leaves it be. (defun c:test (/) [color=Red] ;; load visual lisp, activex support[/color] (vl-load-com) [color=Red] ;; checks if an error was trapped[/color] (if (vl-catch-all-error-p [color=Red] ;; traps an error on a function[/color] (vl-catch-all-apply [color=Red] ;; you can use setvar instead of command for many things[/color] 'setvar [color=Red] ;; setting "wscurrent" as the "loginname"[/color] (list "wscurrent" (getvar "loginname")) ) ;_ vl-catch-all-apply ) ;_ vl-catch-all-error-p [color=Red] ;; if an error was trapped (unable to set wscurrent as loginname, visitor message displayed[/color] (princ "\nWelcome, Visitor.") [color=Red] ;; wscurrent successfully set as loginname, loginname message displayed[/color] (princ (strcat "\nWelcome, " (getvar "loginname"))) ) ;_ if [color=Red] ;; exit quietly[/color] (princ) ) ;_ defun i've noted the process as i went through it Quote
Lee Mac Posted September 7, 2009 Posted September 7, 2009 Tough call. One for the Wishlist: (vla-get-Workspaces (vlax-get-acad-object)) Quote
Lee Mac Posted September 7, 2009 Posted September 7, 2009 This is the best I could come up with: (defun getws ( ) (vl-directory-files (vla-get-WorkSpacePath (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) nil 1)) Quote
alanjt Posted September 7, 2009 Posted September 7, 2009 This is the best I could come up with: (defun getws ( ) (vl-directory-files (vla-get-WorkSpacePath (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) nil 1)) yeah, i looked there. Quote
Lee Mac Posted September 7, 2009 Posted September 7, 2009 yeah, i looked there. You got the .udl file too then... Quote
alanjt Posted September 7, 2009 Posted September 7, 2009 You got the .udl file too then... yes, complete dead end. that's why i just put a catch on it. Quote
Lee Mac Posted September 7, 2009 Posted September 7, 2009 yes, complete dead end.that's why i just put a catch on it. Yeah, good workaround Quote
Guest looseLISPSsinkSHIPS Posted September 7, 2009 Posted September 7, 2009 Whoh whoh...Information overload, this forum is much more responsive than AutoCAD forum Okay I see there's stuff posted that will assist me greatly, I’ve been to the AfraLISP site before however I'm a newbey at this who customising thing and still trying to get my head around the basics (not just AutoLISP but macros and VBA too). Thanks for all your help- Quote
alanjt Posted September 7, 2009 Posted September 7, 2009 Whoh whoh...Information overload, this forum is much more responsive than AutoCAD forum Okay I see there's stuff posted that will assist me greatly, I’ve been to the AfraLISP site before however I'm a newbey at this who customising thing and still trying to get my head around the basics (not just AutoLISP but macros and VBA too). Thanks for all your help- what else would we be doing, our jobs? nah 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.