AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

Here's a little application that you may find interesting. It will check the Login Name of the user and automatically load the relevant Profile for that user.
Firstly you need to name your Profiles the same as your Login Name. e.g. if your Login Name is NDBE51D1, your Profile must be named NDBE51D1.ARG. Then you need to store all your user Profiles in the same folder. (This example uses "c:/profiles/").
Irrespective of which user logs in, the specific Profile for that user will be loaded if necessary, and made Active.
Not much in the way of error checking at the moment I'm afraid.....

;CODING STARTS HERE
(prompt "\nType LoginProfile to run......")

(vl-load-com)

(defun C:LoginProfile (/ profilename acadprofiles actprofile
thelist profilepath)

;retrieve the users login name
(setq profilename (strcase (getvar "LOGINNAME")))

;retrieve a reference to the Profiles
(setq acadprofiles (vla-get-profiles
(vla-get-preferences (vlax-get-Acad-Object))))

;retrieve the Active Profile
(setq actprofile (strcase (vla-get-ActiveProfile acadprofiles)))

;if they are not the same
(if (/= profilename actprofile)

;do the following
(progn

;get a list of the loaded profiles
(vlax-invoke-method acadProfiles 'GetAllProfileNames 'thelist)

;convert to a list
(setq thelist (vlax-safearray->list thelist))

;if the profile is not in the list
(if (not (member profilename thelist))

;do the following
(progn

;store the profile file
(setq profilepath
(strcat "c:/profiles/" profilename ".arg"))

;if the profile is found
(if (findfile profilepath)

;do the following
(progn

;load the profile
(setq NewProfile (vlax-invoke-method
acadprofiles 'ImportProfile
profilename profilepath :vlax-true))

;make the profile the Active Profile
(vla-put-ActiveProfile acadProfiles profilename)

);progn

;profile file cannot be found - exit
(prompt (strcat "\nCannot find profile " profilepath))

);if

);progn

;it is loaded but make the profile the Active Profile
(vla-put-ActiveProfile acadProfiles profilename)

);if

);progn

;We could reload the Profile if we wish.
;Just uncomment the next line.
;(vlax-invoke-method acadProfiles 'ResetProfile profilename)

);if

(princ)

);defun

(princ)
;CODING ENDS HERE

The AutoLisp/Visual Lisp/VBA Resource Website

Copyright 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website