+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16
  1. #1
    Full Member chauncy274's Avatar
    Computer Details
    chauncy274's Computer Details
    Operating System:
    Windows 7
    RAM:
    8 Gig
    Monitor:
    2 Dell LCD Screens
    Using
    AutoCAD 2015
    Join Date
    Sep 2008
    Location
    Baton Rouge, Louisiana
    Posts
    55

    Default changing attribute text width without having to select the block...

    Registered forum members do not see this ad.

    Hey guys I'm running in to a problem and I don't quite have time to sit down and figure it out and I don't know where else to look.

    I have a block in many drawings that I managed to auto fill with information from our database using a lisp routine from Lee Mac (you're a genius lol) but the entries for one of the attributes is just slightly too long and I need a lisp routine (or if anyone has any other idea) where I can just type the known block name and attribute tag and the new text width that's wanted and when I call up the lisp routine it just goes in and does it without any prompting. This way I could batch the lisp routine across these thousand plus drawings. It would also be great if it could manage to not crap out if the drawing doesn't have an instance of that block since there are a handful of drawings that don't have the block in the drawing, but I can work around that.

    I've tried writing a script that redefines the block and that works fine but it won't change the text width of the attribute, it only affects the changes I make to the lines of the block. Weird.

    Any ideas?

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,535

    Default

    Quote Originally Posted by chauncy274 View Post
    I've tried writing a script that redefines the block and that works fine but it won't change the text width of the attribute, it only affects the changes I make to the lines of the block. Weird.
    Attribute References are associated with a Block Reference and their appearance is driven by the properties of the corresponding Attribute Definitions, however they are considered separate to and can be manipulated independently of the Block Definition, enabling Attribute References to hold differing values & properties between multiple Block References.

    Therefore, if you perform modifications to the properties of the Attribute Definition within the Block Definition, these changes will not be reflected across all references of the block until an ATTSYNC operation is performed.

    Alternatively, you can try the following code:
    Code:
    (defun c:changeattribwidth ( / blk idx obj sel tag wid )
    
        (setq blk "MyBlock" ;; Block Name(s) - allows wildcards
              tag "MyTag"   ;; Attribute Tag(s) to Modify - allows wildcards
              wid 0.5       ;; New Attribute Width
        )
        (if (setq sel (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 blk))))
            (repeat (setq idx (sslength sel))
                (if
                    (or
                        (and
                            (vlax-property-available-p (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))) 'effectivename)
                            (wcmatch (strcase (vla-get-effectivename obj)) (strcase blk))
                        )
                        (wcmatch (strcase (vla-get-name obj)) (strcase blk))
                    )
                    (foreach att (vlax-invoke obj 'getattributes)
                        (if
                            (and
                                (wcmatch (strcase (vla-get-tagstring att)) (strcase tag))
                                (vlax-write-enabled-p att)
                            )
                            (vla-put-scalefactor att wid)
                        )
                    )
                )
            )
        )
        (vlax-for def (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
            (if (wcmatch (strcase (vla-get-name def)) (strcase blk))
                (vlax-for obj def
                    (if 
                        (and
                            (= "AcDbAttributeDefinition" (vla-get-objectname obj))
                            (wcmatch (strcase (vla-get-tagstring obj)) (strcase tag))
                            (vlax-write-enabled-p obj)
                        )
                        (vla-put-scalefactor obj wid)
                    )
                )
            )
        )
        (princ)
    )
    (vl-load-com) (princ)
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Full Member chauncy274's Avatar
    Computer Details
    chauncy274's Computer Details
    Operating System:
    Windows 7
    RAM:
    8 Gig
    Monitor:
    2 Dell LCD Screens
    Using
    AutoCAD 2015
    Join Date
    Sep 2008
    Location
    Baton Rouge, Louisiana
    Posts
    55

    Default

    Quote Originally Posted by Lee Mac View Post
    Attribute References are associated with a Block Reference and their appearance is driven by the properties of the corresponding Attribute Definitions, however they are considered separate to and can be manipulated independently of the Block Definition, enabling Attribute References to hold differing values & properties between multiple Block References.

    Therefore, if you perform modifications to the properties of the Attribute Definition within the Block Definition, these changes will not be reflected across all references of the block until an ATTSYNC operation is performed.
    Brilliant like always Lee Mac. I really appreciate this it worked beautifully.

    I've ben reading up on the attsync command but still haven't gotten it to work. I have 1 instance of this block (called "DCS 1") in a thousand different drawings. I created the block in a template drawing file and then we've been making copies of this template file to create all these new drawings. If I were to change the width in the original file and then ATTSYNC it would update all drawings? Or run ATTSYNC in all drawings would update all of the drawings accordingly? Or does ATTSYNC only sync them within that one drawings?

    I appreciate the advice greatly. Thanks.

  4. #4
    Full Member chauncy274's Avatar
    Computer Details
    chauncy274's Computer Details
    Operating System:
    Windows 7
    RAM:
    8 Gig
    Monitor:
    2 Dell LCD Screens
    Using
    AutoCAD 2015
    Join Date
    Sep 2008
    Location
    Baton Rouge, Louisiana
    Posts
    55

    Default

    Ok, I think I understand a bit more about the attsync command, and if I'm not mistaken I can even do this through a script file?

    as in:
    -INSERT
    oldblock=newblock.dwg
    Y
    (COMMAND \e "RESUME")
    attsync
    name
    oldblock

    So attsync sync up the attributes to what ever they are on the official block definition, which only changes if you redefine the actual block definition by insert= or editing the block in the drawing?

  5. #5
    Senior Member
    Computer Details
    Happy Hobbit's Computer Details
    Operating System:
    Win 7
    Discipline
    Electrical
    Using
    AutoCAD 2014
    Join Date
    Jun 2012
    Location
    Dorset, England
    Posts
    175

    Default

    There's also RedefineBlockText also by Lee (post #9), which I use a lot. It's excellent

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,535

    Default

    Quote Originally Posted by chauncy274 View Post
    Brilliant like always Lee Mac. I really appreciate this it worked beautifully.
    Excellent to hear.

    Quote Originally Posted by chauncy274 View Post
    I have 1 instance of this block (called "DCS 1") in a thousand different drawings. I created the block in a template drawing file and then we've been making copies of this template file to create all these new drawings.

    If I were to change the width in the original file and then ATTSYNC it would update all drawings? Or run ATTSYNC in all drawings would update all of the drawings accordingly? Or does ATTSYNC only sync them within that one drawings?
    Firstly, when a drawing is created using a drawing template, the settings from the template file are merely copied to the new drawing - there is absolutely no associativity between the template and new drawing (you cannot determine which template was used to create a drawing), and so making changes to the template will not affect any existing drawings.

    The ATTSYNC command will only operate on blocks within the active drawing.

    Quote Originally Posted by chauncy274 View Post
    Ok, I think I understand a bit more about the attsync command, and if I'm not mistaken I can even do this through a script file?

    as in:
    -INSERT
    oldblock=newblock.dwg
    Y
    (COMMAND \e "RESUME")
    attsync
    name
    oldblock

    So attsync sync up the attributes to what ever they are on the official block definition, which only changes if you redefine the actual block definition by insert= or editing the block in the drawing?
    Yes, this is another way to modify the blocks, however, be aware that the ATTSYNC command will restore all properties (including geometric properties) of all attribute references held by the block to match those held by the corresponding attribute definitions within the block definition - this includes the position of attribute references relative to the block reference (if the 'Lock Position' property is not enabled).
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  7. #7
    Full Member chauncy274's Avatar
    Computer Details
    chauncy274's Computer Details
    Operating System:
    Windows 7
    RAM:
    8 Gig
    Monitor:
    2 Dell LCD Screens
    Using
    AutoCAD 2015
    Join Date
    Sep 2008
    Location
    Baton Rouge, Louisiana
    Posts
    55

    Default

    Quote Originally Posted by Lee Mac View Post
    Excellent to hear.

    Firstly, when a drawing is created using a drawing template, the settings from the template file are merely copied to the new drawing - there is absolutely no associativity between the template and new drawing (you cannot determine which template was used to create a drawing), and so making changes to the template will not affect any existing drawings.
    That's what I've always thought, I was just trying to figure out the command and it's the only thing I could think of atm. Thanks for clearing it up.
    Quote Originally Posted by Lee Mac View Post
    The ATTSYNC command will only operate on blocks within the active drawing.

    Yes, this is another way to modify the blocks, however, be aware that the ATTSYNC command will restore all properties (including geometric properties) of all attribute references held by the block to match those held by the corresponding attribute definitions within the block definition - this includes the position of attribute references relative to the block reference (if the 'Lock Position' property is not enabled).
    Right. That makes sense. Unfortunately for me that does bring up a certain problem for me. There is one attribute in the block that has been shrunk down to numerous different widths to fit with whatever tag number has been placed in it. So if I re-insert and attsync on all drawings some of the tags will be either too wide, or I'll have to make them all on the smaller side so they fit.


    I think your lisp routine that you typed up for me is the best option for this scenario. Thanks so much for all the help.

  8. #8
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,535

    Default

    You're most welcome, I'm glad it helps.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  9. #9
    Full Member chauncy274's Avatar
    Computer Details
    chauncy274's Computer Details
    Operating System:
    Windows 7
    RAM:
    8 Gig
    Monitor:
    2 Dell LCD Screens
    Using
    AutoCAD 2015
    Join Date
    Sep 2008
    Location
    Baton Rouge, Louisiana
    Posts
    55

    Default

    Lee-Mac,

    I've been going over your code just to get a better understanding of it and I'm trying to figure out the logic of a part of it. I'm hoping you can explain the purpose of it?

    Code:
                (if
                    (or
                        (and
                            (vlax-property-available-p (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))) 'effectivename)
                            (wcmatch (strcase (vla-get-effectivename obj)) (strcase blk))
                        )
                        (wcmatch (strcase (vla-get-name obj)) (strcase blk))
                    )
                    (foreach att (vlax-invoke obj 'getattributes)
                        (if
                            (and
                                (wcmatch (strcase (vla-get-tagstring att)) (strcase tag))
                                (vlax-write-enabled-p att)
                            )
                            (vla-put-scalefactor att wid)
                        )
                    )
                )
    The (or(and section of the code, is it so that it will work on dynamic blocks as well? As in "vla-get-effectivename" gets you the name of a dynamic block and "vla-get-name" gets you the name from a standard block? I can't find much info on either of those commands and I'm not sure why you'd need both of them unless it was something like that?

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,535

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by chauncy274 View Post
    The (or(and section of the code, is it so that it will work on dynamic blocks as well? As in "vla-get-effectivename" gets you the name of a dynamic block and "vla-get-name" gets you the name from a standard block?
    The ActiveX effectivename property is required to obtain the 'true' name of a dynamic block (as dynamic blocks reference anonymous block definitions when the dynamic block parameters differ from the dynamic block definition).

    The effectivename property will return the correct block name for both dynamic blocks and standard blocks, however, this property will not be available in AutoCAD versions in which dynamic blocks are not available, hence the vlax-property-available-p test is required to account for this, with the alternative of obtaining the ActiveX name property.

    Quote Originally Posted by chauncy274 View Post
    I can't find much info on either of those commands and I'm not sure why you'd need both of them unless it was something like that?
    See:

    Effective Block Name

    Get Anonymous References
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Select a block by attribute?
    By titoprax in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 18th May 2016, 08:39 pm
  2. Changing the width factor of a text
    By OLDandPR0UD in forum 3D Modelling
    Replies: 5
    Last Post: 27th Mar 2015, 11:38 pm
  3. Changing Width Factor of Text
    By Kenter in forum AutoLISP, Visual LISP & DCL
    Replies: 17
    Last Post: 4th Aug 2010, 10:15 pm
  4. select all Attribute text to change colour
    By VisDak in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 2nd Jun 2009, 11:32 am
  5. Attribute height and width factor - changing many at once?
    By Kad in forum AutoCAD Drawing Management & Output
    Replies: 4
    Last Post: 30th Aug 2005, 12:01 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts