Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

stepping up attribute values in many blocks?

33 REPLIES 33
Reply
Message 1 of 34
Anonymous
260 Views, 33 Replies

stepping up attribute values in many blocks?

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!
33 REPLIES 33
Message 2 of 34
Anonymous
in reply to: Anonymous

What's the name of the block and the attribute that needs to be changed? "The Real JD" wrote in message news:41225673$1_3@newsprd01... > 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! > >
Message 3 of 34
Anonymous
in reply to: Anonymous

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
Message 4 of 34
Anonymous
in reply to: Anonymous

I found one that I did for text. Maybe you can use it as a model.

Tim

(defun c:AddText (/ txt1 txt2 cnt1 ent1 pec1 ss)

(command "_.undo" "_end")
(command "_.undo" "_group")
(vl-load-com)
(setq txt1 (getreal "\nEnter value to increase by (if decreasing, add a minus sign before). "))
(setq cnt1 0)
(if txt1
(progn
(if (not *pec1)
(setq *pec1 3)
)
(setq pec1 (getreal (strcat "\nHow many decimal places [" (itoa *pec1) "]? ")))
(if pec1
(setq *pec1 (fix pec1))
)
(setq ss (ssget '((0 . "TEXT"))))
(while (/= cnt1 (sslength ss))
(setq ent1 (MakeX (ssname ss cnt1)))
(setq txt2 (GetX ent1 'TextString))
(MakeSureNum txt2 ent1)
(setq cnt1 (1+ cnt1))
)
)
)
(prompt "\n May get rounding-off if new decimal is less then existing decimal places!!")
(command "_.undo" "_end")
(princ)
)

;==============

(defun MakeSureNum (txt3 ent1 / cnt1 cnt2 txt4 txt5 txt6 txt7)

(setq cnt1 0
cnt2 1
)
(if (and (>= (ascii (substr txt3 1 1)) 65) (/= (ascii (substr txt3 1 1)) 32))
(while (>= (ascii (substr txt3 1 1)) 65)
(if txt4
(setq txt4 (strcat txt4 (substr txt3 1 1)))
(setq txt4 (substr txt3 1 1))
)
(setq txt3 (substr txt3 2 (strlen txt3)))
)
)
(while (= (substr txt3 1 1) " ")
(setq txt4 (strcat txt4 " "))
(setq txt3 (substr txt3 2 (strlen txt3)))
)
(if (< (ascii (substr txt3 1 1)) 65)
(while (and (<= (ascii (substr txt3 1 1)) 65) (/= (ascii (substr txt3 1 1)) 0) (/= (ascii (substr txt3 1 1)) 32))
(if txt5
(setq txt5 (strcat txt5 (substr txt3 1 1)))
(setq txt5 (substr txt3 1 1))
)
(setq txt3 (substr txt3 2 (strlen txt3)))
)
)
(setq txt5 (atof txt5))
(setq txt6 (+ txt5 txt1))
(setq txt7
(if txt4
(strcat txt4 (rtos txt6 2 *pec1) txt3)
(strcat (rtos txt6 2 *pec1) txt3)
)
)
(PutX ent1 'Textstring txt7)

)
Message 5 of 34
Anonymous
in reply to: Anonymous

block name "p-elev-t" attribute "elev" > What's the name of the block and the attribute that needs to be changed? >
Message 6 of 34
Anonymous
in reply to: Anonymous

Jorge, would the value being added/subtracted from the attribute be constant with all selected blocks? "The Real JD" wrote in message news:41225673$1_3@newsprd01... > 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! > >
Message 7 of 34
Anonymous
in reply to: Anonymous

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 "The Real JD" wrote in message news:41225aed$1_2@newsprd01... > block name "p-elev-t" > attribute "elev" > > > > What's the name of the block and the attribute that needs to be changed? > > > >
Message 8 of 34
Anonymous
in reply to: Anonymous

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. "Jim Claypool" wrote in message news:41225e1e$1_2@newsprd01... > 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 > > > "The Real JD" wrote in message > news:41225aed$1_2@newsprd01... > > block name "p-elev-t" > > attribute "elev" > > > > > > > What's the name of the block and the attribute that needs to be changed? > > > > > > > > >
Message 9 of 34
Anonymous
in reply to: Anonymous

Yes it would... > Jorge, would the value being added/subtracted from the attribute be constant > with all selected blocks? >
Message 10 of 34
Anonymous
in reply to: Anonymous

Thanks Tim, My lisp skills are beginner at best. I'll see what i can do... "T.Willey" wrote in message news:7453823.1092770147531.JavaMail.jive@jiveforum2.autodesk.com... > I found one that I did for text. Maybe you can use it as a model. > > Tim > > (defun c:AddText (/ txt1 txt2 cnt1 ent1 pec1 ss) > > (command "_.undo" "_end") > (command "_.undo" "_group") > (vl-load-com) > (setq txt1 (getreal "\nEnter value to increase by (if decreasing, add a minus sign before). ")) > (setq cnt1 0) > (if txt1 > (progn > (if (not *pec1) > (setq *pec1 3) > ) > (setq pec1 (getreal (strcat "\nHow many decimal places [" (itoa *pec1) "]? "))) > (if pec1 > (setq *pec1 (fix pec1)) > ) > (setq ss (ssget '((0 . "TEXT")))) > (while (/= cnt1 (sslength ss)) > (setq ent1 (MakeX (ssname ss cnt1))) > (setq txt2 (GetX ent1 'TextString)) > (MakeSureNum txt2 ent1) > (setq cnt1 (1+ cnt1)) > ) > ) > ) > (prompt "\n May get rounding-off if new decimal is less then existing decimal places!!") > (command "_.undo" "_end") > (princ) > ) > > ;============== > > (defun MakeSureNum (txt3 ent1 / cnt1 cnt2 txt4 txt5 txt6 txt7) > > (setq cnt1 0 > cnt2 1 > ) > (if (and (>= (ascii (substr txt3 1 1)) 65) (/= (ascii (substr txt3 1 1)) 32)) > (while (>= (ascii (substr txt3 1 1)) 65) > (if txt4 > (setq txt4 (strcat txt4 (substr txt3 1 1))) > (setq txt4 (substr txt3 1 1)) > ) > (setq txt3 (substr txt3 2 (strlen txt3))) > ) > ) > (while (= (substr txt3 1 1) " ") > (setq txt4 (strcat txt4 " ")) > (setq txt3 (substr txt3 2 (strlen txt3))) > ) > (if (< (ascii (substr txt3 1 1)) 65) > (while (and (<= (ascii (substr txt3 1 1)) 65) (/= (ascii (substr txt3 1 1)) 0) (/= (ascii (substr txt3 1 1)) 32)) > (if txt5 > (setq txt5 (strcat txt5 (substr txt3 1 1))) > (setq txt5 (substr txt3 1 1)) > ) > (setq txt3 (substr txt3 2 (strlen txt3))) > ) > ) > (setq txt5 (atof txt5)) > (setq txt6 (+ txt5 txt1)) > (setq txt7 > (if txt4 > (strcat txt4 (rtos txt6 2 *pec1) txt3) > (strcat (rtos txt6 2 *pec1) txt3) > ) > ) > (PutX ent1 'Textstring txt7) > > )
Message 11 of 34
Anonymous
in reply to: Anonymous

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 check out www.cadvault.com "The Real JD" wrote in message news:41225673$1_3@newsprd01... > 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! > >
Message 12 of 34
Anonymous
in reply to: Anonymous

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) ) "The Real JD" wrote in message news:41226809_3@newsprd01... > 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. > > "Jim Claypool" wrote in message > news:41225e1e$1_2@newsprd01... > > 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 > > > > > > "The Real JD" wrote in message > > news:41225aed$1_2@newsprd01... > > > block name "p-elev-t" > > > attribute "elev" > > > > > > > > > > What's the name of the block and the attribute that needs to be > changed? > > > > > > > > > > > > > > > >
Message 13 of 34
Anonymous
in reply to: Anonymous

Sorry JD, I forgot to add these subfunctions.

(defun MakeX (entname)
(vlax-ename->vla-object entname)
)

(defun GetX (object prop)
(if (vlax-property-available-p object prop)
(vlax-get object prop)
)
)

(defun PutX (object prop val)
(if (vlax-property-available-p object prop T)
(vlax-put object prop val)
)
)

Tim
Message 14 of 34
Anonymous
in reply to: Anonymous

It works! Thanks so much! Very cool! "Jim Claypool" wrote in message news:41226b88$1_3@newsprd01... > 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) > ) > > > "The Real JD" wrote in message > news:41226809_3@newsprd01... > > 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. > > > > "Jim Claypool" wrote in message > > news:41225e1e$1_2@newsprd01... > > > 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 > > > > > > > > > "The Real JD" wrote in message > > > news:41225aed$1_2@newsprd01... > > > > block name "p-elev-t" > > > > attribute "elev" > > > > > > > > > > > > > What's the name of the block and the attribute that needs to be > > changed? > > > > > > > > > > > > > > > > > > > > > > > > >
Message 15 of 34
Anonymous
in reply to: Anonymous

Jorge, I have attached a little lisp routine that should do what you are looking for. Best is to open it up and get a brief explanation on how to use it. Please keep in mind that it was done while I was having my coffee so it has little error checking... but it will give you the ability to Add or Subtract a value to an attribute value. It will also allow you to simply change attribute values. To use, basically pick one of the attributes on a block. Hope it helps, and if it buggers up let me know. TimB "The Real JD" wrote in message news:41226838_1@newsprd01... > Yes it would... > > > > Jorge, would the value being added/subtracted from the attribute be > constant > > with all selected blocks? > > > > Attachment not added (content type not allowed): "UPDATT.LSP"
Message 16 of 34
Anonymous
in reply to: Anonymous

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
Message 17 of 34
Anonymous
in reply to: Anonymous

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
Message 18 of 34
Anonymous
in reply to: Anonymous

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? "caca" wrote in message news:31357733.1092848801751.JavaMail.jive@jiveforum2.autodesk.com... > 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
Message 19 of 34
Anonymous
in reply to: Anonymous

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
Message 20 of 34
Anonymous
in reply to: Anonymous

If you send me a sample drawing, I will try to help you. "caca" wrote in message news:32881432.1092944212127.JavaMail.jive@jiveforum2.autodesk.com... > 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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost