Jump to content

Cant Find Error In Lisp


Recommended Posts

Guest looseLISPSsinkSHIPS
Posted

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-

 

8)

 

===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===

Posted

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.

Posted

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?)

Posted
...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 :thumbsup:

 

In general though, yes, it is ok to mention other websites - it is not okay to advertise for another website though.

Posted

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

Posted

Tough call.

 

One for the Wishlist: (vla-get-Workspaces (vlax-get-acad-object))

Posted

This is the best I could come up with: :geek:

 

(defun getws ( )
 (vl-directory-files
   (vla-get-WorkSpacePath
     (vla-get-files
       (vla-get-preferences
         (vlax-get-acad-object)))) nil 1))

Posted
This is the best I could come up with: :geek:

 

(defun getws ( )
 (vl-directory-files
   (vla-get-WorkSpacePath
     (vla-get-files
       (vla-get-preferences
         (vlax-get-acad-object)))) nil 1))

yeah, i looked there.:(

Posted
You got the .udl file too then... o:)

yes, complete dead end.

that's why i just put a catch on it.

Posted
yes, complete dead end.

that's why i just put a catch on it.

 

Yeah, good workaround :)

Guest looseLISPSsinkSHIPS
Posted

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-

Posted
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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...