PDA

View Full Version : Rename profile



arussell2003385516
2013-07-06, 05:37 AM
I trying to rename a profile and i keep getting errs so i most be doing something wrong or don't understand. I'm only having issue with sample-sample-profile-rename.
Thanks for the help.

Script file

(load "C:\\ACAD\\Lisp\\TRC start-up lisp and scripts\\sample-profile-util.lsp")
(sample-profile-import "C:\\ACAD\\USER\\ACAD-Network Profile.arg" "ACAD-Network Profile" T)
(sample-profile-set-active "ACAD-Network Profile")
(sample-sample-profile-rename "ACAD-Standalone Profile" "test")


Code inside sample-profile-util.lsp


(defun sample-profile-rename ( oldName newName / profs ) (and
oldName
newName
(setq profs (sample-get-profiles-object))
(not (vl-catch-all-error-p (vl-catch-all-apply 'vla-RenameProfile (list profs oldName newName))))
)
);defun sample-profile-rename

Tharwat
2013-07-06, 07:25 AM
Try this instead .



(vl-load-com)
(defun ProfileRename (old new / pfs)
;;; Tharwat 06. July. 2013 ;;;
(setq Pfs (vla-get-Profiles
(vla-get-Preferences (vlax-get-acad-object))
)
)
(vla-GetAllProfileNames Pfs 'lst)
(if (and (member old (vlax-safearray->list lst))
(eq (type old) 'STR)
(eq (type new) 'STR)
)
(vl-catch-all-apply 'vla-RenameProfile (list pfs old new))
)
)

arussell2003385516
2013-07-06, 04:48 PM
When I run the command I get this error


Command: (LOAD "C:/Users/russell/Desktop/rename profiles.lsp") PROFILERENAME

Command: (PROFILERENAME)
; error: too few arguments

Tharwat
2013-07-06, 04:58 PM
When I run the command I get this error


Command: (LOAD "C:/Users/russell/Desktop/rename profiles.lsp") PROFILERENAME

Command: (PROFILERENAME)
; error: too few arguments

You should have that error message because you did not feed the function with arguments .:banghead:

Open your option dialog box with the command option or op and go to tab "Profiles" and write down what you have of profile names .

Then load my function like this .



(ProfileRename <Write Here any of the profile names that was in the Profile tab in Option >
< Enter any new profile name that you want to rename the old one >)

arussell2003385516
2013-07-06, 05:23 PM
Thank you for your help. I was changing old and new names in the lisp file. Thanks for the help again.

Tharwat
2013-07-06, 05:26 PM
Thank you for your help. I was changing old and new names in the lisp file. Thanks for the help again.

You're welcome and I hope that you got it working at last . :)

alanjt
2013-07-08, 02:30 PM
Try this instead .



(vl-load-com)
(defun ProfileRename (old new / pfs)
;;; Tharwat 06. July. 2013 ;;;
(setq Pfs (vla-get-Profiles
(vla-get-Preferences (vlax-get-acad-object))
)
)
(vla-GetAllProfileNames Pfs 'lst)
(if (and (member old (vlax-safearray->list lst))
(eq (type old) 'STR)
(eq (type new) 'STR)
)
(vl-catch-all-apply 'vla-RenameProfile (list pfs old new))
)
)


1. case sensitive.
2. why check if member, then check if 'old' is a string?
3. what if the 'new' name is already an existing profile name?
4. your return with vl-catch-all-apply will never be nil since you don't also check if an error was thrown.
5. you don't localize your 'lst' variable.

With the error checking and utilization of vl-catch-all-apply, why not just wrap it all into one?


(defun profileRename (old new)
(not (vl-catch-all-error-p
(vl-catch-all-apply
'vla-renameprofile
(list (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) old new)
)
)
)
)

Tharwat
2013-07-08, 04:58 PM
It is not necessarily all users bring the same solution or outcome , but for me I try to give the best I can and that's what I did in this thread .

To check for extra correct arguments (type function) can't be considered wrong as far as I know and the same for if the profile is a member .

But for the last vl-catch-all-apply function , it does not matter if it returns nil or true as long as we care only about the outcome and nothing's more . ;)

Thanks for the constructive comments Alan .

alanjt
2013-07-08, 05:08 PM
It is not necessarily all users bring the same solution or outcome , but for me I try to give the best I can and that's what I did in this thread .

and I'm just offering a little friendly criticism.


To check for extra correct arguments (type function) can't be considered wrong as far as I know and the same for if the profile is a member .

I wasn't implying it was wrong, just showing that it wasn't fully needed since you could just leave it all in the catch-all wrapper.


But for the last vl-catch-all-apply function , it does not matter if it returns nil or true as long as we care only about the outcome and nothing's more . ;).
Except that with your way, the user only knows if it was successful by then looking at the active profile name to see if it actually changed, rather than just having the function return a T.

Tharwat
2013-07-08, 05:20 PM
I am entirely agree .

And for sure I do read all your posts all around because you give a very rare and constructive replies and very neat way of coding that makes me feel
that I am still so far in the back yard :mrgreen:

Much appreciated .

alanjt
2013-07-08, 05:22 PM
I am entirely agree .

And for sure I do read all your posts all around because you give a very rare and constructive replies and very neat way of coding that makes me feel
that I am still so far in the back yard :mrgreen:

Much appreciated .

We all have a lot to learn.

BlackBox
2013-07-08, 08:42 PM
...

With the error checking and utilization of vl-catch-all-apply, why not just wrap it all into one?


(defun profileRename (old new)
(not (vl-catch-all-error-p
(vl-catch-all-apply
'vla-renameprofile
(list (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) old new)
)
)
)
)

It would be really schnazzy, if one could search for shortcuts in known application shortcut folders (i.e., desktop, taskbar, etc.), and also modify the Target Property if a match is found... Neat, not essential.

alanjt
2013-07-09, 02:39 AM
It would be really schnazzy, if one could search for shortcuts in known application shortcut folders (i.e., desktop, taskbar, etc.), and also modify the Target Property if a match is found... Neat, not essential.
Cool idea. I wrote (and posted here) some shortcut creation functions a few years ago. I bet one could easily glean from them.