Results 1 to 4 of 4

Thread: how to replace only a single string by pre decided string.

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2014-04
    Posts
    1
    Login to Give a bone
    0

    Post how to replace only a single string by pre decided string.

    Hi....
    My query is that I want to replace the value of a pre decided string to a single string by clicking on it. Find and replace is not useful for this because it replaces all strings. For example in autocad drawing any text is given and by clicking on this text it should be replaced by pre decided text "xyz" (for example).

    Thanks in advance!!!!!

  2. #2
    Member
    Join Date
    2013-08
    Posts
    23
    Login to Give a bone
    0

    Default Re: how to replace only a single string by pre decided string.

    Code:
    (if
      (vl-string-search 
        "<Unique Identifier>" 
        (setq txt1 
          (vlax-get-property 
            (setq ent1 
              (vlax-ename->vla-object (car(entsel "\nSelect Text:\t")))
          )
          'textstring)
        )
      )
      (vlax-put-property ent1 'textstring (strcat "<Your Text Stuff Here>" "<More Stuff>"))
    )

    You could put a test at the if function to test that it is at the beginning of the string if it's not a unique identifier (i.e. it could appear in the text after it, false positives). Yes it could be more robust, testing for nil entities etc, but that will get you started.
    Last edited by ngwalters412556; 2014-04-18 at 03:01 PM. Reason: Code Wrap

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

    Default Re: how to replace only a single string by pre decided string.

    Quote Originally Posted by mohammad.raees637333 View Post
    Hi....
    My query is that I want to replace the value of a pre decided string to a single string by clicking on it. Find and replace is not useful for this because it replaces all strings. For example in autocad drawing any text is given and by clicking on this text it should be replaced by pre decided text "xyz" (for example).

    Thanks in advance!!!!!
    Find and replace gives the options to Replace or Find Next as well as Replace All. What version are you using?

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

    Default Re: how to replace only a single string by pre decided string.

    Quote Originally Posted by mohammad.raees637333 View Post
    My query is that I want to replace the value of a pre decided string to a single string by clicking on it. Find and replace is not useful for this because it replaces all strings. For example in autocad drawing any text is given and by clicking on this text it should be replaced by pre decided text "xyz" (for example).
    I am unsure if you intentionally requested to select each-and-every-single text entity one-at-a-time or not, so this will allow you to do that, or select multiple text entities at once:

    Code:
    (defun c:FOO (/ *error* acDoc)
    
      (defun *error* (msg)
        (if	acDoc (vla-endundomark acDoc))
        (cond ((not msg))							; Normal exit
    	  ((member msg '("Function cancelled" "quit / exit abort")))	; <esc> or (quit)
    	  ((princ (strcat "\n** Error: " msg " ** ")))			; Fatal error, display it
        )
        (princ)
      )
    
      (if (ssget "_:L" '((0 . "TEXT,MTEXT")))
        (progn
          (vla-startundomark
    	(setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
          )
          (vlax-for	x (vla-get-activeselectionset acDoc)
    	(vla-put-textstring x "xyz")
          )
        )
      )
      (*error* nil)
    )
    "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

Similar Threads

  1. String Parameters & Field Functionality in a Single Block
    By Wish List System in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2014-08-18, 04:45 PM
  2. How do I replace part of a string?
    By aaronic_abacus in forum AutoLISP
    Replies: 2
    Last Post: 2009-12-12, 06:24 PM
  3. Replies: 0
    Last Post: 2008-05-22, 08:49 PM
  4. Find string in drawing and replace with VBA
    By montana.fox in forum VBA/COM Interop
    Replies: 3
    Last Post: 2006-03-01, 04:51 AM
  5. find and replace removing first letter string
    By tyeelaw13 in forum AutoCAD General
    Replies: 9
    Last Post: 2005-05-03, 04:20 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
  •