Author Topic: Global Attribute Edit w/ Widcard  (Read 250 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Global Attribute Edit w/ Widcard
« on: February 29, 2024, 04:07:55 PM »
I trying to use Peter's function with a wildcard to reset a tags value.
(AttributeStringSubst "SYMRM" "NOTE2" wildcard "")
Need help, please.


Code - Auto/Visual Lisp: [Select]
  1. ;;;(AttributeStringSubst BlockName TagString OldText NewText)
  2. ;;;Peter Jamtgaard
  3. (defun AttributeStringSubst
  4.                                  (strBlockName    strTagString
  5.                                   strPattern      strNewString
  6.                                   /               strString
  7.                                  )
  8.             objLayout
  9.                      (vla-get-layouts
  10.                        (vla-get-activedocument (vlax-get-acad-object))
  11.                      )
  12.     (vlax-for
  13.               objBlock
  14.                       (vla-get-block objLayout)
  15.       (if (and (wcmatch
  16.                  (vla-get-objectname objBlock)
  17.                  "AcDbBlockReference,AcDbMInsertBlock"
  18.                )
  19.                (wcmatch (strcase strBlockName)
  20.                         (strcase (vla-get-name objBlock))
  21.                )
  22.                (= (vla-get-hasattributes objBlock) :vlax-true)
  23.           )
  24.         (foreach
  25.                   objAttribute
  26.                               (vlax-invoke objBlock "getattributes")
  27.           (setq strString (vla-get-textstring objAttribute))
  28.           (if (wcmatch
  29.                 (strcase (vla-get-tagstring objAttribute))
  30.                 (strcase strTagString)
  31.               )
  32.             (if (not (vl-string-search strPattern strNewString))
  33.               (progn (while (vl-string-search strPattern strString 0)
  34.                        (setq strString
  35.                               (vl-string-subst strNewString strPattern strString)
  36.                        )
  37.                      )
  38.                      (vla-put-textstring objAttribute strString)
  39.               )
  40.             )
  41.           )
  42.         )
  43.       )
  44.     )
  45.   )
  46.   (princ))
  47.  
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12910
  • London, England
Re: Global Attribute Edit w/ Widcard
« Reply #1 on: February 29, 2024, 06:46:19 PM »
Perhaps this can help Gary -
https://www.theswamp.org/index.php?topic=58363.msg615317#msg615317

Though, I'm unsure what you mean by 'reset' - do you mean revert to the default value held by the attribute definition?

GDF

  • Water Moccasin
  • Posts: 2081
Re: Global Attribute Edit w/ Widcard
« Reply #2 on: March 01, 2024, 08:40:37 AM »
Thanks Lee...works perfectly!!!
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64