Delete Additional Format from Blocks

Delete Additional Format from Blocks

Anonymous
Not applicable
949 Views
8 Replies
Message 1 of 9

Delete Additional Format from Blocks

Anonymous
Not applicable

I have a drawing with hundreds of a dynamic block which contains attributes for Width and Height.  The default value of these attributes in the block itself is blank.  In each instance of the block the value of these attributes is linked to the Width and Height field from that block reference, with an additional format of a " suffix for inches (eg value is 12 1/2 with a " suffix to make it 12 1/2").

 

  My question is how do I go about deleting the suffix from all of these blocks?  Because the attribute values have been entered in each instance of the block and not in the block itself I cannot do it through the block editor.

 

Thanks in advance.

0 Likes
950 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable

post a sample dwg.

0 Likes
Message 3 of 9

Anonymous
Not applicable

Randall - attached is a small sample dwg.

0 Likes
Message 4 of 9

hencoop
Advisor
Advisor

Search and Replace text might work.

I have a function that I use instead that searches and replaces TEXT, DIMENSIONS, MTEXT, ATTRIBS, and ATTDEFS and is a little better for my needs. It is named SRTEXT and can be saved to file here: http://paracadd.com/lisp/lisp_lst.htm#srtext

Follow the links there to save all of the subroutines required.  Save each one to the name of their link.
Notice in the instructions below how to search and replace a double quote (inch mark).

srtext.jpg

The above message can be read in AutoCAD after loading SRTEXT.LSP by issuing the command SRTEXT_HELP

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 5 of 9

Michiel.Valcke
Advisor
Advisor

Do a _DDATTE on your block,

You will get an Edit Attributes window,

The Width, Height and Area values will have a grey background, this denotes that they are calculated values.

Select one of the values (so it's blue) then right click on it. Choose the option "Edit Field"

You will have a new window with a Name, Property, Format, Preview, Object type and Field category bar on top and a field expression below. On the right side of the window you should see a button that is labeled 'Additional Format' >>> click here.

Here you can change the Suffix.

This is however still for a single attribute. I'm trying to rack my brain how I can make it instantly for all similar attributes in the same block.

0 Likes
Message 6 of 9

Anonymous
Not applicable

The suffix is hard-coded n the field so a simple find and replace is going to miss it.  I only have 2015 loaded on this machine so editing the field in BEDIT is off the table, REFEDIT can alter the field data but will kill the dynamic features of the block.  Later versions may be able to handle field driven attributes better so someone using 2017 might be able to help.

 

You might find help at the lisp forum or theSwamp.

0 Likes
Message 7 of 9

hencoop
Advisor
Advisor

I have a function GETFIELD (made with much help here) that will extract the field string but for ATTRIBs Autocad changes the _ObjId value in the string to 0 which kills its usefulness.

E.G. ... (%<\\_ObjId 158367552>%)... becomes ...(%<\\_ObjId 0>%)...

 

I have been unable to find any way to extract the _ObjId value from the Parent block that it refers to.  All I can find is the INSERT (Block instance) ObjectID which is not at all the same.  I have had great success in capturing field strings for inserting them or preserving them in text. mtext, and multileaders. I had hoped to use the same methods to modify these field strings and replace them.  The change needed is near the end:

 

Existing Width field string:
"%<\\AcObjProp.16.2 Object(%<\\_ObjId 158367552>%).Parameter(65).Parameter(65).UpdatedDistance \\f \"%lu5%pr4%ps[,\\\"]\">%")

New Width field string:
"%<\\AcObjProp.16.2 Object(%<\\_ObjId 158367552>%).Parameter(65).Parameter(65).UpdatedDistance \\f \"%lu5%pr4\">%")

 

