blocks containing 12 attributes.
Ask for new value for watts per meter
pick one of the blocks
read LENGTH attribute and multiply by new value
place new value into WATTS attribute of all similer blocks.
So how to cycle through each block twice in order to first pick up LENGHT then repeat to update WATTS?
I have tried many different methods but none work reliably on multiple blocks its driving me nuts! Please help!
The TAG LENGTH comes after the TAG WATTS which must make it more difficult I guess, or does it? Its going to be a pain if you have to keep re-arranging the order of the TAGS.
;Pick set any tape watts
(defun c:PSWATTS()
(graphscr)
(setq cmd (getvar "cmdecho")
olderr *error*
*error* trap)
(setvar "cmdecho" 0)
(setq twts 7)
(setvar "cmdecho" 0)
(setq ep (entlast))
(prompt"\nSet the Wattage per meter [7]..<")
(princ twts)
(princ ">") ;get new value for watts per meter
(setq ss (ssget "_X" (list (cons 0 "INSERT" )(assoc 2 (entget (car (entsel "\nSelect Fitting: ")))))))
(setq sl (sslength ss)
ct 0
ctr 0)
(princ "\nUpdating all Fittings for new wattage....")
(repeat sl ;step through selection set
(setq e1 (ssname ss ct))
(setq ck 2)
(while (not (equal ck "SEQEND"))
(setq e1 (entnext e1)
e2 (entget e1)
ck (cdr (assoc 0 e2)))
(if (= (cdr (assoc 2 e2)) "LENGTH")
(progn
(setq stlen (cdr (assoc 1 e2))) ;get length of tape polyline stored in fitting attribute TAG called LENGTH then
(setq len (atof stlen)) ;multiply by new wattage per meter
(setq len (/ len 1000))
(setq newwatts (* len twts))
(setq wtstr (rtos newwatts 2 1))
)
)
)
(setq ch 2) ;cycle through selection set again to find TAG WATTS
(while (not (equal ck "SEQEND"))
(setq ck (cdr (assoc 0 e2)))
(if (= (cdr (assoc 2 e2)) "WATTS")
(progn
(setq e2 (subst (cons 1 wtstr)(assoc 1 e2)e2))
(entmod e2)
(entupd e1) ;update TAG WATTS with new value
(setq ctr (+ ctr 1)) ;count number of fittings updated.
)
)
)
(setq ct (+ ct 1))
)
(print ctr)
(princ " Fittings were changed to: ")
(princ twts)
(princ " Watts per meter")
(restore)
)
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Hi rodb,
untested...
;; test for a valid entsel (if (and (setq blk (car (entsel "\nSelect Fitting: "))) ;; test for a valid sssget, make sure the block have attributes (66 . 1) (setq ss (ssget "_X" (list (cons 0 "INSERT") (assoc 2 (entget blk)) '(66 . 1)))) ) (progn (setq sl (sslength ss) ct 0 ctr 0 ) (princ "\nUpdating all Fittings for new wattage....") (repeat sl ;step through selection set (setq e1 (ssname ss ct) wtstr nil wt-ent nil ck 2 ) (while (not (equal ck "SEQEND")) (setq e1 (entnext e1) e2 (entget e1) ck (cdr (assoc 0 e2)) ) (if (= (cdr (assoc 2 e2)) "LENGTH") (progn (setq stlen (cdr (assoc 1 e2))) ;get length of tape polyline stored in fitting attribute TAG called LENGTH then (setq len (atof stlen));multiply by new wattage per meter (setq len (/ len 1000)) (setq newwatts (* len twts)) (setq wtstr (rtos newwatts 2 1)) ) ) ;; if (if (= (cdr (assoc 2 e2)) "WATTS") ;; find TAG WATTS (setq wt-ent e2) ) ;; if ) (if (and wtstr wt-ent) (progn (setq wt-ent (subst (cons 1 wtstr) (assoc 1 wt-ent) wt-ent)) (entmod wt-ent) (entupd e1);update TAG WATTS with new value (setq ctr (+ ctr 1));count number of fittings updated. ) ) (setq ct (+ ct 1)) ) (print ctr) (princ " Fittings were changed to: ") (princ twts) (princ " Watts per meter") (restore) ) )
Henrique
If you just start this drawing, you can use FIELD to fill in Watt attribute with certain factor multiplied with Lengh value in the first block, then copy this block, then change Lengh value of each block, then regen the drawing to update Watt fields.
If you already copied the block in the drawing, and need update attribute of existing blocks, you can try ALTEXT.vlx with "formula" option, use the formula below:
;;; This is an example formula for ALTEXT.vlx ;;; It multiplies "factor" to selected attribute. ;;; It uses current system units and precision for the result. ;;; Change factor, units, and precision to suit your usage. ;;; Change Altext_att_2 to Altext_att_n if the attribute to be updated is No. n attribute in the block. (defun ALTEXT_FORMULA (/ C_lunits C_luprec factor) (setq factor 1.5) (setq C_lunits (getvar "lunits")) (setq C_luprec (getvar "luprec")) (rtos (* (atof Altext_att_2) factor) C_lunits C_luprec)
Could not wait, got up at 5.30am to try it and it works! Wonderful thank you, always coming up with solutions! When I get back from work I'll sit down and work out where I was going wrong.