See the top rated post in this thread. Click here

Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: Edit Attributes Programatically

  1. #1
    I could stop if I wanted to artisteroi's Avatar
    Join Date
    2007-02
    Location
    Tampa, FL
    Posts
    271
    Login to Give a bone
    0

    Lightbulb Edit Attributes Programatically

    Anyone know how to update a given attribute in a group of blocks all at once?
    What I am trying to do is select All Blocks in a drawing and then change the attribute that they all have in common. Is there a way to do that? Maybe a lisp or vba or script but preferably a macro that I can tie to an icon or maybe the icon can just call the other file. Tough one eh?

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

    Default Re: Edit Attributes Programatically

    ;This autolisp program globally edits attribute values of the selected block name.

    Code:
    (DEFUN C:SAV ()
    (PROMPT "\n*SET ATTRIBUTE VALUES*")
    (SETQ BE (CAR (ENTSEL "\nSelect block entity for name: ")))
    (SETQ BEL (ENTGET BE))
    (SETQ BELBN (CDR (ASSOC 2 BEL)))
    (SETQ BELBNF (LIST (CONS 2 BELBN)))
    (SETQ TMV (GETVAR "TILEMODE"))
    (SETVAR "TILEMODE" 1)
    (SETQ BS (SSGET "X" BELBNF))
    (SETVAR "TILEMODE" TMV)
    (SETQ BSL (SSLENGTH BS))
    (SETQ CT (- BSL 1))
    (SETQ NEAS (CAR (NENTSEL "\nSelect attribute to change: ")))
    (SETQ NEASL (ENTGET NEAS))
    (SETQ NEASLAN (CDR (ASSOC 2 NEASL)))
    (PROMPT "\nNew attribute value: ")
    (SETQ NOFUV (READ-LINE))
    (SETQ NOFNU (CONS 1 NOFUV))
    (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 (CDR (ASSOC 2 NEL)))
      (IF (= NEA NEASLAN) 
       (PROGN
        (SETQ OFNU (ASSOC 1 NEL))
        (SETQ NNEL (SUBST NOFNU OFNU NEL))
        (ENTMOD NNEL)
      ));END PROGN/IF
      (IF (= NEAET "SEQEND") (SETQ LP2 NIL))
     );END WHILE LP2
     (SETQ CT (- CT 1))
     (IF (< CT 0) (SETQ LP NIL))
    );END WHILE LP
    (COMMAND "REGEN")
    (PRINC)
    );END SAV
    Attached Files Attached Files

  3. #3
    I could stop if I wanted to artisteroi's Avatar
    Join Date
    2007-02
    Location
    Tampa, FL
    Posts
    271
    Login to Give a bone
    0

    Unhappy Re: Edit Attributes Programatically

    almost. All the blocks have different names. Guess I should have mentioned that.

  4. #4
    Active Member rcrabb's Avatar
    Join Date
    2007-02
    Posts
    99
    Login to Give a bone
    0

    Default Re: Edit Attributes Programatically

    i posted a solution in your VBA thread that may be helpful

  5. #5
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    2

    Default Re: Edit Attributes Programatically

    So you want to select all blocks within a drawing
    Code:
    (setq ss (ssget '((0 . "INSERT"))))
    Now you have your selection set of blocks, you need to step through them to find the attributes for each one. But you only want to change a certain one, so we need to know the tag name. For now we will use 'TAGNAME'.

    First we need to step through the selection set. We will use the counter way.
    Code:
    (setq cnt 0)
    (while (setq Ent (ssname ss cnt))
    This is saying while 'cnt' (a number) equals and entity ('Ent') within the selection set ('ss') we want something to happen. When then number is larger than the amount in the selection set it will return nil, so the while loop will end.

    So 'Ent' is out block entity, so now we can step though the blocks sub-entities (attributes).

    Code:
    (while
     (and
      (setq Ent (entnext Ent))
      (setq EntData (entget Ent))
      (= (cdr (assoc 0 EntData)) "ATTRIB")
     )
    Here we have to use entnext to get the sub-entity. Once we get one, entnext will go to the next one sub entity. Then we get the dxf code that makes up the entity (see help if you need to understand what this is). Then we want to make sure that the entity is an attribute, that is what 'ATTRIB' stands for.

    Now that we are looking at all the attributes, we want to only change the one we want 'TAGNAME' (dxf code 2 is the tag), so we will use an if statement to test it, and if it is the name we want we will change the text of it (dxf code 1).
    Code:
    (if (= (cdr (assoc 2 EntData)) "TAGNAME")
     (entmod (subst (cons 1 "Updated Text!") (assoc 1 EntData) EntData))
    )
    Hope that makes sense.

    So the whole code will look like
    Code:
    (setq ss (ssget '((0 . "INSERT"))))
    (setq cnt 0)
    (while (setq Ent (ssname ss cnt))
     (while
      (and
       (setq Ent (entnext Ent))
       (setq EntData (entget Ent))
       (= (cdr (assoc 0 EntData)) "ATTRIB")
      )
      (if (= (cdr (assoc 2 EntData)) "TAGNAME")
       (entmod (subst (cons 1 "Updated Text!") (assoc 1 EntData) EntData))
      )
     )
     (setq cnt (1+ cnt)) ; used to get the next item in the selection set
    )

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

    Default Re: Edit Attributes Programatically

    This autolisp program is a revision of SAV.LSP that now globally edits attribute values of any block containing the selected attribute name.
    Code:
    (DEFUN C:SAV2 ()
    (PROMPT "\n*SET ATTRIBUTE VALUES*")
    (SETQ TMV (GETVAR "TILEMODE"))
    (SETVAR "TILEMODE" 1)
    (SETQ BS (SSGET "X" '((-4 . "<AND") (0 . "INSERT") (66 . 1) (-4 . "AND>")) ))
    (SETVAR "TILEMODE" TMV)
    (SETQ BSL (SSLENGTH BS))
    (SETQ CT (- BSL 1))
    (SETQ NEAS (CAR (NENTSEL "\nSelect attribute to change: ")))
    (SETQ NEASL (ENTGET NEAS))
    (SETQ NEASLAN (CDR (ASSOC 2 NEASL)))
    (PROMPT "\nNew attribute value: ")
    (SETQ NOFUV (READ-LINE))
    (SETQ NOFNU (CONS 1 NOFUV))
    (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 (CDR (ASSOC 2 NEL)))
      (IF (= NEA NEASLAN) 
       (PROGN
        (SETQ OFNU (ASSOC 1 NEL))
        (SETQ NNEL (SUBST NOFNU OFNU NEL))
        (ENTMOD NNEL)
      ));END PROGN/IF
      (IF (= NEAET "SEQEND") (SETQ LP2 NIL))
     );END WHILE LP2
     (SETQ CT (- CT 1))
     (IF (< CT 0) (SETQ LP NIL))
    );END WHILE LP
    (COMMAND "REGEN")
    (PRINC)
    );END SAV2
    Attached Files Attached Files

  7. #7
    I could stop if I wanted to artisteroi's Avatar
    Join Date
    2007-02
    Location
    Tampa, FL
    Posts
    271
    Login to Give a bone
    0

    Red face Re: Edit Attributes Programatically

    woohoo! Thanx everybody I'll see if I cna get one to do what I want (or combination there of) I'll let you know if it works.

  8. #8
    I could stop if I wanted to artisteroi's Avatar
    Join Date
    2007-02
    Location
    Tampa, FL
    Posts
    271
    Login to Give a bone
    0

    Talking Re: Edit Attributes Programatically

    Quote Originally Posted by T.Willey
    So you want to select all blocks within a drawing
    Code:
    (setq ss (ssget '((0 . "INSERT"))))
    Now you have your selection set of blocks, you need to step through them to find the attributes for each one. But you only want to change a certain one, so we need to know the tag name. For now we will use 'TAGNAME'.

    First we need to step through the selection set. We will use the counter way.
    Code:
    (setq cnt 0)
    (while (setq Ent (ssname ss cnt))
    This is saying while 'cnt' (a number) equals and entity ('Ent') within the selection set ('ss') we want something to happen. When then number is larger than the amount in the selection set it will return nil, so the while loop will end.

    So 'Ent' is out block entity, so now we can step though the blocks sub-entities (attributes).

    Code:
    (while
     (and
      (setq Ent (entnext Ent))
      (setq EntData (entget Ent))
      (= (cdr (assoc 0 EntData)) "ATTRIB")
     )
    Here we have to use entnext to get the sub-entity. Once we get one, entnext will go to the next one sub entity. Then we get the dxf code that makes up the entity (see help if you need to understand what this is). Then we want to make sure that the entity is an attribute, that is what 'ATTRIB' stands for.

    Now that we are looking at all the attributes, we want to only change the one we want 'TAGNAME' (dxf code 2 is the tag), so we will use an if statement to test it, and if it is the name we want we will change the text of it (dxf code 1).
    Code:
    (if (= (cdr (assoc 2 EntData)) "TAGNAME")
     (entmod (subst (cons 1 "Updated Text!") (assoc 1 EntData) EntData))
    )
    Hope that makes sense.

    So the whole code will look like
    Code:
    (setq ss (ssget '((0 . "INSERT"))))
    (setq cnt 0)
    (while (setq Ent (ssname ss cnt))
     (while
      (and
       (setq Ent (entnext Ent))
       (setq EntData (entget Ent))
       (= (cdr (assoc 0 EntData)) "ATTRIB")
      )
      (if (= (cdr (assoc 2 EntData)) "TAGNAME")
       (entmod (subst (cons 1 "Updated Text!") (assoc 1 EntData) EntData))
      )
     )
     (setq cnt (1+ cnt)) ; used to get the next item in the selection set
    )

    ok that worked now I need it to pick all the blocks in the drawing and pass the veriable for the new attribute value from a macro linked in the icon. Hope thats not too much.

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

    Default Re: Edit Attributes Programatically

    I think you may have missed SAV2.LSP(above revision).

  10. #10
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Edit Attributes Programatically

    Quote Originally Posted by artisteroi
    ok that worked now I need it to pick all the blocks in the drawing and pass the veriable for the new attribute value from a macro linked in the icon. Hope thats not too much.
    How do you want to supply the tag name? Would you have one button per tag? or would you want one that asks for the tag for you to type in (wouldn't recomend)?

Page 1 of 3 123 LastLast

Similar Threads

  1. Edit 2 attributes in one go
    By nextvkin in forum Dynamic Blocks - Technical
    Replies: 4
    Last Post: 2013-01-24, 11:41 AM
  2. edit block attributes without selecting
    By timothyjturner in forum AutoLISP
    Replies: 26
    Last Post: 2010-01-28, 06:52 PM
  3. Edit block with attributes tip
    By johan d in forum AutoCAD Tips & Tricks
    Replies: 0
    Last Post: 2006-03-30, 02:36 PM
  4. Edit Attributes across multiple Layouts
    By Richard.Spice in forum AutoCAD General
    Replies: 9
    Last Post: 2005-05-07, 09:59 PM
  5. Using properties palette to edit attributes
    By huascarfdez in forum AutoCAD Tips & Tricks
    Replies: 0
    Last Post: 2005-03-09, 11:26 AM

Posting Permissions

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