Check if a profile exist, copy
Hi!I am trying to figure out how to make a lisp that does the following:
1. Check if a profile with a given name (eg. Engineering) exist in AutoCAD
2. If the profile exist it should be set active
3. If the profile does not exist the active profile should be copied and named "Engineering" and set active.
I have tried to put together some code from several sites and I have this:
(vl-load-com);get profiles from AutoCAD(vlax-invoke-method acadProfiles 'GetAllProfileNames 'profilelist);convert the list(setq profilelist (vlax-safearray->list profilelist));check if the profile exist(if (not (member "Engineering" profilelist));if it does'n exist(progn ;copy active profile and rename to "Engineering"(vlax-invoke-method acadProfiles 'CopyProfile actProfile "Engineering") ));set "Engineering" as active profile(vla-put-ActiveProfile acadProfiles "Engineering")
BUT, it doesn't work.
Can anyone help me out? Welcome to CadTutor
Hope this would help you with it .
(defun c:Test (/ Pfs lst) ;;--- Tharwat 25. April. 2013 ---;; (setq Pfs (vla-get-Profiles (vla-get-Preferences (vlax-get-acad-object)) ) ) (vla-GetAllProfileNames Pfs 'lst) (if (not (member "Engineering" (vlax-safearray->list lst)) ) (progn (vla-copyprofile Pfs (vla-get-activeprofile Pfs) "Engineering" ) (vla-put-activeprofile Pfs "Engineering") ) (vla-put-activeprofile Pfs "Engineering") ) (princ))(vl-load-com) Thank you for your fast reply. But I couldn't get it to work. There are no errors in AutoCAD but it doesn't copy the current profile (which is "Unnamed Profile"). Actually it should do , did you check the profiles tab in the options ? Try this:
(defun c:setprofile ( / lst prf prn ) (setq prn "Engineering" prf (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) ) (vla-getallprofilenames prf 'lst) (setq lst (vlax-safearray->list lst)) (if (member prn lst) (vla-put-activeprofile prf prn) (progn (vla-copyprofile prf (getvar 'cprofile) prn) (vla-put-activeprofile prf prn) ) ) (princ))(vl-load-com) (princ)
I wouldn't assume that the current profile will always be first in the list returned by the getallprofilenames method. Lee , May I know what's the new with your code to mine ?
If I may... Consider the difference between (car nm), and (getvar 'cprofile), in the context of Lee's ending comment.
However if the Auto-Cad session has only one profile or more the (car nm) would return a name of a profile and would copy one
of them and activate it as it's been asked by the OP .
But the OP states:
Hence my comment:
Checked in the profiles tab but there is only Unnamed profile that is listed. I have also tried it after adding other profiles but nothing seams to happen.
页:
[1]
2