Jump to content
eyeofnewt555

Batch change all block attributes to "Preset: Yes"

Recommended Posts

eyeofnewt555

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!

Share this post


Link to post
Share on other sites
13lade001

You could turn off ATTREQ for them and reset it when your done or in the event of an error in your code. See Lee Mac's error handling page under the heading "Resetting the User Environment" that does this for the osm system variable.

Share this post


Link to post
Share on other sites
Lee Mac

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)

Share this post


Link to post
Share on other sites
eyeofnewt555

You are a god among men. Thank you, Lee!

Share this post


Link to post
Share on other sites
Lee Mac

You're welcome, I'm glad it helps.

Share this post


Link to post
Share on other sites
kevinpo

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

Share this post


Link to post
Share on other sites
BIGAL

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

Share this post


Link to post
Share on other sites
kevinpo

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

Share this post


Link to post
Share on other sites
Lee Mac

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)

Share this post


Link to post
Share on other sites
Grrr

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.

Share this post


Link to post
Share on other sites
kevinpo

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

Share this post


Link to post
Share on other sites
kevinpo

Thanks GRR. This worked!

Share this post


Link to post
Share on other sites
kevinpo

Hello Grrr,

Is there a way to get it to change the block giving the name and without having to pick?

Share this post


Link to post
Share on other sites
kevinpo

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

Share this post


Link to post
Share on other sites
Grrr

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.

Share this post


Link to post
Share on other sites
BIGAL

No worries Grr always learning

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×