Jump to content

Recommended Posts

Posted

I have some code from a previous thread that I have managed to adapt with my little lisp knowledge, it helps me define a startup workspace which I want to run once for every new user to generate a saved version in their loginname. I want to add an IF to check whether this has already been done rather than generate an error message, so in normal programming speak I'd like to say something like:

 

IF workspace (loginname) exists goto SETCURRENT - here is the code I'm using at present in my ACAD.lsp

 

(defun-q mystartup ()
(command "_wscurrent" "SWD Drafting")
(command "_wssave" (getvar "loginname"))

)
;(setq S::STARTUP (append S::STARTUP mystartup))

(command "_wscurrent" (getvar "loginname"))

 

The "SWD Drafting" workspace is not editable as it is in the "Enterprise" so I want users to have an individually named copy they can freely edit. It works but I have to comment out "mystartup" after running it once, I'd like to be able to utilise an IF to jump it.

 

I may be hoping for too much but there are some clever people out there who make it look easy.

 

Thanks. In the meantime I'll keep searching :book:

Posted

Please check the solutions proposed in this discussion. After insert the test to your code:

(if ([color=sienna]IsValidWorkspace [/color](getvar "loginname"))
(setq S::STARTUP (append S::STARTUP mystartup))
)

Posted

Thanks Mircea,

 

I have looked through the suggested post but can't see how I can apply it, the solution appears to be generating a log file and interrogating it, can a log be created without a file open? - I want to apply these settings during CAD startup before any files are open.

 

I can now follow how the IF will be applied from your example but I am struggling to find a way to define the true/false element of the named workspace, e.g. if false (workspace name does not exist) run mystartup else if true set _wscurrent "loginname".

 

I'd welcome any other suggestions.

Posted

I agree that Visual LISP should be able to directly query the Object Model for the available Workspaces (even if that requires iterating each the Main, and Enterprise CUI), all without the need to write to a log file, etc. as the post linked above suggests.

 

Perhaps, this will help:

 

(vl-load-com)

