Jump to content

Batch change all block attributes to "Preset: Yes"


eyeofnewt555

Recommended Posts

I've got a ton of blocks, each with the same attribute but different preset values. Obnoxiously, when they're inserted the dialogue box to edit the attribute value pops up (problem described here). I know this can be suppressed with ATTREQ, but I'd rather folks not have to change any settings and for this to work smoothly on its own.

 

So, rather than manually going through and changing each attribute to preset > yes, anyone got a handy LISP for it?

 

Thanks!

Link to comment
Share on other sites

Try the following:

(defun c:presetattdefs nil
   (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
       (if (= :vlax-false (vla-get-islayout blk) (vla-get-isxref blk))
           (vlax-for obj blk
               (if (and (= "AcDbAttributeDefinition" (vla-get-objectname obj)) (vlax-write-enabled-p obj))
                   (vla-put-preset obj :vlax-true)
               )
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)

Link to comment
Share on other sites

  • 4 months later...

Hello Lee,

Is there a way of just changing one block (Tag-Revision) to a false preset?

I am trying but keep getting tangled up in code.

 

Thanks,

Kevin

Link to comment
Share on other sites

Try this for one

 

(setq obj (vlax-ename->vla-object (car (entsel "\nPick "))))
(if (and (= "AcDbAttributeDefinition" (vla-get-objectname obj)) (vlax-write-enabled-p obj))
(vla-put-preset obj :vlax-false)
)

Link to comment
Share on other sites

Thank you for the quick response but it didn't seem to change the Preset to No/false.

I simply want to change the one attribute in the block definition to have the preset set to no. if I look at it in the properties palette in block editor it still says Yes for preset. I tried attsync after too and that still didn't change. I'd like to not have to select the block but rather just fix it if its in the drawing.

Thank you!!

Link to comment
Share on other sites

The following will change attributes with tag REVISION in all blocks:

(defun c:presetattdefs nil
   (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
       (if (= :vlax-false (vla-get-islayout blk) (vla-get-isxref blk))
           (vlax-for obj blk
               (if (and (= "AcDbAttributeDefinition" (vla-get-objectname obj)) (vlax-write-enabled-p obj) [color=red](= "REVISION" (strcase (vla-get-tagstring obj)))[/color])
                   (vla-put-preset obj [color=red]:vlax-false[/color])
               )
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)

Link to comment
Share on other sites

BIGAL,

Attribute Definitions are contained inside the Block's definition, while

Attribute References are contained inside the Block's reference, hence:

 

(defun C:test nil
 (vlax-map-collection
   (vla-item
     (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object)))
     (vla-get-EffectiveName (vlax-ename->vla-object (car (entsel "\nSelect a block: "))))
   )
   (quote
     (lambda (o) 
       (and 
         (vlax-write-enabled-p o) 
         (eq "AcDbAttributeDefinition" (vla-get-ObjectName o))
         (vla-put-Preset o :vlax-false)
       )
     )
   )
 )
)

 

I don't really know what that code should do, but it should work.

Link to comment
Share on other sites

Thanks Lee,

For some reason I still cannot get the Preset to change. This didn't work.

Is there a way I can just check to see if the preset is set to Yes in my block "Tag-Revision" so I can make a conditional workaround?

 

Thanks

Link to comment
Share on other sites

I got it, Thanks buys.

(defun C:test nil
 (vlax-map-collection
   (vla-item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) "Tag-Revision")
   (quote
     (lambda (o) 
       (and 
         (vlax-write-enabled-p o) 
         (eq "AcDbAttributeDefinition" (vla-get-ObjectName o))
         (vla-put-Preset o :vlax-false)
       )
     )
   )
 )
)

Edited by SLW210
Code Tags
Link to comment
Share on other sites

I'm glad that it worked for you kevinpo, and that you figured out the solution for your problem by yourself!

Lee's code works but your question misleaded to: attribute definition with a tag name of "Revision", although he was clear enough what his code does.

 

I just tried to correct BIGAL, and to practice a bit.

Link to comment
Share on other sites

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