The characters %ps[,\\ are what specifies the " at the end.  The new value worked just fine as a replacement but I had to copy the original value from the Field Editor's Field expression window to capture the correct _ObjId value.  I also had to replace "\" with "\\" when I copy it this way., When I capture it using lisp it looks like this:
"%<\\AcObjProp.16.2 Object(%<\\_ObjIdx 0>%).Parameter(65).UpdatedDistance \\f \"%lu5%pr4%ps[,\\\"]\">%"

 

If anyone knows how to get the _ObjId (not the ObjectID) from the block that would make this doable.

 

BTW: Once that is done, replacing the field value is pretty easy:

Where edata is the ATTRIB entity definition, this is all that is required:

(setq edata (subst (cons 1 new-width-str)(assoc 1 edata) edata))
(entmod edata)
(entupd (cdr (assoc -1 edata)))

 

FieldString.jpg

 

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 8 of 9

hencoop
Advisor
Advisor

I found how to get the Object ID and I replaced the 0 with it.  Something still breaks the connection with the Insert object (block) so the field data source becomes *Unknown* even though the correct Object ID is there.

Does anyone know how to keep from breaking the field's data source?

; Requires DOSLIB from Robert McNeel & Associates and getfield.lsp
(DEFUN c:reformatfields () (VL-LOAD-COM) (SETQ it (ENTSEL)) (IF (AND it (SETQ ename (CAR it))(=(CDR(ASSOC 0(ENTGET ename)))"INSERT")) (PROGN (SETQ itobj (VLAX-ENAME->VLA-OBJECT ename)) (SETQ blkobjid (ITOA (VLA-GET-OBJECTID itobj))); I do not understand how this two digit integer becomes a 9 (SETQ attag-lst ; digit string by (ITOA ...) but it does! It must be the source. (MAPCAR '(LAMBDA (x) (LIST (VLA-GET-TAGSTRING x) (VLA-GET-OBJECTID x) (vlax-vla-object->ename x))) (VLAX-INVOKE itobj 'getattributes) ) ) (SETQ width-ename (LAST (ASSOC "WIDTH" attag-lst))) (getfield width-ename) (SETQ objidndx (+ 2 (DOS_STRFIND fexp "x")) width-str1 (SUBSTR fexp 1 objidndx) width-str2 blkobjid width-str3 (SUBSTR fexp (+ 2 objidndx)) width-str (STRCAT width-str1 width-str2 width-str3) ) (IF (WCMATCH width-str "*`%ps`[`,\\\"`]*") (PROGN ; Removes inch mark formatting from field strings (SETQ width-str (STRCAT "%<" (DOS_STRREPLACE width-str "%ps[,\\\"]" "") ">%")) (SETQ edata (ENTGET width-ename)) (SETQ edata (SUBST (CONS 1 width-str)(ASSOC 1 edata) edata)) (ENTMOD edata) ) ) (SETQ height-ename (LAST (ASSOC "HEIGHT" attag-lst))) (getfield height-ename) (SETQ objidndx (+ 2 (DOS_STRFIND fexp "x")) height-str1 (SUBSTR fexp 1 objidndx) height-str2 blkobjid height-str3 (SUBSTR fexp (+ 2 objidndx)) height-str (STRCAT height-str1 height-str2 height-str3) ) (IF (WCMATCH height-str "*`%ps`[`,\\\"`]*") (PROGN ; Removes inch mark formatting from field strings (SETQ height-str (STRCAT "%<" (DOS_STRREPLACE height-str "%ps[,\\\"]" "") ">%")) (SETQ edata (ENTGET height-ename)) (SETQ edata (SUBST (CONS 1 height-str)(ASSOC 1 edata) edata)) (ENTMOD edata) ) ) ) ) )

 

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 9 of 9

hencoop
Advisor
Advisor

Hi,

 

I made an error in reconstructing the field string (ObjIdx should have changed to ObjId) and left the original .16.2 in the string which is not there on my system if I select the block and pick the field value.  After fixing those issues the routine reformats your dimensions nicely on my system.

(DEFUN c:reformatfields ()
  (VL-LOAD-COM)
  (SETQ it (ENTSEL))
  (IF (AND it (SETQ ename (CAR it))(=(CDR(ASSOC 0(ENTGET ename)))"INSERT"))
    (PROGN
      (SETQ itobj (VLAX-ENAME->VLA-OBJECT ename))
      (SETQ blkobjid (ITOA (VLA-GET-OBJECTID itobj))); I do not understand how this two digit integer becomes a 9
      (SETQ attag-lst                                ; digit string by (ITOA ...) but it does!  It must be the source.
        (MAPCAR '(LAMBDA (x) (LIST (VLA-GET-TAGSTRING x) (VLA-GET-OBJECTID x) (vlax-vla-object->ename x)))
          (VLAX-INVOKE itobj 'getattributes)
        )
      )
      (SETQ width-ename (LAST (ASSOC "WIDTH" attag-lst)))
      (getfield width-ename)
      (SETQ width-str0 fexp
            objndx (DOS_STRFIND width-str0 "16.2 ")
            width-stra (SUBSTR width-str0 1 (1- objndx))
            width-strb (SUBSTR width-str0 (+ objndx 5))
            width-strc (STRCAT width-stra width-strb)
            objidndx (+ 2 (DOS_STRFIND width-strc "x"))
            width-str1 (SUBSTR width-strc 1 (- objidndx 2))
            width-str2 (STRCAT " " blkobjid)
            width-str3 (SUBSTR width-strc (+ 2 objidndx))
            width-str (STRCAT width-str1  width-str2 width-str3)
      )
      (IF (WCMATCH width-str "*`%ps`[`,\\\"`]*")
        (PROGN	  ; Removes inch mark formatting from field strings
          (SETQ width-str (STRCAT "%<" (DOS_STRREPLACE width-str "%ps[,\\\"]" "") ">%"))
          (SETQ edata (ENTGET width-ename))
          (SETQ edata (SUBST (CONS 1 width-str)(ASSOC 1 edata) edata))
          (ENTMOD edata)
        )
      )
      (SETQ height-ename (LAST (ASSOC "HEIGHT" attag-lst)))
      (getfield height-ename)
      (SETQ height-str0 fexp
            objndx (DOS_STRFIND height-str0 "16.2 ")
            height-stra (SUBSTR height-str0 1 (1- objndx))
            height-strb (SUBSTR height-str0 (+ objndx 5))
            height-strc (STRCAT height-stra height-strb)
            objidndx (+ 2 (DOS_STRFIND height-strc "x"))
            height-str1 (SUBSTR height-strc 1 (- objidndx 2))
            height-str2 (STRCAT " " blkobjid)
            height-str3 (SUBSTR height-strc (+ 2 objidndx))
            height-str (STRCAT height-str1  height-str2 height-str3)
      )
      (IF (WCMATCH height-str "*`%ps`[`,\\\"`]*")
        (PROGN	  ; Removes inch mark formatting from field strings
          (SETQ height-str (STRCAT "%<" (DOS_STRREPLACE height-str "%ps[,\\\"]" "") ">%"))
          (SETQ edata (ENTGET height-ename))
          (SETQ edata (SUBST (CONS 1 height-str)(ASSOC 1 edata) edata))
          (ENTMOD edata)
        )
      )
    )
  )
)
AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes