label attibute up by 1

Discussion in 'AutoCAD' started by horgan, Jun 24, 2004.

  1. horgan

    horgan Guest

    In 2004, I have multiple blocks that have an attribute titled "label". After inserting many of these blocks, I need to go back and select a certain group of them and have a program ask for a letter title, such as "A" and a number to begin at, say "001". From that point, whichever blocks have been selected, all would be "A" and increment up by one from the starting number. So of the 50 blocks that are inserted, I will select 10 of them either by single selection or multiple windows, answer the questions of which letter identifier and the starting number and all 10 blocks would be labeled, A001 through A010.

    Thanks for your review.
     
    horgan, Jun 24, 2004
    #1
  2. horgan

    ECCAD Guest

    Try this:
    ;; Grab blocks, look for tag 'label', replace value(s) with Letter + number
    ;;
    ;; Define DXF function
    ;;
    (defun dxf (code elist)
    (cdr (assoc code elist))
    ); end function dxf
    ;;
    ;; Function to replace value in Attribute
    ;; .. ent = entity
    ;; (setq ename (ssname ss index))
    ;; (setq ent (entget ename))
    ;; .. att = attribute sub-entity
    ;; (setq att (entget (entnext (dxf -1 ent)))); sub-entity
    ;; .. nstr = new string value
    ;; (setq nstr "NEW VALUE")
    ;;
    (defun rep_att_value ( ename ent att nstr )
    (entmod (setq att (subst (cons 1 nstr)(assoc 1 att) att)))
    (entupd ename)
    (princ)
    ); end function rep_att_value
    ;;
    ;; Get a block, check it's attributes
    ;;
    (defun C:IA (); Increment Attribute
    (Prompt "\nPick Blocks with Attr. to Change and Sequence {use Window}:")
    (setq A (ssget)); get selection set
    (if (/= A nil); Else if A is nil, do nothing.
    (setq B (sslength A)); check number of members in 'A' selection set.
    (setq B 0); --- else, set length to zip.
    ); end if
    ;;
    ;; A = selection set of entities
    ;; B = sslength of A
    ;; C = Counter for number of entities found
    ;;
    (if (> B 0); -- Must be something to look at in selection set..
    (progn
    (setq Letter (getstring "\nLetter to apply:")); get the Letter
    (setq num (getint "\nStart with Number ? :")); get the Number
    (setq C 0 E 1); C = entity selecter, starts at 0, goes 1,2,3..
    (repeat B
    (setq ename (ssname A C)); get entity name from 'A', if no name, ename is nil.
    (if (/= ename nil); found something ?
    (progn
    (setq ent (entget ename)); chk used to hold each entity 'list' item.
    (if (and
    (= "INSERT" (cdr (assoc 0 ent))) ; case of BLOCKS
    (/= (cdr (assoc 66 ent)) nil); with Attrib's following
    ); end and
    (progn
    (setq av nil CX 1); init inside loop
    (while (> CX 0)
    (setq att (entget (entnext (dxf -1 ent)))); sub-entity
    (setq BN (cdr (assoc 0 att))); name of item
    (setq ent att); swap to next Attrib
    (if (or (= "INSERT" BN)(= "SEQEND" BN))
    (setq CX 0)
    ); end if
    ;; - if not at end of Attributes, keep going
    (if (= "ATTRIB" BN)
    (progn
    (setq tag (strcase (cdr (assoc 2 att)))); get the tag name
    (setq av (cdr (assoc 1 att))); get the attrib value
    (if av
    (progn
    (if (= tag "LABEL")
    (progn
    (setq nx (itoa num))
    (if (= (strlen nx) 1)(setq nx (strcat "00" nx)))
    (if (= (strlen nx) 2)(setq nx (strcat "0" nx)))
    (setq nstr (strcat Letter nx)); make new string
    (rep_att_value ename ent att nstr)
    (setq num (+ num 1))
    ); end progn
    ); end if
    ); end progn
    ); end if
    ); end progn
    ); end if
    ); end while CX > 0
    ); end progn
    ); end if INSERT
    ); end progn
    ); end if ename /= nil
    (setq C (+ C 1)); ratchet counter C to get next entity.
    (setq ename nil av nil); reset ename - for IF above.
    ); end repeat B
    ); end progn
    ); end if B > 0
    (princ)
    ); end function
    (C:IA)

    Bob
     
    ECCAD, Jun 24, 2004
    #2
  3. horgan

    horgan Guest

    Bob,

    This works great. I appreciate this a lot.

    Thanks so much.
     
    horgan, Jun 24, 2004
    #3
  4. horgan

    ECCAD Guest

    You are welcome.
    I know that this one will increment the numbers, but in order of 'block' inserts. In other words, may look random on the drawing. If you need to pick the block(s) in some order, a slight modification can do that also..

    Bob
     
    ECCAD, Jun 24, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.