See the top rated post in this thread. Click here

Page 1 of 3 123 LastLast
Results 1 to 10 of 29

Thread: Convert Field to Text within Block Globally

  1. #1
    Active Member
    Join Date
    2007-08
    Posts
    81
    Login to Give a bone
    0

    Default Convert Field to Text within Block Globally

    I have an old block with FIELDs referencing a lookup value. My new block is just the attribute input...didn't like the FIELD look up. Is there a way to replace the old FIELD block with the new block, where the field value will carry over to the new block? The attributes are named the same, I just removed the field and lookup.

    * - I have tried BLOCKREPLACE, but it won't replace block for some reason.
    * - I tried the old fashion method of inserting the new block & running attsync, but field remains and upon regen or ATTSYNC "####" comes up since look up is missing.
    * - I found a Lisp routine, REPL.LSP, that replaced the block, but left the field and regen/attsync issue remains as mentioned above.
    * - Did find a program online that appears to do what I want, but i don't want to spend $ for it.

    Basically I need a way to globally change field to text within a block. From there I should be able to replace the block. Any suggestions.

  2. #2
    Active Member
    Join Date
    2007-08
    Posts
    81
    Login to Give a bone
    0

    Default Re: Convert Field to Text within Block Globally

    Anyone have a solution?

  3. #3
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    1

    Default Re: Convert Field to Text within Block Globally

    Try this LISP. Save it to a file with a LSP extension & load via Tools --> Load Application. Then type the command FLD2TXT at the command prompt. This will change all the attributes in the block to only text values - thus removing any fields.

    ;; Start copy here
    Code:
    (vl-load-com)
    (defun c:FLD2TXT (/ ss n bn an ad s)
      (prompt
        "Select the blocks you wish to remove the field links from: "
      ) ;_ end of prompt
      (setq ss (ssget '((0 . "INSERT"))))	;Get selection set from user
      (setq n 0)				;Initialize counter
      ;; Step through selection set one entity at a time
      (while (< n (sslength ss))
        (setq bn (ssname ss n))		;Get the nth entity in the selection set
        (setq an (entnext bn))		;Get the next enity after bn
        ;; Step through each next entity until it is not an attribute
        (while (and	an			;Check if entity is found
    		(setq ad (entget an))	;Get data
    		(= "ATTRIB" (cdr (assoc 0 ad))) ;Check if attribute
    	   ) ;_ end of and
          (setq s (cdr (assoc 1 ad)))	;Get text value
          (setq ad (subst (vl-list* 1 "") (assoc 1 ad) ad))
    					;Clear the attribute's value
          (entmod ad)			;Modify the entity
          (setq ad (subst (vl-list* 1 s) (assoc 1 ad) ad))
    					;Set the attribute's value back to only the text
          (entmod ad)			;Modify the entity
          (entupd an)			;Update screen to show change
          (setq an (entnext an))		;Get next entity
        ) ;_ end of while
        (setq n (1+ n))			;Increment counter
      ) ;_ end of while
      (setq ss nil)				;Clear selection set
      (gc)					;Clear unused memory
      (princ)
    ) ;_ end of defun
    ;; End copy here
    Last edited by Opie; 2022-07-22 at 12:02 AM. Reason: [CODE] tags added

  4. #4
    Active Member
    Join Date
    2007-08
    Posts
    81
    Login to Give a bone
    0

    Default Re: Convert Field to Text within Block Globally

    Thank you...worked perfectly. Just don't ATTSYNC again, since this will make the field come back.

  5. #5
    I could stop if I wanted to Hammer.John.J's Avatar
    Join Date
    2015-09
    Location
    Springfield, MA
    Posts
    491
    Login to Give a bone
    0

    Default Re: Convert Field to Text within Block Globally

    Quote Originally Posted by irneb View Post
    Try this LISP. Save it to a file with a LSP extension & load via Tools --> Load Application. Then type the command FLD2TXT at the command prompt. This will change all the attributes in the block to only text values - thus removing any fields.
    Code:
    ;; Start copy here
    
    (vl-load-com)
    (defun c:FLD2TXT (/ ss n bn an ad s)
      (prompt
        "Select the blocks you wish to remove the field links from: "
      ) ;_ end of prompt
      (setq ss (ssget '((0 . "INSERT"))))	;Get selection set from user
      (setq n 0)				;Initialize counter
      ;; Step through selection set one entity at a time
      (while (< n (sslength ss))
        (setq bn (ssname ss n))		;Get the nth entity in the selection set
        (setq an (entnext bn))		;Get the next enity after bn
        ;; Step through each next entity until it is not an attribute
        (while (and	an			;Check if entity is found
    		(setq ad (entget an))	;Get data
    		(= "ATTRIB" (cdr (assoc 0 ad))) ;Check if attribute
    	   ) ;_ end of and
          (setq s (cdr (assoc 1 ad)))	;Get text value
          (setq ad (subst (vl-list* 1 "") (assoc 1 ad) ad))
    					;Clear the attribute's value
          (entmod ad)			;Modify the entity
          (setq ad (subst (vl-list* 1 s) (assoc 1 ad) ad))
    					;Set the attribute's value back to only the text
          (entmod ad)			;Modify the entity
          (entupd an)			;Update screen to show change
          (setq an (entnext an))		;Get next entity
        ) ;_ end of while
        (setq n (1+ n))			;Increment counter
      ) ;_ end of while
      (setq ss nil)				;Clear selection set
      (gc)					;Clear unused memory
      (princ)
    ) ;_ end of defun
    ;; End copy here
    i need to do this for dimensions and mtext

  6. #6
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Convert Field to Text within Block Globally

    Try this:
    Code:
    (vl-load-com)
    (defun c:FLD2TXT (/ ss n bn an ad s)
      (prompt
        "Select the blocks you wish to remove the field links from: "
      ) ;_ end of prompt
      (setq ss (ssget '((0 . "INSERT,MTEXT,DIMENSION,TEXT"))))    ;Get selection set from user
      (setq n 0)                ;Initialize counter
      ;; Step through selection set one entity at a time
      (while (< n (sslength ss))
        (setq bn (ssname ss n))        ;Get the nth entity in the selection set
        (setq ad (entget bn))               ;Get the entity's data
        (cond
           ((= "INSERT" (cdr (assoc 0 ad))) ;Check if block
            (setq an (entnext bn))        ;Get the next enity after bn
            ;; Step through each next entity until it is not an attribute
            (while (and    an            ;Check if entity is found
                (setq ad (entget an))    ;Get data
                (= "ATTRIB" (cdr (assoc 0 ad))) ;Check if attribute
               ) ;_ end of and
              (setq s (cdr (assoc 1 ad)))    ;Get text value
              (setq ad (subst (vl-list* 1 "") (assoc 1 ad) ad))
                            ;Clear the attribute's value
              (entmod ad)            ;Modify the entity
              (setq ad (subst (vl-list* 1 s) (assoc 1 ad) ad))
                            ;Set the attribute's value back to only the text
              (entmod ad)            ;Modify the entity
              (entupd an)            ;Update screen to show change
              (setq an (entnext an))        ;Get next entity
            ) ;_ end of while
          )
          (t
            (setq s (cdr (assoc 1 ad)))    ;Get text value
            (setq ad (subst (vl-list* 1 "") (assoc 1 ad) ad))
            (entmod ad)            ;Modify the entity
            (setq ad (subst (vl-list* 1 s) (assoc 1 ad) ad))
             (entmod ad)            ;Modify the entity
            (entupd an)            ;Update screen to show change
           )
        )
        (setq n (1+ n))            ;Increment counter
      ) ;_ end of while
      (setq ss nil)                ;Clear selection set
      (gc)                    ;Clear unused memory
      (princ)
    ) ;_ end of defun

  7. #7
    Member
    Join Date
    2010-02
    Posts
    6
    Login to Give a bone
    0

    Default Re: Convert Field to Text within Block Globally

    I was able to get it to work but now after an AutoCAD restart I get

    error: bad argument type: lentityp nil

    Autocad 20111 64 bit, windows 7 pro

    Also will this convert mleader fields to text?

  8. #8
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Convert Field to Text within Block Globally

    Not yet, no. But also I'd avoid using this thing on annotative text. It needs a bit of rewriting to not screw up anno text's height. I'll get back with a fixed version ASAP.

  9. #9
    Member
    Join Date
    2010-02
    Posts
    6
    Login to Give a bone
    0

    Default Re: Convert Field to Text within Block Globally

    That would be great.....I use it all annotative, multileaders and fields but I found not everyone does nor do they understand it so....I want to take the drawings and "dumb" them down My plan is do this on a copy and keep the intelligent drawing for me

  10. #10
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Convert Field to Text within Block Globally

    Here goes:
    Code:
    (vl-load-com)
    (defun c:FLD2TXT (/ ss n bn an ad s)
      (prompt
        "Select the objects you wish to remove the field links from: "
      ) ;_ end of prompt
      (setq ss (ssget '((0 . "INSERT,MTEXT,DIMENSION,TEXT,MULTILEADER")))) ;Get selection set from user
      (setq n 0) ;Initialize counter
      ;; Step through selection set one entity at a time
      (while (< n (sslength ss))
        (setq bn (ssname ss n)) ;Get the nth entity in the selection set
        (setq ad (entget bn)) ;Get the entity's data
        (cond
          ((= "INSERT" (cdr (assoc 0 ad))) ;Check if block
           (setq an (entnext bn)) ;Get the next enity after bn
           ;; Step through each next entity until it is not an attribute
           (while (and an ;Check if entity is found
                       (setq ad (entget an)) ;Get data
                       (= "ATTRIB" (cdr (assoc 0 ad))) ;Check if attribute
                  ) ;_ end of and
             (setq s (cdr (assoc 1 ad))) ;Get text value
             (entmod (list (assoc -1 ad) (cons 1 ""))) ;Modify the entity
             (entmod (list (assoc -1 ad) (cons 1 s))) ;Modify the entity
             (entupd an) ;Update screen to show change
             (setq an (entnext an)) ;Get next entity
           ) ;_ end of while
          )
          ((= "MULTILEADER" (cdr (assoc 0 ad))) ;Check if block
           (setq ad (vlax-ename->vla-object bn)
                 s (vla-get-TextString ad)
                 )
           (vla-put-TextString ad "")
           (vla-put-TextString ad s)
          )
          ;; Anything else
          (t
           (setq s (cdr (assoc 1 ad))) ;Get text value
           (entmod (list (assoc -1 ad) (cons 1 ""))) ;Modify the entity
           (entmod (list (assoc -1 ad) (cons 1 s))) ;Modify the entity
           (entupd an) ;Update screen to show change
          )
        )
        (setq n (1+ n)) ;Increment counter
      ) ;_ end of while
      (setq ss nil) ;Clear selection set
      (gc) ;Clear unused memory
      (princ)
    ) ;_ end of defun
    It should now also work for Multileaders and Annotative Text.

Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 2015-06-26, 04:55 PM
  2. WANT TO CHANGE TEXT STYLE WITHIN A BLOCK- GLOBALLY
    By jeff.garr in forum Dynamic Blocks - Technical
    Replies: 21
    Last Post: 2014-11-20, 12:26 PM
  3. 2014: Auto Cad -2014 LT Attribute field value covert to Text globally
    By umesh.yadav419124 in forum AutoCAD Customization
    Replies: 0
    Last Post: 2013-09-14, 11:47 PM
  4. Block Attribute / Field (text) that wraps
    By bweir in forum AutoCAD Tips & Tricks
    Replies: 6
    Last Post: 2007-11-12, 10:28 PM
  5. Globally convert text to mtext
    By Stephen.Walz in forum AutoLISP
    Replies: 11
    Last Post: 2006-12-08, 08:45 PM

Posting Permissions

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