(defun c:SetOrMakeUserWs (/ wsTemplate _WsCurrent user)

 ;; Change this string to be the name of the standard
 ;; workspace to be copied as the user workspace:
 (setq wsTemplate "SWD Drafting")

 ;; _WsCurrent sub-function:
 (defun _WsCurrent (workspace)
   (if (vl-catch-all-error-p
         (vl-catch-all-apply
           'setvar
           (list 'wscurrent workspace)
         )
       )
     nil
     T
   )
 )

 ;;
 ;; Main code:
 ;;
 ;; If you cannot set the user's workspace current
 ;; (meaining it does not exist)
 (if (not (_WsCurrent (setq user (getvar 'loginname))))

   ;; Attempt to set the template workspace current
   (if (_WsCurrent wsTemplate)
     (progn

       ;; If successful, save the template workspace
       ;; as the user workspace
       (command "._wssave" user)

       ;; Now that the user workspace exists, set
       ;; it current
       (_WsCurrent user)
     )
   )
 )
 (princ)
)
(c:SetOrMakeUserWs)

Posted

Thanks RenderMan this works perfectly :celebrate:

 

Can you recommend any good reference books/sites where I can learn more?

Posted

:oops: Oh no! I got carried away.

 

When I run your code from my ACAD.lsp it works but does not save the Quick Access Toolbar from my loaded enterprise. If I _appload within CAD it is interrupted with an error message:

 

CannotSave.jpg

 

When I close this; the code completes and everything is as I want.

 

Any ideas how I might get around this?

 

Thanks.

Posted

Thanks RenderMan this works perfectly :celebrate:

 

:oops: Oh no! I got carried away.

 

When I run your code from my ACAD.lsp it works but does not save the Quick Access Toolbar from my loaded enterprise. If I _appload within CAD it is interrupted with an error message:

 

attachment.php?attachmentid=36016&d=1342617444

 

When I close this; the code completes and everything is as I want.

 

Any ideas how I might get around this?

 

Thanks.

 

Firstly, you're welcome.

 

There are several ways of doing this. The reason you are recieving an error is the result of the system not being fully loaded. Perhaps this would be more successful by running via Script (SCR) instead, given the startup sequence. This however will require that you modify (a copy of) the application icon's target path to include the /b switch (more on startup switches).

 

Application icon's target path, pseudo code:

"[color=red][b]<YourFilePathHere>[/b][/color]\acad.exe" /b "[color=red][b]<YourFilePathHere>[/b][/color]\[color=blue][b]<YourScriptFileName>[/b][/color].scr"

Script, pseudo code:

(load "[color=red][b]<YourFilePathHere>[/b][/color]\[color=blue][b]<YourLispFileName>[/b][/color].lsp")

Can you recommend any good reference books/sites where I can learn more?

 

There are tons of resources to learn from for free such as forums like these, AfraLisp, etc., however, if you want a good book I'd recommend (image is linked):

 

The Visual LISP Developer's Bible

 

[/url]

vldb_cover_2011.JPG?height=320&width=244

Posted

Thanks for your time and input it's really appreciated.

 

I'll work through your suggestions and will feedback how I get on :beer:

Posted

I've looked through your links and set up a test with the /b switch and a script loader.

 

It works as if I manually ran _appload; I get a true copy of the worspace but I get the warning message as previously. I know I can tick the "do not show this again" (which does work) but it's too messy to deploy to all the users and ask them to tick the box, is it possible to disable the warning message?

 

I think we're on a different timezone so I'll do some browsing to see if I can locate a solution, thanks for the book recommendation I'll be getting that for the weekend!

Posted

RenderMan, thank you for the link to that book! I just purchased it ($6, that's it?!) and sent it to my Kindle Fire, my phone and my desktop app on my computer. Could've used the Lending Library for free, but I read a LOT and wanted it at my disposal.

Posted
I've looked through your links and set up a test with the /b switch and a script loader.

 

It works as if I manually ran _appload; I get a true copy of the worspace but I get the warning message as previously. I know I can tick the "do not show this again" (which does work) but it's too messy to deploy to all the users and ask them to tick the box, is it possible to disable the warning message?

 

I think we're on a different timezone so I'll do some browsing to see if I can locate a solution, thanks for the book recommendation I'll be getting that for the weekend!

 

Unfortunately, I am unsure how to best accomplish what you're after. This was one method, but by no means the only. All I can say at this time (as I have little to spare), is to try and deduce (on your setup, or a 'debug' copy of), what is exactly causing this problem... Is it that the workspace being copied only exists within the Enterprise CUI, and saving a copy of is attempting to save to the Enterprise rather than the Main CUI? I am not sure, honestly.

 

RenderMan, thank you for the link to that book! I just purchased it ($6, that's it?!) and sent it to my Kindle Fire, my phone and my desktop app on my computer. Could've used the Lending Library for free, but I read a LOT and wanted it at my disposal.

 

You're very welcome, Lee Roy. :beer:

 

I've previously read David's 2003 edition, then when the 2011 edition came out, I had to buy it. I like his writing style, and I learned a great deal from his book(s).

 

Without entirely hijacking this thread; I did take issue with the fact that the book is only for sale as an eBook (no hardcopy), which prompted a response from David personally, and motivated me to start this thread to say thanks.

 

Again; glad I could help out, and enjoy the book.

Posted

I couldn't locate any way to deactivate the warning, so thinking laterally I will try setting up a cui with a copy of my enterprise workspace as it stands and use that to generate the named version, should avoid the pop up (I hope). It would be good to delete the "Default" workspace after using it for the copy but I can't find a keyboard entry to do this without entering the CUI interface, so I'll keep researching.

 

Thanks again.

Posted

I seem to have got it working now, although some further testing required. I manually copied the enterprise workspace and named it "Default" this applies to "mymenu.cuix" that I will robocopy into the local Users support folder then with some trial and error manipulation of RM's code (see below). The code now checks for the "Default" workspace renames it as the "loginname" and then deletes the original Default workspace. I have added this in to my ACAD.lsp, I no-longer appear to need the .scr method.

 

(vl-load-com)
(defun c:SetOrMakeUserWs (/ wsTemplate _WsCurrent user)
 ;; Change this string to be the name of the standard
 ;; workspace to be copied as the user workspace:
 (setq wsTemplate "Default")
 ;; _WsCurrent sub-function:
 (defun _WsCurrent (workspace)
   (if (vl-catch-all-error-p
         (vl-catch-all-apply
           'setvar
           (list 'wscurrent workspace)
         )
       )
     nil
     T
   )
 )
 ;;
 ;; Main code:
 ;;
 ;; If you cannot set the user's workspace current
 ;; (meaining it does not exist)
 (if (not (_WsCurrent (setq user (getvar 'loginname))))
   ;; Attempt to set the template workspace current
   (if (_WsCurrent wsTemplate)
;;(_WsCurrent wsTemplate)
     (progn
       ;; If successful, save the template workspace
       ;; as the user workspace
       (command "._wssave" user)
       ;; Now that the user workspace exists, set
       ;; it current
       (_WsCurrent user)
(command "._workspace" "delete" "Default" "y")
     )
   )
 )
(princ)
)
(c:SetOrMakeUserWs)

 

:thumbsup:

Posted

Unfortunately further testing proved all was not well, after removing the profile from the registry and re-running CAD as if starting as a new user, showed that none of my defined settings loaded. CAD ignores the /p switch on the shortcut which should trigger the correct acad.lsp to run.

 

Is it me or do others get false results due to remembered registry settings?

 

Oh, well back to the drawing board. :?

  • 1 month later...
Posted
I agree that Visual LISP should be able to directly query the Object Model for the available Workspaces (even if that requires iterating each the Main, and Enterprise CUI), all without the need to write to a log file, etc. as the post linked above suggests.

 

Perhaps, this will help:

 

(vl-load-com)

(defun c:SetOrMakeUserWs (/ wsTemplate _WsCurrent user)

 ;; Change this string to be the name of the standard
 ;; workspace to be copied as the user workspace:
 (setq wsTemplate "SWD Drafting")

 ;; _WsCurrent sub-function:
 (defun _WsCurrent (workspace)
   (if (vl-catch-all-error-p
         (vl-catch-all-apply
           'setvar
           (list 'wscurrent workspace)
         )
       )
     nil
     T
   )
 )

 ;;
 ;; Main code:
 ;;
 ;; If you cannot set the user's workspace current
 ;; (meaining it does not exist)
 (if (not (_WsCurrent (setq user (getvar 'loginname))))

   ;; Attempt to set the template workspace current
   (if (_WsCurrent wsTemplate)
     (progn

       ;; If successful, save the template workspace
       ;; as the user workspace
       (command "._wssave" user)

       ;; Now that the user workspace exists, set
       ;; it current
       (_WsCurrent user)
     )
   )
 )
 (princ)
)
(c:SetOrMakeUserWs)

 

Hi RenderMan

 

I'm doing some more vlisp and I'm trying to get my head around the formatting as I want to create another 'IF' scenario, e.g. IF profile iscurrent THEN FINISH else IMPORT and setcurrent.

 

I have chunks of code cobbled together from various threads for each stage I want to achieve and have adapted them ok, I just need to work out how to control them with 'IF'. From my description you can probably guess I do a lot of Batch scripting, it would be great if you could explain how each of your code lines (above) work so I can begin to understand better, for example you have a line noted as Nil followed by T what do these represent?

 

Hope you can spare some time for the definitions, many thanks.

Posted

Update to original Query:

 

I Eventually got this to work using RenderMan's original suggestion of a Script to fire up the Lisp, however I also had to use some batch files to preload a default profile into the registry otherwise it just didn't want to run the shortcut path. My batch file merges the profile once for a new user to set the process in place and deletes it from the local source after, next time the user logs in the batch can't find the source file so jumps past the registry merge. It works for me don't know how others have resolved this, I'm sure as I learn more I'll find a neater way.

:)

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