+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Full Member
    Using
    AutoCAD 2011
    Join Date
    May 2006
    Posts
    27

    Default Formula Fields and Atributes

    Registered forum members do not see this ad.

    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.

  2. #2
    Senior Member
    Computer Details
    JohnM's Computer Details
    Operating System:
    xp pro
    Using
    AutoCAD 2006
    Join Date
    Feb 2009
    Location
    houston, texas
    Posts
    382

    Default

    sounds simple, just open the project and search for 4050 then replace it with the new number.

  3. #3
    Full Member
    Using
    AutoCAD 2011
    Join Date
    May 2006
    Posts
    27

    Default not that simple

    Autocad FIND command does not look at field formulas...just simple text. We tried using find with no luck.

  4. #4
    Senior Member
    Using
    AutoCAD 2007
    Join Date
    Jul 2009
    Location
    Marseille France
    Posts
    178

    Default

    Registered forum members do not see this ad.

    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...

    Code:
    ;; 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))
      )
    )

Similar Threads

  1. automatic numbering of block atributes.. is it possible??
    By ottoatom in forum AutoCAD General
    Replies: 11
    Last Post: 12th Nov 2012, 11:43 pm
  2. VBA Atributes
    By Eklips in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 18th Sep 2009, 08:19 pm
  3. My formula is wrong?
    By JaketheMan in forum Catch All
    Replies: 10
    Last Post: 10th Mar 2009, 05:41 pm
  4. Formula in Attribute
    By Impala62 in forum AutoCAD Beginners' Area
    Replies: 3
    Last Post: 7th Jan 2008, 07:05 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts