Jump to content

help requierd for BATTMAN lisp


Recommended Posts

Guest looseLISPSsinkSHIPS
Posted

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?

Posted

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))

Posted

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?

Posted

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

Posted
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:

Posted
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.

Guest looseLISPSsinkSHIPS
Posted

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-

Posted

You would have to change the function definition to something different - also bear in mind that Steve's approach only changes existing blocks. :wink:

Posted

I apologise for the slight mistake in my old LISP - in the fact that it would change all the tags :oops:

 

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.

Posted

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)

  • 1 month later...

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...