Author Topic: lisp to change an attribute tag NOT IN A BLOCK  (Read 1979 times)

0 Members and 1 Guest are viewing this topic.

strebor71

  • Guest
lisp to change an attribute tag NOT IN A BLOCK
« on: December 17, 2014, 03:00:12 PM »
Hello,  I am having a hell of a time trying to find out how to write some code that will allow me to be able to change the Tag name of an attribute that is not in a block. we have several drawings that have attributes in them so that when inserted into a drawing the attribute either prompts the user for input or is auto populated from a field or what have you. I want to be able to batch change the text in one of these attributes for several drawings. the tag is the same in all drawings so it should be simple. All the lisp and conversations seem to deal with how to change the attributes for an existing block, not just attributes themselves. can someone please point me in the right direction on how to get this done. thanks

ronjonp

  • Needs a day job
  • Posts: 7526
Re: lisp to change an attribute tag NOT IN A BLOCK
« Reply #1 on: December 17, 2014, 04:05:52 PM »
Here is a simple example how to change the tagstring for an attribute definition.  Welcome to TheSwamp :) .
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ o str)
  2.   (if (and (setq o (car (entsel "\nPick attribute definition:")))
  3.            (setq o (vlax-ename->vla-object o))
  4.            (= (vla-get-objectname o) "AcDbAttributeDefinition")
  5.            (/= "" (setq str (getstring "\nEnter tagname: ")))
  6.       )
  7.     (vla-put-tagstring o str)
  8.   )
  9.   (princ)
  10. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

David Bethel

  • Swamp Rat
  • Posts: 656
Re: lisp to change an attribute tag NOT IN A BLOCK
« Reply #2 on: December 17, 2014, 04:55:15 PM »
While closely related, ATTDEF and ATTRIB are (2) different entity types and must modified accordingly.   As you are finding out,  editing an ATTRIB has no affect on the corresponding ATTDEF without some type of sync command.  -David
R12 Dos - A2K

sbanister

  • Guest
Re: lisp to change an attribute tag NOT IN A BLOCK
« Reply #3 on: December 18, 2014, 10:44:37 AM »
'change the Tag name of an attribute that is not in a block'

I don't understand why you're not using simple text.

There's not much point in attributes if they're not part of a block

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: lisp to change an attribute tag NOT IN A BLOCK
« Reply #4 on: December 18, 2014, 01:22:59 PM »
'change the Tag name of an attribute that is not in a block'

I don't understand why you're not using simple text.

There's not much point in attributes if they're not part of a block

I think the gist is batch modifying a library of block definitions.  We have several thousand of these; thankfully, I also have people to do the grunt work when this comes around.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}