Guest looseLISPSsinkSHIPS Posted December 10, 2009 Posted December 10, 2009 We have a block named template which has an attribute tag named "PAGEnum" recently I updated the block and renamed the TAG "PAGENUMBER". Though I am able to use the BATTMAN command I would simply like to automate the whole process with one single command (easyer then telling the drafters time after time). Though I know how to write much of the command what I can’t do is mimic the "Tab" key needed to skip around the different sections of the BATTMAN pop-up dialogue box. In a nutshell I want to automate the entire BATTMAN procedure, given that I know my block name (template), my incorrect/ existing tag name (PAGENUMBER), and the correct/ replacement tag name (PAGEn). Could anyone please help me with this? Quote
SteveK Posted December 10, 2009 Posted December 10, 2009 Just to be clear I haven't misread, you want to change one tag name in one block name with one command? (defun c:ChPgTag (/ BLK DOC I NEWTAG OLDTAG SS) (vl-load-com) (setq blk "template" oldtag "PAGEnum" newtag "PAGENUMBER" i -1 doc (vla-get-activedocument (vlax-get-acad-object))) (if (ssget "_X" (list (cons 0 "INSERT")(cons 2 blk))) (vlax-for bl (setq ss (vla-get-activeselectionset doc)) (foreach att (vlax-invoke bl 'getAttributes) (If (eq (vla-get-tagstring att) oldtag) (vla-put-tagstring att newtag)))) (princ "\nNo Selection Set Found.")) (princ)) Quote
Lee Mac Posted December 10, 2009 Posted December 10, 2009 If Steve is right, here is maybe a better way: Quote
SteveK Posted December 11, 2009 Posted December 11, 2009 Yeah that looks a better way. get-Blocks would surely be quicker than ssget. Though would get-item with if statement be quicker than get-attributes? attsync, another one I'll have to remember. Wouldn't it be best the put it only in the if statment? Quote
Lee Mac Posted December 11, 2009 Posted December 11, 2009 Its not the speed that I was thinking of, although I think it would be quicker this way (not sure how quick attsync is though).. It was more that, in my method, I change the block definition - hence any subsequent blocks inserted use the new definition and have tags that are already updated. Whereas in your method - only existing blocks are changed Lee Quote
Lee Mac Posted December 11, 2009 Posted December 11, 2009 attsync, another one I'll have to remember. Wouldn't it be best the put it only in the if statment? It is within the IF statement :wink: Quote
SteveK Posted December 11, 2009 Posted December 11, 2009 Its not the speed that I was thinking of, although I think it would be quicker this way (not sure how quick attsync is though).. It was more that, in my method, I change the block definition - hence any subsequent blocks inserted use the new definition and have tags that are already updated. Whereas in your method - only existing blocks are changed Lee Ahh, I didn't even think of that! Good one. It is within the IF statement :wink: And sorry, yeah my bad I didn't think about what attsync does. Quote
Guest looseLISPSsinkSHIPS Posted December 15, 2009 Posted December 15, 2009 Steves example works perfectly but has anybody noticed why AutoCAD has difficulty running two similar lisp codes at start-up, I namely lied a little, there are two attributes which both have to be renamed to "PAGENUMBER" I thought I could simply duplicate the code and only change the section of the "Oldtag" number, obviously not.. Can anybody explain what’s going on here? Thanks- Quote
Lee Mac Posted December 15, 2009 Posted December 15, 2009 You would have to change the function definition to something different - also bear in mind that Steve's approach only changes existing blocks. :wink: Quote
Lee Mac Posted December 15, 2009 Posted December 15, 2009 I apologise for the slight mistake in my old LISP - in the fact that it would change all the tags This will cope with multiple changes: (defun attchng (blk old new / obj) (mapcar (function set) '(blk old new) (mapcar (function strcase) (list blk old new))) (cond ( (or (wcmatch old "* *") (wcmatch new "* *")) (princ "\n** Invalid Attribute Tags **")) ( (not (tblsearch "BLOCK" blk)) (princ "\n** Block Not Found **")) (t (vlax-for obj (vla-item (cond (*blk*) ((setq *blk* (vla-get-Blocks (vla-get-activeDocument (vlax-get-acad-object)))))) blk) (if (and (eq "AcDbAttributeDefinition" (vla-get-ObjectName obj)) (eq old (strcase (vla-get-TagString obj)))) (vla-put-TagString obj new))) (vl-cmdf "_.attsync" "_N" blk))) (princ)) (defun c:test nil (mapcar (function attchng) '("template") ;; List of Blocks '("pagenum") ;; List of Old Attribute Tags '("pagenumber") ;; List of New Attribute Tags ) (princ)) Just alter the lists as required. Quote
SteveK Posted December 15, 2009 Posted December 15, 2009 looseLISPSsinkSHIPS, can I call you "loose"? Anyways, firstly, yeah I'd recommend Lee's lisp over mine as it will change the block definition too. EDIT: sorry Lee, I didn't see you wrote another one! Second, here's a variant of mine that lets you add as many tags as you want. Note it only applies to that "template" block. Edit it to your liking: (defun changeTags (/ BLK DOC I TAGLST SS) (vl-load-com) (setq blk "template" tagLst '( ;"Old Tag" "New Tag" ("PAGEnum" "PAGENUMBER") ("TAG2" "NEWTAG2") ) i -1 doc (vla-get-activedocument (vlax-get-acad-object)) ) (if (ssget "_X" (list (cons 0 "INSERT")(cons 2 blk))) (vlax-for bl (setq ss (vla-get-activeselectionset doc)) (foreach att (vlax-invoke bl 'getAttributes) (If (assoc (vla-get-tagstring att) tagLst) (vla-put-tagstring att (cadr (assoc (vla-get-tagstring att) tagLst))) ))) (princ "\nNo Selection Set Found.")) (princ)) ;; Run program manually with this: (defun c:ChPgTag () (changeTags)) ;; Uncomment this to run when lisp loaded ;(changeTags) Quote
Least Posted February 11, 2010 Posted February 11, 2010 Thanks SteveK that lisp for me is very handy. Quote
SteveK Posted February 12, 2010 Posted February 12, 2010 Thanks (Least), ' appreciate the comment. 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.