Change attribute values to default values

Change attribute values to default values

Anonymous
Not applicable
11,847 Views
29 Replies
Message 1 of 30

Change attribute values to default values

Anonymous
Not applicable

Hi all,

 

I have several instances of a block placed on my drawings, and they all have attributes with values already set up. I have now changed the default value for two of those attributes to be a dynamic field. Is there a way to change those two attributes values back to the new default value for all instances of the block?

Thank you.

 

Alessandro

0 Likes
Accepted solutions (2)
11,848 Views
29 Replies
Replies (29)
Message 2 of 30

Richard.Vivanco
Advisor
Advisor

Use attsync command.

 


Richard Vivanco V.
Arq. BIM Manager + Autodesk Certified Instructor
Website | Youtube | LinkedIn



EESignature

0 Likes
Message 3 of 30

Anonymous
Not applicable

No it doesn't work.

I think the problem is that I am trying to convert attribute values to attribute fields. Those attributes were entered manually but now I am trying to change them to show automatically the coordinates of the object. I can't do that by changing all the current values, but I can do that by changing the default values of the attributes, that's why the question. But for some reason I can't make it work. Hope makes sense.

Thanks.

 

Alessandro

0 Likes
Message 4 of 30

vinodkl
Mentor
Mentor

Hi,

 

Have you tried the Global attribute editor command "GATTE". By using this you would be able to change value of the attribute in whole of the drawing.

--------------------------------------------------------------------------------------------------------------------------
ವಿನೋದ್ ಕೆ ಎಲ್( System Design Engineer)
Likes is much appreciated if the information I have shared is helpful to you and/or others.

Please mark "Accept as Solution" if my reply resolves the issue or answers your question, to help others in the community.
--------------------------------------------------------------------------------------------------------------------------
Message 5 of 30

Anonymous
Not applicable

As far as I know with GATTE you can only set a text value, not a field.

0 Likes
Message 6 of 30

Moshe-A
Mentor
Mentor

@Anonymous  hi,

 

Here is a lisp command called RESETAGS that will do exactly what you want.

wrap the following code lines in a lisp file called it resetags.lsp.

 

first you'll be prompt to select attributes you want to be reset (update) directly taken from the default attribute value of the block definition. than you''ll be prompt to select all block references to be reset.

 

works with dynamic blocks too 😀

 

enjoy

Moshe

 

 

(vl-load-com); load activex support

