Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Change attribute textstyle within block

  1. #1
    Member
    Join Date
    2013-03
    Posts
    4
    Login to Give a bone
    0

    Default Change attribute textstyle within block

    Hi All

    I am trying to create a lisp routine to change the attribute textstyle within a block and there are a multiple of different block to be changed within the same drawing.

    This is also to be applied to many drawings to bring them into line with the updated CAD standards.

    I have attached what I have so far, but it does not loop through the blocks.

    Any help appreciated.
    Attached Files Attached Files

  2. #2
    Member
    Join Date
    2006-12
    Location
    Cascais, Portugal
    Posts
    25
    Login to Give a bone
    0

    Default Re: Change attribute textstyle within block

    We need to loop through the blocks, and through the inserts to change all attributes style.

    As a 'demo'
    Code:
    (vl-load-com)
    (defun c:demo (/ atts i obj ss)
       (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
       (vlax-for blks (vla-get-blocks adoc)
          (if (= :vlax-false (vla-get-isxref blks))
             (vlax-for blk blks
                (if (= (vla-get-objectname blk) "AcDbAttributeDefinition")
                   (vla-put-stylename blk "MyStyleName")
                )
             )
          )
       )
       (if (setq ss (ssget "X" '((0 . "INSERT") (66 . 1))))
          (repeat (setq i (sslength ss))
             (setq obj  (vlax-ename->vla-object (ssname ss (setq i (1- i))))
                   atts (vlax-invoke obj 'getattributes)
             )
             (foreach att atts
                (vla-put-stylename att "MyStyleName")
             )
          )
       )
       (vla-regen adoc acallviewports)
       (princ)
    )
    Hope this helps,
    henrique

  3. #3
    Member
    Join Date
    2013-03
    Posts
    4
    Login to Give a bone
    0

    Default Re: Change attribute textstyle within block

    Hi Henrique
    Sorry for the delay in responding, but I have been side tracked by another project.
    Thank for the reply, yes this works excellent.
    Another question, I have to check the current text styles and then use a condition statement to change the style to the new value.
    Are you able to help?
    I have attached a sample of the cond statement.
    regards
    Steve
    Attached Files Attached Files

  4. #4
    Member
    Join Date
    2006-12
    Location
    Cascais, Portugal
    Posts
    25
    Login to Give a bone
    0

    Default Re: Change attribute textstyle within block

    Hi Steve,
    if we use 'strcase' function when we set 'ts', the return will be in uppercase...
    The 'ht' variable is a real number???
    Code:
    (cond
        ((= ts "TXT-13") (setq newval "13-TEXT"))
        ((= ts "TXT-18") (setq newval "18-TEXT"))
        ((= ts "TXT-25") (setq newval "25-TEXT"))
        ((= ts "TXT-35") (setq newval "35-TEXT"))
        ((= ts "TXT-5") (setq newval "5-TEXT"))
        ((= ts "TXT-7") (setq newval "7-TEXT"))
        ((and (= ts "ROMANS") (vl-position ht '(1.3 2.6 6.5 13.0 26.0 32.5 65.0 130.0)))
         (setq newval "13-TEXT")
        )
        ((and (= ts "ROMANS") (vl-position ht '(1.8 3.6 9.0 18.0 36.0 45.0 90.0 180.0)))
         (setq newval "18-TEXT")
        )
        ((and (= ts "ROMANS") (= ht 250.0))
         (setq newval "25-TEXT")
        )
        ((and (= ts "ROMANS") (vl-position ht '(3.5 7.0 17.5 35.0 70.0 87.5 175.0 350.0)))
         (setq newval "35-TEXT")
        )
        ((and (= ts "ROMANS") (vl-position ht '(5.0 10.0 25.0 50.0 100.0 125.0 250.0 500.0)))
         (setq newval "5-TEXT")
        )
     ;if none of the above conditions is true, and ts= ROMANS, change to "7-TEXT"
        ((= ts "ROMANS") (setq newval "7-TEXT"))
    ) ;end cond
    Henrique

  5. #5
    Member
    Join Date
    2013-03
    Posts
    4
    Login to Give a bone
    0

    Default Re: Change attribute textstyle within block

    Hi Henrique
    Attached is current program, but I am having trouble associating variables for the fist part, BLOCKS.
    I an been able to convert the ActiveX name to a lisp name and set variable "nam", but I am unable to extract any text variables from this "block" object.
    The lower section, attribute definition, seems to work.
    Any help appreciated.
    Regards
    Steve

    - - - Updated - - -

    Hi Henrique

    Also I have attached a sample drawing I am using.

    It is a block with attributes imbedded.
    Attached Files Attached Files

  6. #6
    I could stop if I wanted to
    Join Date
    2006-04
    Posts
    466
    Login to Give a bone
    0

    Default Re: Change attribute textstyle within block

    Good Luck!

    I recommend using 'filter to select blocks
    Attached Files Attached Files
    Last edited by aaronic_abacus; 2016-08-10 at 02:31 PM.

  7. #7
    Member
    Join Date
    2017-01
    Posts
    3
    Login to Give a bone
    0

    Default Re: Change attribute textstyle within block

    Thanks a bunch this is just what I need, would it be possible though to be able to select multiple entities when actually changing the "textstyle" instead of just the 1 ?

  8. #8
    I could stop if I wanted to
    Join Date
    2006-04
    Posts
    466
    Login to Give a bone
    0

    Default Re: Change attribute textstyle within block

    Code:
    (DEFUN C:CAS (/ BS BSL CT NOFUV NOFNU LP NE NEL NEAET NEA NEAS OFNU NNEL)
     (PROMPT "\n*CHANGE ATTRIBUTE STYLE* ")
     (PROMPT "\nSelect block with attributes to change: ")
     (SETQ BS (SSGET '((-4 . "<AND") (0 . "INSERT") (66 . 1) (-4 . "AND>")) ))
     (SETQ BSL (SSLENGTH BS))
     (SETQ CT (- BSL 1))
     (SETQ NOFUV (GETSTRING "\nNew attribute style: "))
     (SETQ LP 1)
     (WHILE LP
      (SETQ NE (SSNAME BS CT))
      (SETQ CT2 0)
      (SETQ LP2 1)
      (WHILE LP2
       (SETQ NE (ENTNEXT NE))
       (SETQ NEL (ENTGET NE))
       (SETQ NEAET (CDR (ASSOC 0 NEL)))
       (SETQ NEA (ASSOC 7 NEL))
       (SETQ NEAS (CDR NEA))
       (IF (= NEAET "ATTRIB") 
        (PROGN
         (IF (/= NEA NIL)
          (PROGN
           (SETQ NOFNU (CONS 7 NOFUV))
           (SETQ OFNU NEA)
           (SETQ NNEL (SUBST NOFNU OFNU NEL))
           (ENTMOD NNEL)
           (ENTUPD NE)
         ));END PROGN/IF NEA
       ));END PROGN/IF NEAET
       (IF (= NEAET "SEQEND") (SETQ LP2 NIL))
      );END WHILE LP2
      (SETQ CT (- CT 1))
      (IF (< CT 0) (SETQ LP NIL))
     );END WHILE LP
     (PRINC)
    );END CAS
    Attached Files Attached Files
    Last edited by aaronic_abacus; 2017-04-28 at 11:45 AM.

  9. #9
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,505
    Login to Give a bone
    0

    Default Re: Change attribute textstyle within block

    Quote Originally Posted by aaronic_abacus View Post
    Code:
     (DEFUN C:CAS (/ BS BSL CT NOFUV NOFNU LP NE NEL NEAET NEA NEAS OFNU NNEL)
    (PROMPT "\n*CHANGE ATTRIBUTE STYLE* ")
     (PROMPT "\nSelect block with attributes to change: ")
     (SETQ BS (SSGET '((-4 . "<AND") (0 . "INSERT") (66 . 1) (-4 . "AND>")) ))
     (SETQ BSL (SSLENGTH BS))
     (SETQ CT (- BSL 1))
     (SETQ NOFUV (GETSTRING "\nNew attribute style: "))
     (SETQ LP 1)
     (WHILE LP
      (SETQ NE (SSNAME BS CT))
      (SETQ CT2 0)
      (SETQ LP2 1)
      (WHILE LP2
       (SETQ NE (ENTNEXT NE))
       (SETQ NEL (ENTGET NE))
       (SETQ NEAET (CDR (ASSOC 0 NEL)))
       (SETQ NEA (ASSOC 7 NEL))
       (SETQ NEAS (CDR NEA))
       (IF (= NEAET "ATTRIB") 
        (PROGN
         (IF (/= NEA NIL)
          (PROGN
           (SETQ NOFNU (CONS 7 NOFUV))
           (SETQ OFNU NEA)
           (SETQ NNEL (SUBST NOFNU OFNU NEL))
           (ENTMOD NNEL)
           (ENTUPD NE)
         ));END PROGN/IF NEA
       ));END PROGN/IF NEAET
       (IF (= NEAET "SEQEND") (SETQ LP2 NIL))
      );END WHILE LP2
      (SETQ CT (- CT 1))
      (IF (< CT 0) (SETQ LP NIL))
     );END WHILE LP
     (PRINC)
    );END CAS
    Hey there.. I see you're not new here,
    please remember to use "code tags" when posting code, as you can see it's easier to read/scroll etc. and keeps your formatting.

    You simply format it like so: [ code ] your code here [ /code ]
    (I added spaces at the brackets for visual purposes, you wouldn't have those spaces when actually doing this)

  10. #10
    I could stop if I wanted to
    Join Date
    2006-04
    Posts
    466
    Login to Give a bone
    0

    Default Re: Change attribute textstyle within block

    thanks ted! I forgot how to use the CODE tags :O

Page 1 of 2 12 LastLast

Similar Threads

  1. How to change dynamic block attribute default values based on block selected?
    By zeirz109180 in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2013-12-13, 02:20 PM
  2. Replies: 13
    Last Post: 2012-09-18, 07:51 PM
  3. Change existing text to new Textstyle
    By Mater in forum AutoLISP
    Replies: 7
    Last Post: 2011-04-28, 03:42 AM
  4. Block attribute change within a table...
    By seneb in forum AutoCAD General
    Replies: 2
    Last Post: 2009-01-29, 07:45 PM
  5. Help with Text / TextStyle change routine
    By newfoundfreedom in forum VBA/COM Interop
    Replies: 2
    Last Post: 2007-05-10, 04:56 PM

Posting Permissions

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