stepping up attribute values in many blocks?

Discussion in 'AutoCAD' started by The Real JD, Aug 17, 2004.

  1. The Real JD

    The Real JD Guest

    I've got to change the attribute values to quite a few blocks.

    Ie: block attribute 1 has 152.45 for a value and i have to add 1 to that
    value. (153.45)

    Does anyone know of a lisp to do this? I've been searching but haven't had
    any luck yet.

    Any help would be appreciated.

    Thx all!
     
    The Real JD, Aug 17, 2004
    #1
  2. The Real JD

    Jim Claypool Guest

    What's the name of the block and the attribute that needs to be changed?
     
    Jim Claypool, Aug 17, 2004
    #2
  3. The Real JD

    T.Willey Guest

    I don't know of one, but you could do it pretty simple if you don't mind useing single selection method.
    Select the attribute with nentsel
    Get the value of attribute (assoc 1)
    Convert that to a number
    Then add 1
    Convert back to string
    Plug new value back into attribute
    Repeat until enter is hit.

    Hope that helps.
    Tim
     
    T.Willey, Aug 17, 2004
    #3
  4. The Real JD

    The Real JD Guest

    block name "p-elev-t"
    attribute "elev"
     
    The Real JD, Aug 17, 2004
    #4
  5. The Real JD

    Tim Badger Guest

    Jorge, would the value being added/subtracted from the attribute be constant
    with all selected blocks?
     
    Tim Badger, Aug 17, 2004
    #5
  6. The Real JD

    Jim Claypool Guest

    Use (attchg "p-elev-t" "elev")

    (defun attchg (blk att / cnt ss attlist attval)
    (setq ss (ssget "x" (list (cons 2 blk))))
    (if ss
    (progn
    (setq cnt 0)
    (repeat (sslength ss)
    (setq attlist (getatts (ssname ss cnt)))
    (setq attval (1+ (atof (cdr (assoc att attlist)))))
    (setq attlist (subst (cons att attval) (assoc att attlist) attlist))
    (setatts (ssname ss cnt) attlist)
    (setq cnt (1+ cnt))
    );end repeat
    );end progn
    );end if
    (princ)
    )
    (defun GetAtts (Obj)
    (setq obj (vlax-ename->vla-object obj))
    (mapcar
    '(lambda (Att)
    (cons (vla-get-TagString Att) (vla-get-TextString Att))
    )
    (vlax-invoke Obj "GetAttributes")
    )
    );end defun getatts

    (defun SetAtts (Obj Lst / AttVal)
    (setq obj (vlax-ename->vla-object obj))
    (mapcar
    '(lambda (Att)
    (if (setq AttVal (cdr (assoc (vla-get-TagString Att) Lst)))
    (vla-put-TextString Att AttVal)
    )
    )
    (vlax-invoke Obj "GetAttributes")
    )
    (vla-update Obj)
    (princ)
    );end defun setatts
     
    Jim Claypool, Aug 17, 2004
    #6
  7. The Real JD

    The Real JD Guest

    Jim,

    I've tried using it, but I get a

    "error: bad argument type: stringp nil"

    I'm using AutoCAD 2000i if that helps.

    Thanks for the effort.
     
    The Real JD, Aug 17, 2004
    #7
  8. The Real JD

    The Real JD Guest

    Yes it would...
     
    The Real JD, Aug 17, 2004
    #8
  9. The Real JD

    The Real JD Guest

    Thanks Tim,

    My lisp skills are beginner at best. I'll see what i can do...

    1)) 0) (/= (ascii (substr txt3 1 1)) 32))
     
    The Real JD, Aug 17, 2004
    #9
  10. The Real JD

    Jeff Mishler Guest

    Here's one I came up with a while back. It prompts to select the attribute
    to adjust in one of the blocks, as well as for the amount to "bump" by.

    (defun c:bumpelev (/ ent bmpfac blk ss count atts str prec)
    (vl-load-com)
    (if (and
    (setq ent (nentsel "\nSelect attribute in a block to bump the elevation:
    "))
    (= "ATTRIB" (cdr (assoc 0 (setq ent (entget (car ent))))))
    (setq bmpfac (getreal "\nEnter amount to bump: "))
    (setq blk (entget (cdr (assoc 330 ent))))
    (setq ss (ssget (list (cons 2 (cdr (assoc 2 blk)))(cons 0 "INSERT"))))
    )
    (progn
    (vla-startundomark (vla-get-activedocument
    (vlax-get-acad-object)))
    (setq count -1)
    (while (< (setq count (1+ count))(sslength ss))
    (setq blk (vlax-ename->vla-object (ssname ss count))
    atts (vlax-safearray->list
    (vlax-variant-value (vla-getattributes blk))))
    (foreach att atts
    (if (= "ELEV" (vla-get-tagstring att))
    (progn
    (setq str (vla-get-textstring att))
    (setq prec (1- (vl-string-position (ascii ".") str)))
    (setq str (rtos (+ bmpfac (atof str)) 2 prec))
    (vla-put-textstring att str)
    )
    )
    )
    )
    (vla-endundomark (vla-get-activedocument
    (vlax-get-acad-object)))
    )
    )
    (princ)
    )
     
    Jeff Mishler, Aug 17, 2004
    #10
  11. The Real JD

    Jim Claypool Guest

    Try this one.

    (defun attchg (blk att / cnt ss attlist attval)
    (setq att (strcase att)) ;;Added this line to account for a lower case
    entry
    (setq ss (ssget "x" (list (cons 2 blk))))
    (if ss
    (progn
    (setq cnt 0)
    (repeat (sslength ss)
    (setq attlist (getatts (ssname ss cnt)))
    (setq attval (1+ (atof (cdr (assoc att attlist)))))
    (setq attlist (subst (cons att attval) (assoc att attlist) attlist))
    (setatts (ssname ss cnt) attlist)
    (setq cnt (1+ cnt))
    );end repeat
    );end progn
    );end if
    (princ)
    )
     
    Jim Claypool, Aug 17, 2004
    #11
  12. The Real JD

    The Real JD Guest

    It works! Thanks so much! Very cool!


     
    The Real JD, Aug 17, 2004
    #12
  13. The Real JD

    caca Guest

    Hi, can I use this lisp to subtract 97,8 from the values that are already inserted in our attributes.
    And the name of our blocks and attributes are different.
    Is it possible?
    I have tested already and it didn´t work...
    thank you,
    Carol
     
    caca, Aug 18, 2004
    #13
  14. The Real JD

    T.Willey Guest

    Depends on which one you grabbed. If you grabbed Jim's lastest one he posted, at the command prompt type
    (attchg "yourblockname" "yourtagname")
    and it should work.

    Most things posted on this NG you can use.

    Tim
     
    T.Willey, Aug 18, 2004
    #14
  15. The Real JD

    Jim Claypool Guest

    What value is in the attribute? Is it really 2 numbers separated by a comma
    as you indicate?
    If so, what does it represent and what are you trying to accomplish?
     
    Jim Claypool, Aug 18, 2004
    #15
  16. The Real JD

    caca Guest

    Hi,

    The numbers I need to change are from elevation block, el tag. There are many elevation blocks inserted with different values (nn,nn). There is another project that is a complement from a first one we´ve made that is the same specification, only the elevation values that all need to be subtracted by the value of 97.8. That´s why I need the lisp. I have tried to get the Jim Claypool´s lisp but I can´help make it work...can you help me please? I would appreciate it. Thank you
     
    caca, Aug 19, 2004
    #16
  17. The Real JD

    Jim Claypool Guest

    If you send me a sample drawing, I will try to help you.

    many elevation blocks inserted with different values (nn,nn). There is
    another project that is a complement from a first one we´ve made that is the
    same specification, only the elevation values that all need to be subtracted
    by the value of 97.8. That´s why I need the lisp. I have tried to get the
    Jim Claypool´s lisp but I can´help make it work...can you help me please? I
    would appreciate it. Thank you
     
    Jim Claypool, Aug 19, 2004
    #17
  18. The Real JD

    caca Guest

    Hi Jim,

    I am sending one only with our blocks. The "el." valeus need to be subtracted by 97.8.

    Thank you,
    Carol
     
    caca, Aug 19, 2004
    #18
  19. The Real JD

    Jim Claypool Guest

    The el attribute value is 10,0 or 20,0 etc.
    What do you want to subtract the 97.8 from?
     
    Jim Claypool, Aug 19, 2004
    #19
  20. The Real JD

    caca Guest

    Hi Jim,

    Sorry, I didn´t realize that. I was making tests.
    But most of our elevation values are 120,00; 250,00...something like that.

    Sorry Jim and thank you again.
    Carol
     
    caca, Aug 20, 2004
    #20
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.