Looking for help on a lisp that will look to see who logged in on the computer to set that persons workspace layout. So if the current workspace does not match the username it will change it to the correct work space but if the workspace is correct then it will do nothing. I really hope this is possible.
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Start with the WSCURRENT system variable. Note that you can't get a list of *available* workspace names (based on current Enterprise and Main CUIx files), so trying to set a workspace that doesn't exist may fail. You should consider how to handle that as well.
So lets say I want it to check to make sure JARRED is set to the current workspace and if it isn't change it to JARRED. How do I store the data that comes from WSCURRENT command so I can check to make it match? I am new at this so I probably over thinking it.
Writing LISP is very similar to doing it manually - first work out the steps (I frequently do it as code comments) then write the LISP to meet the steps:
- get current user ID
- get current workspace
- if current user ID isn't the workspace name
- change the current workspace
If you aren't familiar with them I'd suggest looking up the following functions: 'setq', 'getvar', and 'if'. If you are, lets see the code you have so far and where the stumbling point is.
Minor point - WSCURRENT is a system variable, not a command. System variables store values, in some cases they are read-only and in others they can be changed. Commands tell AutoCAD to do something and the results aren't always directly returned as useable values.
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
The software is on the computer. My main reason I am trying to get a lisp to find out what workspace is being used is because I am sharing my PROFILE file with another coworker to up date his tool palette groups. So each day when he opens up CAD I have a lisp set up to change work space to his because I have things set up differently on my workspace than he has on his. If I don't set it to change it will automatically open up a drawing with my profile. So with the lisp I have now all it does is change the workspace to his ever single time he opens a drawing so I need it to verify if it needs to change it or if it doesn't need to change. So verifying who logged in doesn't have any importance. Just when I share my profile with 2 more coworkers I will need to just alter the lisp to each computer.
The main issue I am having is trying to figure out how to start this lisp (just starting to try and comprehend lisps). Once I have one started I usually can take off and finish it from there but I never can figure out what the correct way to start one is.
I do know I need to get the Workspace name so I will do (getvar "wscurrent") but now what do I do to store that info to check it? and how do I check it?
Anybody able to show me some examples or a basic code that I could work from?????
As a demo:
(vl-load-com)
(defun c:demo (/ space user) (setq user (strcase (getvar 'LOGINNAME)) space (strcase (getvar 'WSCURRENT)) ) (cond ((and (= user "JARRED") (/= space "3D MODELING")) (if (vl-catch-all-error-p (vl-catch-all-apply '(lambda () (setvar 'WSCURRENT "3D MODELING"))) ) (prompt "\nJarred predefined Workspace don't exist...") ) ) ((and (= user "PAUL") (/= space "AUTOCAD CLASSIC")) (if (vl-catch-all-error-p (vl-catch-all-apply '(lambda () (setvar 'WSCURRENT "AUTOCAD CLASSIC"))) ) (prompt "\nPaul predefined Workspace don't exist...") ) ) ) (princ) )
Henrique
So is there a reason when I tried to run it all it said was DEMO in the command prompt nothing ran.
Also If I dont need it to look for who the user is just to check to see if current workspace is (WORKSPACE X) and if not (WORKSPACE X) change current it to WORKSPACE?
@bgraverholt wrote:
So is there a reason when I tried to run it all it said was DEMO in the command prompt nothing ran.
You'll have to change the (= user "JARRED") to the correct username, and the (/= space "3D MODELING")) to the correct workspace name and the (setvar 'WSCURRENT "3D MODELING"))) also (uppercase), and the same to the other user...
bgraverholt wrote:Also If I dont need it to look for who the user is just to check to see if current workspace is (WORKSPACE X) and if not (WORKSPACE X) change current it to WORKSPACE?
(if (/= (strcase (getvar 'WSCURRENT)) "YOURWORKSPACENAME") (setvar 'WSCURRENT "YOURWORKSPACENAME") )
Henrique
What I am still having an issue with is its still switching to Jarred the work space (which is the correct one) that I want every time I open a new drawing.
.
The other issue is when I open autocad from windows with no logo it wont automatically run the check and change the work space. I have to open another new drawing for it to do it.
@bgraverholt wrote:
What I am still having an issue with is its still switching to Jarred the work space (which is the correct one) that I want every time I open a new drawing.
Is this correct for you?
Yes or no?
@bgraverholt wrote:
The other issue is when I open autocad from windows with no logo it wont automatically run the check and change the work space. I have to open another new drawing for it to do it.
How are you loading the code?
Henrique
Yes JARRED is the correct workspace. But every time I open a drawing it does the Switch to JARRED even though it is already set to JARRED already.
The way I am loading it is like
(vl-load-com)
(if (/= (strcase (getvar 'WSCURRENT)) "Jarred")
(setvar 'WSCURRENT "Jarred")
)
)
(princ)
)
Which is probably the wrong way. What would be the best way for it to run at start up? Could I add it to the Autocad Icon some how?
If you don't have a 'acaddoc.lsp' file, just creates a new one and save it at your support directory, if you have one just add to the end this lines
(if (/= (getvar 'WSCURRENT) "Jarred") (setvar 'WSCURRENT "Jarred") )
acaddoc.lsp file will be loaded in all dwg's.
Hope that helps
Henrique
Is there a specific way to create the acaddoc.lsp? Never have had a file named that.
@bgraverholt wrote:
Is there a specific way to create the acaddoc.lsp? Never have had a file named that.
Just like any other .lsp file, but AutoCAD will load it in every dwg, if in a support directory.
Henrique
That worked perfectly thank you. Do you know if there is a way to reset the tool palette, property, and layer property manager to show up in the correct location on the screen? Since I am sharing my profile on another computer some times when opening autocad after I copy the profile over to that computer it says its the correct workspace but the Tool palette, properties and layer properties manager are in the wrong location according to where should be according to that workspace was saved at.
@bgraverholt wrote:
That worked perfectly thank you.
You're welcome!
@bgraverholt wrote:
Do you know if there is a way to reset the tool palette, property, and layer property manager to show up in the correct location on the screen? Since I am sharing my profile on another computer some times when opening autocad after I copy the profile over to that computer it says its the correct workspace but the Tool palette, properties and layer properties manager are in the wrong location according to where should be according to that workspace was saved at.
I'm not sure but tools location should be saved at User/Profiles/Profile.aws
Henrique