mdbdesign Posted April 11, 2012 Posted April 11, 2012 (edited) Working on combining some codes to get layout tabs rename to file name and add suffix (numbers or letters - thanks to CAB) to it. It is working fine except file extension keep writing into tab new name. Can somebody take look at it and tell me what need to be changed in order to get only file name and suffix write in tab (let say "TEST-A" not an TEST.dwg-A) ;;; FUNCTION ;;; This routine will rename all layout tabs with ;;; dwg file name (MB) prefix & number or letter suffix ;;; ;;; ARGUMENTS ;;; none ;;; ;;; USAGE ;;; renl ;;; ;;; PLATFORMS ;;; 2000+ ;;; ;;; AUTHOR ;;; Copyright© 2004 Charles Alan Butler ;;; e-mail-removed;;; ;;; VERSION ;;; 1.0 Oct. 01, 2004 ;;; ;;; This software is provided "as is" without express or implied ; ;;; warranty. All implied warranties of fitness for any particular ; ;;; purpose and of merchantability are hereby disclaimed. ; ;;; You are hereby granted permission to use, copy and modify this ; ;;; software without charge, provided you do so exclusively for ; ;;; your own use or for use by others in your organization in the ; ;;; performance of their normal duties, and provided further that ; ;;; the above copyright notice appears in all copies and both that ; ;;; copyright notice and the limited warranty and restricted rights ; ;;; notice appear in all supporting documentation. ; ;;; (defun c:renl (/ tab_name doc cnt x suffix new_list) (vl-load-com) (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) (vlax-for l (vla-get-layouts *AcadDoc*) (if (eq 1 (vla-get-taborder l)) (vl-catch-all-apply (function vla-put-name) (list l (vl-filename-base (getvar 'dwgname)))) ) ) (setq tab_name (getvar 'dwgname)) (cond (tab_name) ((setq tab_name ""))) (initget "Numbers Letters") (setq suffix (getkword "\nSuffix to use? [Numbers or Letters] : <Numbers> ")) (cond (suffix) ((setq suffix "Numbers"))) (setq *doc* (vla-get-activedocument (vlax-get-acad-object))) (vlax-for tab (vla-get-layouts ; get list of layout tabs (vla-get-activedocument (vlax-get-acad-object))) (if (/= (setq tmpname (vla-get-name tab)) "Model") ; omit MODEL space (setq new_list (cons (cons (vla-get-taborder tab) tab) new_list)) ) ) ;; sort list acording to tab order (setq new_list (vl-sort new_list '(lambda (e1 e2) (< (car e1) (car e2))))) ;;remove the taborder numbers (setq new_list (mapcar 'cdr new_list)) ;; rename the tabs (setq cnt (cond ((= suffix "Numbers") 0) (64))) (foreach x new_list (vla-put-name x (strcat tab_name "-" (cond ((= suffix "Numbers") (itoa (setq cnt (1+ cnt)))) ((chr (setq cnt (1+ cnt)))) ))) ) (princ) ) ; defun (prompt "\n*-* Rename Tab layouts Loaded, Enter renl to run. *-*") (princ) Edited April 12, 2012 by mdbdesign Quote
BlackBox Posted April 11, 2012 Posted April 11, 2012 Marek - I tried Cab's code as posted in your OP, and it works fine AFAIK... The code prompts the user to enter the tab name (prefix), so if the .dwg is showing in the tab name(s), then methinks user error, no? Quote
mdbdesign Posted April 12, 2012 Author Posted April 12, 2012 Marek - I tried Cab's code as posted in your OP, and it works fine AFAIK... The code prompts the user to enter the tab name (prefix), so if the .dwg is showing in the tab name(s), then methinks user error, no? Sorry for late response. Jeez, I posted original CAB codes. Sorry guys. Updated in first post with new changed codes. Hope it is now clear what I was planing to do. Once again sorry. Quote
pBe Posted April 12, 2012 Posted April 12, 2012 (setq tab_name [b][color=blue](vl-filename-base[/color][/b] (getvar 'dwgname)[color=blue][b])[/b][/color]) Might as well change this too (setq suffix (getkword "\nSuffix to use? [[b][color=blue]Numbers/Letters[/color][/b]] : <Numbers> ")) Quote
Lee Mac Posted April 12, 2012 Posted April 12, 2012 Here's another version: (defun c:renl ( / cnt fun lst tab ) (vl-load-com) (initget "Numbers Letters") (if (eq "Letters" (getkword "\nSuffix to Use? [Numbers/Letters] <Numbers>: ")) (setq fun chr cnt 64) (setq fun itoa cnt 0) ) (setq tab (vl-filename-base (getvar 'dwgname))) (vlax-for lay (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (if (not (eq "Model" (vla-get-name lay))) (setq lst (cons (cons (vla-get-taborder lay) lay) lst)) ) ) (foreach lay (vl-sort lst '(lambda ( a b ) (< (car a) (car b)))) (vla-put-name (cdr lay) (strcat tab "-" (fun (setq cnt (1+ cnt))))) ) (princ) ) Quote
mdbdesign Posted April 12, 2012 Author Posted April 12, 2012 And it was so easy?!?! Thank you guys. I actually try to replace as pBe suggest but must miss something. Now is working. What about hardcoding letters only? After I can use two hardcoded version: one for letters and one for numbers. Quote
pBe Posted April 12, 2012 Posted April 12, 2012 (defun [color=blue]renl [color=black]([/color]mode[/color] / tab_name doc cnt x suffix new_list) [color=blue];;; [/color] (initget "Numbers Letters") [color=blue];;;[/color] (setq suffix (getkword "\nSuffix to use? [Numbers/Letters] : <Numbers> ")) [color=blue];;; [/color] (cond (suffix) ((setq suffix "Numbers"))) [color=blue](setq suffix mode) [/color] [b](Defun c:Rn1 ()(renl "Numbers"))[/b] [b](Defun c:Rn2 ()(renl "Letters"))[/b];<--- could be anything other than "Numbers" Quote
mdbdesign Posted April 12, 2012 Author Posted April 12, 2012 Great, thank you. One more question: how lisp can "remember" my choice of options when next time I start Autocad? Quote
pBe Posted April 12, 2012 Posted April 12, 2012 Great, thank you. One more question: how lisp can "remember" my choice of options when next time I start Autocad? Now thats another matter. Do you really want to go there? I would do Ldata. Quote
BlackBox Posted April 12, 2012 Posted April 12, 2012 Consider the GetEnv and SetEnv functions, otherwise you'll have to write to an external file, or the registry. Quote
pBe Posted April 12, 2012 Posted April 12, 2012 Consider the GetEnv and SetEnv functions, How's that work Renderman? can you please give me some pointers on those functions. Quote
BlackBox Posted April 12, 2012 Posted April 12, 2012 How's that work Renderman? can you please give me some pointers on those functions. In my previous post, the functions are linked to the online developer documentation for said functions. Basically, these aptly named functions get or set a registry key specifically within the FixedProfile -> General Key for the active version of AutoCAD, which is different than writing your own registry key elsewhere. As a small demonstration, consider: (setenv "MyFooTest" "Foo") ... Then search the registry using Edit -> Find and type in MyFooTest (no quotes), and you should end up here: (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\FixedProfile\\General") Hope that makes sense? Quote
BlackBox Posted April 12, 2012 Posted April 12, 2012 Here's one (quickly written) way of incorporating getenv and setenv into a routine: ((lambda (env / mode) (cond ((= "ON" (setq mode (getenv env))) ;; <- Do stuff ) ((or (= mode "OFF") (= mode nil)) (initget "ON OFF") (if (or (setq mode (getkword "\nEnter mode [ON/OFF] <OFF>: ")) (setq mode "OFF")) (progn (setenv env mode) ;; <- Do stuff ))))) "myEnv") Quote
pBe Posted April 12, 2012 Posted April 12, 2012 That is so cool. and its not limited to a single drawing to boot. Question: Is there a limit to the number of values i can store? Quote
BlackBox Posted April 12, 2012 Posted April 12, 2012 That is so cool. and its not limited to a single drawing to boot. Yes, this can be very useful for complex functions. Question: Is there a limit to the number of values i can store? That's a great question - One that I do not know the answer to. LoL Not knowing what OS you're running, if you happen to run into issues with the number of registry keys being stored (due to low registry space), it appears that one can Set the Registry Size to "unlimited". ** Note - Always edit the registry responsibly. Quote
irneb Posted April 12, 2012 Posted April 12, 2012 I'd also advise you add a subfolder for your settings, that way they don't clutter up (and possibly overwrite) one of the existing stuff in that General folder. It's quite easy to do: (setenv "MyFolder\\MyKey" "MyValue") (getenv "MyFolder\\MyKey") It also makes it simpler to do a reg-export and import on another PC. Just one issue with the setenv/getenv: it only works on text values. If you need to store integers / reals, then either convert them to/from text or use the vl-registry-* functions. Quote
pBe Posted April 12, 2012 Posted April 12, 2012 Not knowing what OS you're running, if you happen to run into issues with the number of registry keys being stored (due to low registry space), it appears that one can Set the Registry Size to "unlimited Can it burn something that is not supposed to be burnt? Having read that gives me the chills BTW: Am using Windows XP Professional ** Note - Always edit the registry responsibly. Will compy Renderman. Thank you for the info and the code snippet. Cheers Quote
pBe Posted April 12, 2012 Posted April 12, 2012 I'd also advise you add a subfolder for your settings, that way they don't clutter up (and possibly overwrite) one of the existing stuff in that General folder. Now that is indeed a great idea. Just one issue with the setenv/getenv: it only works on text values. If you need to store integers / reals, then either convert them to/from text or use the vl-registry-* functions. Yup. wilco. Thank you kind sir. Quote
mdbdesign Posted April 12, 2012 Author Posted April 12, 2012 Now thats another matter. Do you really want to go there? I would do Ldata. No, just curiosity. I will stay on lower level. Thank you. BTW, lots of changes (new posts) after server went down in my place. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.