Jump to content

Recommended Posts

Posted

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!

Posted

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.

Posted

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)

Posted

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

  • 4 months later...
Posted

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

Posted

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

Posted

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

Posted

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)

Posted

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.

Posted

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

Posted

Hello Grrr,

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

Posted (edited)

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
Posted

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.

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