RickyD302 Posted August 31, 2009 Posted August 31, 2009 Has anybody have experience with these objects and vba? What I've done is use a formula in a attribute value where I can select and link to an object (polyline area) then multiple it by 8". This gives me a volume then take that value and multiply it by 4050 (weight of cubic yard). This gives me weight of the object. I've done this thru out my drawing with different objects. What I'm needing is to change the 4050 to 3240 (they changed it to lw concrete). I've messed around with vba and attribute values but not using fields. Looking for a little heads up before I start digging into it. Quote
JohnM Posted August 31, 2009 Posted August 31, 2009 sounds simple, just open the project and search for 4050 then replace it with the new number. Quote
RickyD302 Posted September 3, 2009 Author Posted September 3, 2009 Autocad FIND command does not look at field formulas...just simple text. We tried using find with no luck. Quote
gile Posted September 3, 2009 Posted September 3, 2009 Hi, AFAIK, the FieldCode method don't work with attribute references (only with texts and mtexts). Another way to find the field code of a (m)text or an atribute is to search in the object extension dictionary for a "ACAD_FIELD" entry which is another dictionary in which you have to look for a "TEXT" entry which is the "FIELD" object. But I was not able to go further using the COM/Activex automation (used both by VBA and Visual LISP). So, all I can give you now is a LISP routine which deals with DXF datas, maybe you can inspire to write some VBA code... The routine uses a recursive process because in fields using formulas, an object linked field can be nested into another object nlinked field, and so on... ;; gc:FieldCode (gile) ;; Returns an attribute text or mtext string with the field code ;; ;; Argument : object entity name (ENAME) (defun gc:FieldCode (ent / foo elst xdict dict field str) ;;--------------------------------------------------------;; (defun foo (field str / pos fldID objID) (setq pos 0) (if (setq pos (vl-string-search "\\_FldIdx " str pos)) (while (setq pos (vl-string-search "\\_FldIdx " str pos)) (setq fldId (entget (cdr (assoc 360 field))) field (vl-remove (assoc 360 field) field) str (strcat (substr str 1 pos) (if (setq objID (cdr (assoc 331 fldId))) (vl-string-subst (strcat "ObjId " (itoa (gc:EnameToObjectId objID))) "ObjIdx" (cdr (assoc 2 fldId)) ) (foo fldId (cdr (assoc 2 fldId))) ) (substr str (1+ (vl-string-search ">%" str pos))) ) ) ) str ) ) ;;--------------------------------------------------------;; (setq elst (entget ent)) (if (and (member (cdr (assoc 0 elst)) '("ATTRIB" "MTEXT" "TEXT")) (setq xdict (cdr (assoc 360 elst))) (setq dict (dictsearch xdict "ACAD_FIELD")) (setq field (dictsearch (cdr (assoc -1 dict)) "TEXT")) ) (setq str (foo field (cdr (assoc 2 field)))) ) ) ;;============================================================;; ;; gc:EnameToObjectId (gile) ;; Converts an ename to an object ID ;; ;; Argument : an ename (defun gc:EnameToObjectId (ename) ((lambda (str) (hex2dec (substr (vl-string-right-trim ">" str) (+ 3 (vl-string-search ":" str))) ) ) (vl-princ-to-string ename) ) ) ;;============================================================;; ;; hex2dec (gile) ;; convert an hexadécimal (string) into a décimal (integer) ;; ;; Argument : un hexadédimal (chaîne) (defun hex2dec (s / r l n) (setq r 0 l (vl-string->list (strcase s))) (while (setq n (car l)) (setq l (cdr l) r (+ (* r 16) (- n (if (<= n 57) 48 55))) ) ) ) ;;============================================================;; ;; lst2str (gile) ;; Concatenates a list and a separator into a string ;; ;; Arguments ;; lst : list ;; sep : separator (defun lst2str (lst sep) (if (cdr lst) (strcat (vl-princ-to-string (car lst)) sep (lst2str (cdr lst) sep) ) (vl-princ-to-string (car lst)) ) ) 1 Quote
Recommended Posts
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.