Results 1 to 9 of 9

Thread: Update field value/format inside of mtext

  1. #1
    Member
    Join Date
    2008-10
    Posts
    4
    Login to Give a bone
    0

    Default Update field value/format inside of mtext

    I update the format of a field inside of an mtext:

    Code:
    (defun c: putfield ()
       (vl-load-com)
       (setq elemname (car (entsel "\nSelect Text, MText, or Attributed Block with Field Expression: ")))
       (princ "\n")
       (setq elemdata (entget elemname))
       (setq tval (cdr (assoc 1 elemdata)))				
    
       (setq dict (vlax-vla-object->ename (vla-GetExtensionDictionary (vlax-ename->vla-object elemname))))
       (setq flst (entget (cdr (assoc 360 (entget (cdr (last (dictnext dict "ACAD_FIELD"))))))))					
       (setq fexp (cdr (assoc 2 flst)))
    
       (princ (strcat "\nField Expression of Text Value \"" tval "\": " fexp "\n"))
       (setq newstr "\\AcObjProp Object(%<\\_ObjIdx 0>%).Area \\f \"%lu2\%ps[, m²]%ct8[0.0001]\"")
       (setq flst (subst (cons 2 newstr) (assoc 2 flst) flst))
       (entmod flst)
       ;; (entupd flst)
       (entupd elemname)
       (vla-update (vlax-ename->vla-object elemname))
       (vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
       ;; (command "regen")
    
       (princ)
    )
    regen or regenall: no change
    But the visible value do not change
    If i open the mtexteditor and edit the field i can see the new format, if i update the field the new format will be applied.
    How can i update the mtext/field?
    Attached Files Attached Files
    Last edited by gerhard.weinhaeusel; 2013-02-25 at 09:33 PM. Reason: [code] tags added

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Update field value/format inside of mtext

    Shouldn't be that hard. Try setting FIELDEVAL to 31 and DEMANDLOAD to 3. Maybe post a small drawing with an mtext that isn't updating so we can see what's going on? Is the lisp to replace the existing field or are you just trying to get it to update?

  3. #3
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Update field value/format inside of mtext

    gerhard.weinhaeusel, please revise your post to include [CODE ] Tags.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  4. #4
    Member
    Join Date
    2008-10
    Posts
    4
    Login to Give a bone
    0

    Default Re: Update field value/format inside of mtext

    I have uploaded the dwg. FIELDEVAL always 31 , demandload 3. I change the format of the field (suffix, multiplier). If I edit the MText and update the field inside of MTexteditor the changes are applied. I want to do the visible update wirh lisp.

  5. #5
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Update field value/format inside of mtext

    What about
    Code:
     (vl-cmdf "updatefield" (car (entsel "\nSelect Text, MText, or Attributed Block with Field Expression: ")) "")

  6. #6
    Member
    Join Date
    2008-10
    Posts
    4
    Login to Give a bone
    0

    Default Re: Update field value/format inside of mtext

    No - no changes in visible text - the only way to update is edit mtext and update field.
    i have also changed the text with "assoc 1 elemdata" with a new text - no visible change - edit mtext and update field: real value visible, newtext removed.

  7. #7
    Member
    Join Date
    2008-10
    Posts
    4
    Login to Give a bone
    0

    Default Re: Update field value/format inside of mtext

    Finally find a solution:
    Code:
    (defun c:putfield ()
       (vl-load-com)
       (setq elemname (car (entsel "\nMText mit Schriftfeld auswählen: ")))
       (setq elemdata (entget elemname))
       (setq tval (cdr (assoc 1 elemdata)))
       (setq dict (vlax-vla-object->ename (vla-GetExtensionDictionary (vlax-ename->vla-object elemname))))
       (setq flst (entget (cdr (assoc 360 (entget (cdr (last (dictnext dict "ACAD_FIELD"))))))))					
       (setq fexp (cdr (assoc 2 flst)))
       (setq newstr "\\AcObjProp Object(%<\\_ObjIdx 0>%).Area \\f \"%lu2\%pr2%ct8[0.0001]\"")
       (setq flst (subst (cons 2 newstr) (assoc 2 flst) flst))
       (entmod flst)
       (setq elemnamevla (vlax-ename->vla-object elemname))
       (vla-put-textstring elemnamevla (vla-fieldcode elemnamevla))
       (princ)
    )
    Last edited by Opie; 2013-02-27 at 03:15 PM. Reason: [code] tags added ~Opie

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Update field value/format inside of mtext

    gerhard.weinhaeusel, please re-read post#3.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  9. #9
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Update field value/format inside of mtext

    Nice code accessing the field with dictionary, but much easier to follow if it had the code tags.
    Thanks,

Similar Threads

  1. white spaces and crlf inside a mtext field
    By adam.kalajzich in forum AutoCAD Fields
    Replies: 5
    Last Post: 2009-08-28, 11:21 AM
  2. Field Format Settings
    By mraafateg in forum ACA General
    Replies: 13
    Last Post: 2007-09-12, 01:52 PM
  3. Replies: 4
    Last Post: 2007-04-10, 05:43 PM
  4. Different Layers inside MTEXT
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2006-06-30, 01:33 PM
  5. Replies: 3
    Last Post: 2006-04-10, 11:11 AM

Tags for this Thread

Posting Permissions

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