Jump to content
tmelancon

Dynamically Scale Attribute Within A Block

Recommended Posts

tmelancon

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.

Share this post


Link to post
Share on other sites
Lee Mac

@tmelancon Thank you for your praise & gratitude for my work.

 

In response to your request, have you first considered my existing Dynamic Attribute Width program?

Share this post


Link to post
Share on other sites
tmelancon

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!

Share this post


Link to post
Share on other sites
Lee Mac

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.

Share this post


Link to post
Share on other sites
tmelancon

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.

Share this post


Link to post
Share on other sites
Lee Mac

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

Share this post


Link to post
Share on other sites
tmelancon
Posted (edited)

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

Share this post


Link to post
Share on other sites
tmelancon

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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