Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp to change workspace layout

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
bgraverholt
2320 Views, 18 Replies

Lisp to change workspace layout

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.

 

 

Tags (3)
18 REPLIES 18
Message 2 of 19
dgorsman
in reply to: bgraverholt

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.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 3 of 19
bgraverholt
in reply to: dgorsman

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.

Message 4 of 19
dgorsman
in reply to: bgraverholt

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.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 5 of 19
scot-65
in reply to: bgraverholt

Storing the data is beyond the file level, and admin. privileges, or lack of, might prevent storage in the registry (HKLM and not HKCU).

Try looking into the "original" storage method: SETCFG and GETCFG
to store all the user's names (not sure if this will work either). The ACAD.cfg
file is unique to each user profile, and is found in each specific user's profile area.

Just a thought...
How is one profile able to see another profile where you are?
Is the software being deployed from a server as what you ask it is not possible if the software is on a workstation?

Another Option:
Use the profile switch method that is embedded in a desktop shortcut icon (or tile).
Many threads on this topic. I must caution you that any changes to the workspace will not take effect next time unless one manually redefines the ARG file that is read by using said icon.

And Finally:
A separate text-type external file in a common location that can be opened for reading while the program initializes. Someone else can chime-in on this topic.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 6 of 19
bgraverholt
in reply to: scot-65

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. 

 

Message 7 of 19
bgraverholt
in reply to: bgraverholt

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?

Message 8 of 19
bgraverholt
in reply to: bgraverholt

Anybody able to show me some examples or a basic code that I could work from?????

Message 9 of 19
hmsilva
in reply to: bgraverholt

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

EESignature

Message 10 of 19
bgraverholt
in reply to: hmsilva

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? 

 

Message 11 of 19
hmsilva
in reply to: bgraverholt


@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

 

EESignature

Message 12 of 19
bgraverholt
in reply to: hmsilva

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.

Message 13 of 19
hmsilva
in reply to: bgraverholt


@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

 

EESignature

Message 14 of 19
bgraverholt
in reply to: hmsilva

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?

Message 15 of 19
hmsilva
in reply to: bgraverholt

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

EESignature

Message 16 of 19
bgraverholt
in reply to: hmsilva

Is there a specific way to create the acaddoc.lsp? Never have had a file named that.

Message 17 of 19
hmsilva
in reply to: bgraverholt


@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

 

EESignature

Message 18 of 19
bgraverholt
in reply to: hmsilva

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.

 

Message 19 of 19
hmsilva
in reply to: bgraverholt


@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

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost