See the top rated post in this thread. Click here

Results 1 to 5 of 5

Thread: Looking for an 'invisible' find and replace

  1. #1
    Member
    Join Date
    2014-12
    Posts
    3
    Login to Give a bone
    0

    Default Looking for an 'invisible' find and replace

    Hello all

    I'm looking for a specific Find and Replace routine with the following characteristics:
    Works with Text, Mtext, Block Attributes
    Works without user input
    Runs three times, replacing different text strings, each time.
    Could be assigned to a toolbar button

    Text I would like to Find/Replace
    Find "" (double quotes), Replace with $
    Find " (single quotes), Replace with nothing (essentially deleting the single quotes
    Find $, Replace with " (single quotes)

    I am using ATTIN out of Excel, which is adding quotation marks to my attributes,
    and would like a one-button 'fix' to remove them.

    I've scoured the internet and have not found exactly what I am looking for.

    Any help is greatly appreciated

    Thanks in advance!

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Looking for an 'invisible' find and replace

    Something like this?

    You can change it to be global with and "x" in the ssget statement or type all at the select objects prompt.

    P=

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard C.E., P.E., S.E. copyright 2018 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    ;
    ; Any use by unauthorized person or business is strictly prohibited.
    ;___________________________________________________________________________________________________________|
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Comand line function list
    ;___________________________________________________________________________________________________________|
    
    ;* C:TextFix
    ;* Command line function to remove quotes from text, mtext and attributes
    
    ;___________________________________________________________________________________________________________|
    ;
    ; General Function Header List
    ;___________________________________________________________________________________________________________|
    
    ;  Function List Argument1 Argument2 Arguement3
    
    ;* (ErrorTrap symFunction)
    ;* Standard Error Trap
    
    ;* (TextFix strReplace strFind strTextString)
    ;* Function to replace all single quotes with blanks and double quotes with single quotes
    
    ;* (TextSubstituteAll strReplace strFind strTextString)
    ;* Function to replace all instances of a find string in a text string with a replace string
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Command line function to remove quotes from text, mtext and attributes
    ;___________________________________________________________________________________________________________|
    
    (defun C:TextFix (/ intCount entSelection lstEntity objSelection ssSelections )
     (if (setq ssSelections (ssget (list (cons 0 "TEXT,MTEXT,INSERT"))))
      (repeat (setq intCount (sslength ssSelections))
       (and
        (setq intCount      (1- intCount))
        (setq entSelection  (ssname ssSelections intCOunt))
        (setq lstEntity     (entget entSelection))
        (setq objSelection  (vlax-ename->vla-object entSelection))
       )
       (if (wcmatch (vla-get-objectname objSelection) "AcDbBlockReference,AcDbMInsertBlock")
        (if (= (vla-get-hasattributes objSelection) :vlax-true)
         (foreach objAttribute (vlax-invoke  objSelection "getattributes")
          (TextFix objAttribute)
         )
        )
        (TextFix objSelection)
       )
      )
     )
     (princ)
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Standard Error Trap
    ;___________________________________________________________________________________________________________|
    
    (defun ErrorTrap (symFunction / objError result)
     (if (vl-catch-all-error-p
          (setq objError (vl-catch-all-apply
                         '(lambda (XYZ)(set XYZ (eval symFunction)))
                          (list 'result))))
      nil
      (or result 
          'T
      )
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to replace all single quotes with blanks and double quotes with single quotes
    ;___________________________________________________________________________________________________________|
    
    (defun TextFix (objSelection / strTextString)
     (and
      (setq strTextString (vla-get-textstring objSelection))
      (setq strTextString (TextSubstituteAll strTextString "\"\"" "$" ))
      (setq strTextString (TextSubstituteAll strTextString "\""   ""  ))
      (setq strTextString (TextSubstituteAll strTextString "$"    "\""))
      (errortrap '(vla-put-textstring objSelection strTextString)) 
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to replace all instances of a find string in a text string with a replace string
    ;___________________________________________________________________________________________________________|
    
    (defun TextSubstituteAll (strTextString strFind strReplace )
     (while (vl-string-search strFind strTextString)
      (setq strTextString (vl-string-subst strReplace strFind strTextString))
     )
     strTextString
    )
    
    (vl-load-com)
    Attached Files Attached Files
    AutomateCAD

  3. #3
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Looking for an 'invisible' find and replace

    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard C.E., P.E., S.E. copyright 2018 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    ;
    ; Any use by unauthorized person or business is strictly prohibited.
    ;___________________________________________________________________________________________________________|
    Why did you posted?

  4. #4
    Member
    Join Date
    2014-12
    Posts
    3
    Login to Give a bone
    0

    Default Re: Looking for an 'invisible' find and replace

    Thank you for the reply Peter!

    Unfortunately, I have not had a chance to test this yet, but I will post back as soon as I do.

    Thank

    2X

    Quote Originally Posted by peter View Post
    Something like this?

    You can change it to be global with and "x" in the ssget statement or type all at the select objects prompt.

    P=

  5. #5
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    1

    Default Re: Looking for an 'invisible' find and replace

    Well first... I always put a header on all of my code maintaining copyrights.

    If you would see all my libraries you would understand.

    What I share here I use a standard templates to build them on the fly after the question is posted.

    What I share here is also basic coding...

    What I share is intended to help teach the viewers to write professionally.

    Headers, good comments, good naming conventions for variables and functions...
    Good solid structured programming with built in error trapping (crashes look really bad to customers...)

    Also... then it becomes my decision whether the person is Authorized.

    So far I have never sued anyone for using my code,
    and it invites the person using it to rewrite it in their own style to own it.

    P=
    AutomateCAD

Similar Threads

  1. 2007: Find & replace
    By nextvkin in forum AutoCAD General
    Replies: 6
    Last Post: 2015-09-06, 11:19 PM
  2. FIND invisible attributes
    By Wish List System in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2013-02-06, 02:18 PM
  3. Find and replace on invisible attributes
    By geoff.80680 in forum AutoCAD General
    Replies: 0
    Last Post: 2009-03-04, 11:34 AM
  4. Find and Replace
    By U.Rackharrow in forum AutoCAD General
    Replies: 9
    Last Post: 2007-10-16, 02:44 PM
  5. Find & replace
    By markl.70662 in forum Revit Architecture - Wish List
    Replies: 4
    Last Post: 2005-05-25, 05:12 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
  •