Jump to content

Numerical Global Block Attribute


kristin

Recommended Posts

I have a question for all you experienced AutoCAD guru's...

 

I have a drawing with numerous spot elevations. The spots are listed via a block inserted where I label the block with two attributes (top of curb elevation and bottom of curb elevation) Sometimes a client will want the whole site to be dropped or lowered by a certain increment. How or can I edit ALL spot elevation blocks to be increased or decreased by a specific numerical amount? I have been told this is not possible, but I am really hopeful that I can find a better solution then opening each block attribute and manually editing the values by a lowly 1.5 feet! (Of course that way I also hit the roadblock of trying to discern which blocks have been upped the 1.5' and which have not!) I have tried changing the block color as i change each one, but then I cannot find a way of changing all back to the bylayer color. attedit has not worked in the past for this fdor some reason. Any tips or tricks would be greatly appreciated.

 

~Kristin

Link to comment
Share on other sites

I know I can do this using VBA and I am certain it can be done using LISP. However I am at home now so away from AutoCAD and I don't have the time to do it at work at the moment.

 

Assuming all your blocks have the same name (and all need changing by the same amount) you can get them all into a selection set, retrieve the value, do your sums and write the new value back.

 

This really needs to be in the LISP/VBA area but I am sure a mod will move it soon.

Link to comment
Share on other sites

OK, I was expecting one of the LISP people to come to my rescue but, oh well.

 

Just to prove something can be done I have created a block comprising a rectangle with a single attribute in it. The following code will add 28 to that attribute. (Note very exciting but never mind)

 

(defun c:bl()
(setq F1 (entsel))
(setq F2 (entget(entnext(car F1))))
(setq V1 (assoc 1 F2))
(setq V2 (+ 28 (atof (cdr V1))))
(setq V3 (cons 1 (rtos V2)))
(setq F2 (subst V3 V1 F2))
(entmod F2)
(princ)
)

 

load the code, type BL and select the block and see what happens. Note - there are no error checks so don't try it on a valuable drawing!

Link to comment
Share on other sites

You can try this, be careful it will edit all attributes in a dwg and will display 2 decimal points (the code can be edited to change that)

;Adds a numerical value to attributes (caution: edits ALL attributes in drawing)

(defun AddNumAtt (add tag / e ei et txt)
`
(setq e (entnext)
tag (strcase tag))
(while (setq e (entnext e))
(setq ei (entget e)
et (cdr (assoc 0 ei)))
(and (= "ATTRIB" et)
(wcmatch (cdr (assoc 2 ei)) tag)
(setq txt (cdr (assoc 1 ei)))
(numberp (setq num (read txt)))
(entmod
(subst (cons 1 (rtos (+ add num) 2 2)) (assoc 1 ei) ei))
(entupd e)))
(princ))
(alert "This will edit all attributes in the drawing!!!")
(setq addreal (getreal "Enter amount to add: "))
(AddNumAtt addreal "*")
;(AddNumAtt 1.00 "*")

I can't take credit, most of it by SOE.

Link to comment
Share on other sites

Thanks for the help. I took a brief and basic AutoCAD course back in 98 in college but have not touched the program until I began working this year (been following my military hubby around europe for 6 yrs) and found that the minimal stuff I learned in college has evaporated! Couple that with all the improvements since... what... R14? What a CAD mess I am... :cry: Thanks again for helping.

 

~Kristin

 

(Hey, lpseifert... looks like we are in the same area!)

Link to comment
Share on other sites

It will work if your attributes contains numbers only.

 

(defun c:addn(/ aLst bLst bSet cAtt cDel cNum fLst nAtt)
 (vl-load-com)
 (if
   (and
     (setq cAtt(nentsel "\nPick attribute > "))
     (= "ATTRIB"(cdr(assoc 0(entget(setq cAtt(car cAtt))))))
     ); end and
   (progn
     (setq cAtt(vlax-ename->vla-object cAtt)
    fLst(vl-remove-if-not '
	  (lambda(x)(member x '(0 2)))
	    (entget(vlax-vla-object->ename
	      (vla-ObjectIDtoObject
		(vla-get-ActiveDocument
		  (vlax-get-acad-object))
	            (vla-get-OwnerID cAtt)))))
    nAtt(vla-get-TagString cAtt)
    ); end setq
     (princ "\n<<< Select blocks >>>")
      (if(setq bSet(ssget fLst))
 (progn
   (setq bLst(mapcar 'vlax-ename->vla-object
		(vl-remove-if 'listp
                         (mapcar 'cadr(ssnamex bSet))))
	 cDel(getreal "\nSpecify number to Add/Subtract: ")
	 ); end setq
   (foreach b bLst
     (setq aLst(vlax-safearray->list
		  (vlax-variant-value
		    (vla-getAttributes b))))
     (foreach at aLst
       (if(= nAtt(setq cAtt(vla-get-TagString at)))
	 (if(setq cNum(atof(vla-get-TextString at)))
	   (vla-put-TextString at(rtos(+ cNum cDel)2 1))
	   ); end if
	 ); end if
       ); end foreach
     ); end foreach
   ); end progn
 ); end if
     ); end progn
   ); end if
 (princ)
 ); end of c:addn

Link to comment
Share on other sites

  • 3 years later...

Hello,

 

Thanks you very much for the lisp. I have a question, if we run the script it changes "+7.00" to "8" it does not keep the "+" sign or the decimal digits.

 

Is there a way to solve this? we have about 15.000 attributes with elevations like (-07.22) and we have to subtract 7 from these. :sick:

 

 

Thanks again for your help.

Link to comment
Share on other sites

Hi Cestel, welcome to the forum.

 

What Lisp are you referring to? There are three in this thread.

 

Incidently, this thread is about 3 years old, and if its ASMIs Lisp you are referring too, he's not very active here anymore so if you don't get a respons, consider starting a new thread and pose your question there.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...