(defun C:RESETAGS (/ select_attributes attdef->list ; local functions
		     blocks ss tags^ AcDbBlkRef attdef^ attributes^ attrib tag0 tag1 item)

 ; return list of attributes name 
 (defun select_attributes (/ pick elist tag lst)
  (while (setq pick (nentsel "\nSelect attribute: "))
   (setq elist (entget (car pick)))

   (cond 
    ((/= (cdr (assoc '0 elist)) "ATTRIB")
     (vlr-beep-reaction)
     (prompt "\nEntity selected is not an attributes.")
    ); case
    ( t
     (prompt (strcat "\ntag: " (setq tag (cdr (assoc '2 elist)))))
     (setq lst (cons tag lst))
    ); case
   ); cond
  ); while
  
  lst ; return
 ); select_attributes
  
  
 ; return a list of block definition attributes data
 (defun attdef->list (/ bname AcDbBlkTblRec lst)
  (setq bname (vla-get-effectiveName AcDbBlkRef))
  (setq AcDbBlkTblRec (vla-item blocks bname))

  (vlax-for AcDbEntity AcDbBlkTblRec
   (if (eq (vla-get-objectName AcDbEntity) "AcDbAttributeDefinition")
    (setq lst (cons (cons (vla-get-tagString AcDbEntity) (vla-get-textString AcDbEntity)) lst))
   )
   (vlax-release-object AcDbEntity) 
  ); vlax-for
   
  (vlax-release-object AcDbBlkTblRec)
   
  lst ; return
 ); attdef->list

  
 ; here start C:RESETAGS
 (setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
  
 (if (and
       (setq tags^ (select_attributes))
       (setq ss (ssget (list '(0 . "insert") '(66 . 1))))
     )  
  (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (setq AcDbBlkRef (vlax-ename->vla-object ename))
   (setq attdef^ (attdef->list))
   (setq attributes^ (vlax-invoke AcDbBlkRef 'GetAttributes))

   (foreach attrib attributes^
    (setq tag0 (strcase (vla-get-tagString attrib)))
      
    (foreach tag1 tags^      
     (if (and
	   (eq tag0 tag1)
           (setq item (assoc tag0 attdef^))
	 )
       (vla-put-textString attrib (cdr item))
     ); if
    ); foreach
   ); foreach

   (foreach attrib attributes^
    (vlax-release-object attrib)
   )
     
   (vlax-release-object AcDbBlkRef)
  ); foreach
 ); if

 (vlax-release-object blocks)
   
 (princ)
); C:RESETAGS

0 Likes
Message 7 of 30

vinodkl
Mentor
Mentor

Oops. I assumed that you were about to replace all the blocks value and not with field as per the question you asked.

So for this my suggestion would be to rename the tag of the attribute to something different and then in the default you can update the field and then save the block and run the attsync command. now all the block will be replaced with the default value.

Again open the block in block editor and then change the value of the attribute tag as it was earlier and close and the block and again run the attsync command.

--------------------------------------------------------------------------------------------------------------------------
ವಿನೋದ್ ಕೆ ಎಲ್( System Design Engineer)
Likes is much appreciated if the information I have shared is helpful to you and/or others.

Please mark "Accept as Solution" if my reply resolves the issue or answers your question, to help others in the community.
--------------------------------------------------------------------------------------------------------------------------
0 Likes
Message 8 of 30

Anonymous
Not applicable

Thank you Moshe-A, unfortunately this is only partially working. For some reason it is copying the coordinates of the first object (the one on which I set the default attribute's value to be the coordinate field) to all other objects, whereas obviously I would like each object to have its own coordinates. 

0 Likes
Message 9 of 30

Anonymous
Not applicable

I am wondering if it is possible to set a "block's" field changing dynamically with the block's instances, instead of an object's field. Probably that is the problem. 

0 Likes
Message 10 of 30

Moshe-A
Mentor
Mentor

did already post a sample dwg that explain the specific field data you want to copy? 

 

0 Likes
Message 11 of 30

Anonymous
Not applicable

See attached a very basic example, here is what I have done:

 

1. I created a "Test" block which is a circle and the attribute "X" which is supposed to show the X coordinate of the center

2. I inserted three Test blocks and changed their attribute manually (text)

3. After that I changed the default value of the attribute of the block at the top to be the Position-X field of that object

4. I used your code with the other 2 objects

 

I have noticed that what I am trying to do works only if I copy and paste the object on which I set the default field value, in that case the attribute is showing the current position of the object, but not if I try to update existing object or insert new objects.

Many thanks.

0 Likes
Message 12 of 30

vinodkl
Mentor
Mentor
Accepted solution

The problem with the block is the field. Instead of using the field category: object use the field category: block place holder and then select the block and its position which would be the insertion point as seen in the screenshot.

BPH.PNG

--------------------------------------------------------------------------------------------------------------------------
ವಿನೋದ್ ಕೆ ಎಲ್( System Design Engineer)
Likes is much appreciated if the information I have shared is helpful to you and/or others.

Please mark "Accept as Solution" if my reply resolves the issue or answers your question, to help others in the community.
--------------------------------------------------------------------------------------------------------------------------
Message 13 of 30

Moshe-A
Mentor
Mentor

ok this requires a total new lisp, stay tume

0 Likes
Message 14 of 30

Moshe-A
Mentor
Mentor

@Anonymous  hi,

 

OK it tooks alot of time but have success 😀

 

So Attached pattfc.zip contain pattfc.VLX (Populate Attribute Field Code) lisp program which uses FieldCodeV1-1.lsp from Lee Mac (thanks lee) to retrieve field code from attribute, may be download from >> here << but you do not need this cause i wrapped it all for you in one VLX file.

 

extract the vlx in any lisp folder and load it and key in PATTFC to run the program.

 

Command:  PATTFC

Select source attribute to populate:  <pick attributes>

 

You can pick some attributes from some blocks in one session.

cause AutoCAD do not respond to highlight calls to highlight attribute from AutoLISP, each attribute you pick will echo the tag name to the command line (so you'll know it is picked). press enter to finish picking attributes, than all the relevant block references is auto selected and the populate field code will be preformed. the selected attributes are skipped and not be modified.

 

at finish do a REGEN to see the change 😀

 

enjoy

Moshe

 

OH, one more thing:

this task could all be done more easily with pure lisp without using field. cause fields i given to ones (and AutoCAD LT) that does not write lisp code or has no one to write for. it's true when there is a field and the block moves the attribute is update (after a regen or updatefield) but if there isn't field the lisp can be run and the result is the same.

 

Am i right?

 

 

0 Likes
Message 15 of 30

Anonymous
Not applicable

Many thanks, that would be great but I couldn't get it work. I type PATTFC, select the attributes, enter, REGEN, but nothing happens.

 

0 Likes
Message 16 of 30

Moshe-A
Mentor
Mentor

relocate the blocks a little. if you are not testing it with example.dwg? then post your current dwg.

 

 

 

 

0 Likes
Message 17 of 30

Anonymous
Not applicable

Yes I am using example.dwg, still not working. If you tested it on the same file I am surely doing something wrong, but don't know what...

0 Likes
Message 18 of 30

Moshe-A
Mentor
Mentor

maybe this:

when you select source attributes you only have to select one attribute (no all of them) cause the selected attributes are skipped from modify.

 

OK here is an update, this one pauses to ask if you also want to update the selected attribues?

only if you select No the selected attributes are skipped.

 

works?

 

0 Likes
Message 19 of 30

Anonymous
Not applicable

No sorry, still not working. Did you test it on example.dwg and it worked?

0 Likes
Message 20 of 30

Moshe-A
Mentor
Mentor

yes i'm developing the lisp based on example.dwg and it work prefect.

 

PATTFC stands for Populate Attributes Field Code that means populating only attributes that has field code value and skip non field code value. your example.dwg came with 3 inserts that has no field code but the block definition does have it, so run ATTSYNC (or BATTMAN) to update the inserts. remember that only the selected attributes must have the field code in order it to work.

 

 

0 Likes