Is this possible? in lisp? or vlisp? -- Jamie Duncan Consulting - If you're not part of the solution, there's good money in prolonging the problem.
And your gender reference Ms. Jamie Duncan "How wrong it is for a woman to expect the man to build the world she wants, rather than to create it herself." - Anais Nin (1903-1977)
then dimstyleObject is a collection of the dimstyles dimstyles, right? like: (setq dimstyleObject (vla-get-dimstyles *doc*)) Thanks Jason. Now do I have to pretest for the existence of the new name? or can I setq like this? (setq flagwave (vla-put-name dimstyleObject "MyNewName")) and if flagwave is nil it worked? right? Am I actually getting this? -- Jamie Duncan "How wrong it is for a woman to expect the man to build the world she wants, rather than to create it herself." - Anais Nin (1903-1977)
You can't rename a collection object, but you can rename an item from within the collection (if allowed and in this case, yes it is). You need to set dimstyleObject to be an item contianed in the dimstyle collection. You should test for the existence of the new name before you use vla-put-name, or you could wrap the whole thing in a vl-catch-all-apply and deal with the error (if it occurs). ; active document (setq *doc* (vla-get-activedocument (vlax-get-acad-object))) ; dimstyle collection <-- contains all dimstyles (setq dims (vla-get-dimstyles *doc*)) ; dimstyle object from within the collection (setq item (vla-item dims "Standard")) ; apply new name, trapping error incase the ; new name already exists. (setq error (vl-catch-all-apply 'vla-put-name (list item "MyNewName")) ) ; if 'error' is an object returned by vl-catch-all-apply ; print the error message, otherwise renaming worked. (if (vl-catch-all-error-p error) (vl-catch-all-error-message error) (princ "renaming worked") )
Thanks for the help Jason! Now I have a startup routine that sets *docs* like you've done, I assume then that as a global it will be fine for the session. Correct? And to test - I assume tblsearch is fine? I've searched a bit through the vlisp to see if there is an equivalent but I couldn't find any. -- Jamie Duncan "How wrong it is for a woman to expect the man to build the world she wants, rather than to create it herself." - Anais Nin (1903-1977)
Hi Jamie, This is about as close to "tblsearch" as you'll get with activex: (setq dims (vla-get-dimstyles *doc*)) (if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list dims "mydim")))) (alert "Dim name found") (alert "Dim name not found") ) HTH, Jeff
All other discussion notwithstanding, the brute force method: (command "_.rename" "_d" "OldName" "NewName") ___
The global will be valid for the life of the drawing it was initiated in, not necessarily the session. Tblsearch is one way to test for the existence, or you can do as Jeff has shown. (vla-item <collection> <item>) is the *same* as tblsearch in terms of activex. Just remember to trap for errors. If an error occurred, it failed.
Hi Jason, This Tony snip might help Jamie with the general idea. Joe ;;-------- All ActiveX collection objects raise a 'Key Not found' exception when an attempt to reference a non-existing element is made. The proper way to test for membership in any collection object, is to call the collections Item() method in a protected block of code (passing the name of the item which you want to test for membership), and handling the exception that occurs if the element is not found. Here is an example: ;; Return T if the selection set whose ;; Name is passed as an argument exists ;; in the Active Document's selection ;; sets collection, or nil otherwise: (defun selection-set-exists? (Name) (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-Item (list (vla-get-SelectionSets (ThisDrawing) ) Name ) ) ) ) ) ;;--------