Jump to content

Dynamically Scale Attribute Within A Block


tmelancon

Recommended Posts

BRILLIANT code by Lee Mac helping another user out on the webs... Thank you Lee for your years of dedication to the AutoCAD/Code world!

(defun changeattributewidth ( tag wid / typ )
   (setq tag (strcase tag))
   (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
       (if (= :vlax-false (vla-get-isxref blk))
           (vlax-for obj blk
               (cond
                   (   (= "AcDbBlockReference" (setq typ (vla-get-objectname obj)))
                       (foreach att (vlax-invoke obj 'getattributes)
                           (if (and (= tag (strcase (vla-get-tagstring att))) (vlax-write-enabled-p att))
                               (vla-put-scalefactor att wid)
                           )
                       )
                   )
                   (   (and (= "AcDbAttributeDefinition" typ)
                            (= tag (vla-get-tagstring obj))
                            (vlax-write-enabled-p obj)
                       )
                       (vla-put-scalefactor obj wid)
                   )
               )
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)

Evaluate with tag name (case-insensitive) and new attribute width factor, e.g.:

(changeattributewidth "tag" 0.7)

 

I was just curious to see if there was a way to edit the code so upon command and selection of block it allows user to dynamically scale the attribute (just like running the regular scale command on any other text).. this way if the text within a titleblock is too long and the user is unsure of exactly how much shorter it needs to be then he/she can just quickly run shortcut command, click on block/attribute, automatically step into block, select attribute, and the user can drag mouse to scale up or down dynamically.

 

Any and all help is so so much appreciate. Blessings.

Link to comment
Share on other sites

Oh such a beautiful program! I apologize for not even looking on your site first. Forgive me. Would it be possible to mod it for both height and width? Killer LISP!

Link to comment
Share on other sites

Thanks - I'm glad you like it.

 

Modifying the program for both height & width is not quite as straightforward, as, whilst the width factor can scale the width independently of the height, changing the height also impacts the width.

Link to comment
Share on other sites

Lee,

 

I hope you don't mind. I changed the DXF code "41" to "40" throughout and this is exactly what I needed. BOOM! Thanks man! LISP is for personal use and of course the modified version will not be shared.

Link to comment
Share on other sites

Not at all - I thought you were looking to change the height independently of the width, but if that works as you require, that's great :)

Link to comment
Share on other sites

What would be awesome is if this code could be modded to where when the user steps in and selects the attribute text, dragging the cursor freely, up and down changes the height and side to side changes the width. Ultimately making the text precisely what you want it to look like and fit in to whatever space you wanted regardless of how it looked.

Edited by tmelancon
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...