Author Topic: How to ssget the text with"[]" and replace it with pattern?  (Read 15141 times)

0 Members and 1 Guest are viewing this topic.

cjw

  • Guest
How to ssget the text with"[]" and replace it with pattern?
« on: March 06, 2009, 10:09:14 AM »
My english is poor so that I only can express the question with lisp code.

;Fisrt step:
(setq pattern1 "`[12`]")
(setq ss (ssget (list (cons 1 (strcat "*" pattern "*")))))
(setq v1_list (cjw-ss-value_list ss 1))

;_$ v1_list
("abc[12]" "abc[12]test" "123[12]")

;Second step:
(setq pattern2 "[12]")
(setq new_pattern "[abc456]")
(setq string "abc[12]test")

(while (vl-string-search pattern2 string)
  (setq string (vl-string-subst new_pattern pattern2 string))
)

;_$ string
"abc[abc456]test"

If (= pattern2 pattern1 "`[12`]")

How to finish the Second step ?

I am sorry my poor english that i can't express the problem clearly!
always i want to help others. always have this trouble. :-(

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #1 on: March 06, 2009, 11:00:49 AM »
I don't understand the question.
Please try again to explain.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #2 on: March 06, 2009, 11:20:36 AM »
??
(vla-put-textstring ...
??
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #3 on: March 06, 2009, 11:45:04 AM »
ssget uses wcmatch rules and vl-string-* reads the string literally. what's the problem then?
« Last Edit: March 06, 2009, 11:49:04 AM by VovKa »

FengK

  • Guest
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #4 on: March 07, 2009, 01:59:04 AM »

I am sorry my poor english that i can't express the problem clearly!
always i want to help others. always have this trouble. :-(

How about writing your question in your native language? Someone here can probably translate for you.
« Last Edit: March 07, 2009, 02:02:05 AM by xycadd »

cjw

  • Guest
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #5 on: March 07, 2009, 09:46:50 AM »
Thank you all~!

OK...


我的问题是:

选择并替换带有通配符的字符串

遇到的困难是:

ssget的通配符需要用到转义字符,replace需要反转义字符

Bable Fish translation: <entered by CAB>My question is: Chooses and replaces has the wildcard character string of character Meets the difficulty is: the ssget wildcard character needs to use the figurative meaning character, replace to need the counter-figurative meaning character
« Last Edit: March 07, 2009, 04:04:53 PM by CAB »

cjw

  • Guest
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #6 on: March 07, 2009, 09:52:52 AM »
My aim is to achieve the replacement of function
The same as command "Find"

cjw

  • Guest
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #7 on: March 07, 2009, 10:03:51 AM »
oh! I forget it.

I have readed the "find.lsp" in CAD R14 long time ago.

May be that can help.

Thank you every one. Thanks for your help!!!


cjw

  • Guest
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #8 on: March 07, 2009, 11:00:32 AM »
After read the "FIND.LSP" from CAD R14
I know replace the text. only use "(setq sset (ssget (list (cons 0 "TEXT"))))"
but not use "(setq sset (ssget (list (cons 0 "TEXT") (cons 1 (strcat "*" pattern "*")))))"


Quote
;;;     FIND.LSP
;;;     Copyright (C) 1997 by Autodesk, Inc.
;;;
;;;     Permission to use, copy, modify, and distribute this software
;;;     for any purpose and without fee is hereby granted, provided
;;;     that the above copyright notice appears in all copies and
;;;     that both that copyright notice and the limited warranty and
;;;     restricted rights notice below appear in all supporting
;;;     documentation.
;;;
;;;     AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
;;;     AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
;;;     MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
;;;     DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
;;;     UNINTERRUPTED OR ERROR FREE.
;;;
;;;     Use, duplication, or disclosure by the U.S. Government is subject to
;;;     restrictions set forth in FAR 52.227-19 (Commercial Computer
;;;     Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
;;;     (Rights in Technical Data and Computer Software), as applicable.
;;;
;;;     Credits: Bill Kramer, Q.C.
;;;              Dominic Panholzer
;;;              Randy Kintzley, Error Handling
;;;              Greg Robinson



;|   Check to see if AI_UTILS is loaded, If not, try to find it,
     and then try to load it.

    If it can't be found or it can't be loaded, then abort the
    loading of this file immediately, preserving the (autoload)
    stub function.
|;

(cond
  ((and ai_dcl (listp ai_dcl)))      ; it's already loaded.

  ((not (findfile "ai_utils.lsp"))   ; find it
   (ai_abort "DDCHPROP"
        (strcat "Can't locate file AI_UTILS.LSP."
           "\n Check support directory."
        )
   )
  )

  ((eq "failed" (load "ai_utils" "failed")) ; load it
   (ai_abort "DDCHPROP" "Can't load file AI_UTILS.LSP")
  )
)               ;end conditional

(if (not (ai_acadapp))         ; defined in AI_UTILS.LSP
  (ai_abort "DDCHPROP" nil)      ; a Nil <msg> supresses
)               ; ai_abort's alert box dialog.




               ;    metering prompt
(defun gc_meter   (gcm_pr gc_num gc_max)
  (prompt
    (strcat "\r"
       gcm_pr
       " ("
       (rtos (* (/ (float (1+ gc_num)) (float gc_max)) 100) 2 0)
       "%)"
    )               ;strcat
  )               ;prompt   
)               ;defun

(defun C:FIND
         (/       mode    replace_loc  _accept
          _replace       text    text_string  index
          pointer       sset    id         text_string_length
          *olderror*
         )
  (init_bonus_error
    (list
      (list "cmdecho"
       0
      )
      T               ;flag. True means use undo for error clean up. 
    )               ;list 
  )               ;init_bonus_error

               ;process an ok
  (defun _accept ()
    (cond
      (
       (or
    (=
      (get_tile "find")
      ""
    )
               ; (=
               ;    (get_tile "replace")
               ;    ""
               ; )
       )
       (set_tile "error" "Empty or invalid input")
      )
      (
       (=
    (get_tile "find")
    (get_tile "replace")
       )
       (set_tile "error" "Find and replace are identical")
      )
      (T
       (setq #find_string (get_tile "find"))
       (setq #replace_string (get_tile "replace"))
       (setq #case_sensitive (get_tile "case"))
       (setq #global (get_tile "global"))
       (done_dialog 1)
      )
    )
  )

               ;function for prompt to replace
  (defun _replace ()
    (new_dialog "find2" id "" replace_loc)
    (action_tile "cancel" "(done_dialog)(exit)")
    (action_tile "accept" "(setq replace_loc (done_dialog 1))")
    (action_tile "skip" "(setq replace_loc (done_dialog 0))")
    (action_tile "auto" "(done_dialog 2)")
    (set_tile
      "error"
      (strcat
   (rtos (1+ index) 2 0)
   " of "
   (rtos (sslength sset) 2 0)
      )
    )
    (start_dialog)
  )

               ;set up the dialog identification
  (setq id (load_dialog "find"))

               ;open dialog and store location as a global
  (new_dialog "find" id)

               ;set those defaults
  (if
    #find_string
     (set_tile "find" #find_string)
  )
  (if
    #replace_string
     (set_tile "replace" #replace_string)
  )
  (if
    #case_sensitive
     (set_tile "case" #case_sensitive)
  )
  (if
    #global
     (set_tile "global" #global)
  )

               ;set up callbacks
  (action_tile "accept" "(_accept)")
  (mode_tile "find" 2)

               ;process the look for the callbacks
  (if
               ;make changes if ok is picked
    (=
      (start_dialog)
      1
    )
     (progn
               ;get a selection set if not global
       (if (/= #global "1")
    (while
      (=
        (setq sset (ssget (list (cons 0 "TEXT"))))
        nil
      )
       (prompt "\nNo entities selected")
    )
    (setq sset (ssget "_X" (list (cons 0 "TEXT"))))
       )
       (setq index 0)
               ;go through the selection set
       (while (and sset
         (/=
           (setq text (ssname sset index))
           nil
         )
         )
               ;go through each string
    (setq pointer 1)
    (setq text_string (cdr (assoc 1 (entget text))))
    (if
      (<=
        (strlen #find_string)
        (strlen text_string)
      )
       (progn
         (setq text_string_length (strlen text_string))
               ;go until you reach the end of the string
         (while
      (<
        pointer
        (+ (- text_string_length (strlen #find_string)) 2)
      )
       (if
         (=
           (if
             (= #case_sensitive "1")
         (substr
           text_string
           pointer
           (strlen #find_string)
         )
         (strcase
           (substr
             text_string
             pointer
             (strlen #find_string)
           )
         )
           )
           (if (= #case_sensitive "1")
             #find_string
             (strcase #find_string)
           )
         )
          (progn
            (redraw text 3)
            (if (/= mode 2)
         (if (/= #global "1")
           (setq mode (_replace))
           (setq mode 2)
         )
            )
            (if (> mode 0)
         (progn
           (setq   text_string
             (if (= pointer 1)
               (strcat
                 #replace_string
                 (substr
                   text_string
                   (+ pointer (strlen #find_string))
                 )
               )
               (strcat
                 (substr
                   text_string
                   1
                   (- pointer 1)
                 )
                 #replace_string
                 (substr
                   text_string
                   (+ pointer (strlen #find_string))
                 )
               )
             )
           )
           (entmod
             (subst
               (cons 1 text_string)
               (assoc 1 (entget text))
               (entget text)
             )
           )
           (setq
             pointer
              (+ pointer (strlen #replace_string))
           )
           (setq
             text_string_length
              (strlen text_string)
           )
         )
            )
            (redraw text 4)
            (setq pointer (1+ pointer))
          )
          (setq pointer (1+ pointer))
       )
         )
       )
    )
    (gc_meter "Changing text" index (sslength sset))
    (setq index (1+ index))
       )
     )
  )
  (unload_dialog id)
  (restore_old_error)
  (princ)
)               ;defun find
(princ
  "FIND Loaded. Find and Replace DText Strings. FINDHELP for Help\n"
)
(princ)

(defun c:findhelp (/)
  (prompt
    "The find command preforms a find and replace on Dtext strings.\n"
  )
  (prompt "This version does not support Mtext.\n")
  (prompt
    "Usage is through the Dialog box, note the options! \n"
  )
  (prompt "User can preform Selected or Global replacement.\n"
  )
  (prompt "Case is supported, check option in Dialog.\n")
  (prompt
    "If the Dialog fails to appear, check your Support path.\n"
  )
  (prompt "Files used: Find.lsp & Find.dcl\n")
  (prompt "Type FIND to begin command.\n")
  (textscr)
  (princ)
)



MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #9 on: March 07, 2009, 11:04:21 AM »
;;;     Use, duplication, or disclosure by the U.S. Government is subject to
;;;     restrictions set forth in FAR 52.227-19 (Commercial Computer
;;;     Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
;;;     (Rights in Technical Data and Computer Software), as applicable.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

cjw

  • Guest
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #10 on: March 07, 2009, 11:34:36 AM »
sorry,MP

I only can understand the lisp code.

what's that mean?

Does it mean can't copy??? :oops:
Quote
;;;     Use, duplication, or disclosure by the U.S. Government is subject to
;;;     restrictions set forth in FAR 52.227-19 (Commercial Computer
;;;     Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
;;;     (Rights in Technical Data and Computer Software), as applicable.


Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #11 on: March 07, 2009, 03:34:39 PM »
I'm no lawyer so ... *shrug*
Quote
Page 1
EXHIBIT CCS (10-91)
(Ref.: FAR 52.227-19)
COMMERCIAL COMPUTER SOFTWARE--RESTRICTED RIGHTS
(a) As used in this clause, "restricted computer software" means any computer program, computer data base, or
documentation thereof, that has been developed at private expense and either is a trade secret, is commercial or
financial and confidential or privileged, or is published and copyrighted.
(b) Notwithstanding any provisions to the contrary contained in any standard commercial license or lease
agreement pertaining to any restricted computer software delivered under this purchase order/subcontract, and
irrespective of whether any such agreement has been proposed prior to or after issuance of this purchase
order/subcontract or of the fact that such agreement may be affixed to or accompany the restricted computer software
upon delivery, Seller agrees that the Company and the Government shall have the rights that are set forth in
paragraph (c) of this clause to use, duplicate, or disclose any restricted computer software delivered under this
purchase order/subcontract. The terms and provisions of this subcontract, including any commercial lease or license
agreement, shall be subject to paragraph (c) of this clause and shall comply with Federal laws and the Federal
Acquisition Regulation.
(c) (1)
The restricted computer software delivered under this subcontract may not be used, reproduced, or
disclosed by the Company or the Government except as provided in subparagraph (c)(2) of this clause or as
expressly stated otherwise in this subcontract.
(2)
The restricted computer software may be:
(i) Used or copied for use in or with the computer or computers for which it was acquired, including
use at any Government installation to which such computer or computers may be transferred;
(ii) Used or copied for use in or with backup computer if any computer for which it was acquired is
inoperative;
(iii) Reproduced for safekeeping (archives) or backup purposes;
(iv) Modified, adapted, or combined with other computer software, provided that the modified,
combined, or adapted portions of the derivative software incorporating any of the delivered, restricted computer
software shall be subject to same restrictions set forth in this purchase order/subcontract;

(v) Disclosed to and reproduced for use by support service contractors or subcontractors, subject to
the same restrictions set forth in this purchase order/subcontract; and
(vi) Used or copied for use in or transferred to a replacement computer.
(3)
If the restricted computer software delivered under this purchase order/subcontract is published and
copyrighted, it is licensed to the Company and the Government, without disclosure prohibitions, with the rights set
forth in subparagraph (c)(2) of this clause unless expressly stated otherwise in this purchase order/subcontract.
(4)
To the extent feasible the Seller shall affix a Notice substantially as follows to any restricted computer
software delivered under this purchase order/subcontract; or, if the Seller does not, the Company and the Government
have the right to do so: "Notice--Notwithstanding any other lease or license agreement that may pertain to, or
accompany the delivery of, this computer software, the rights of the Company and the Government regarding its use,
reproduction, and disclosure are as set forth in Martin Marietta Energy Systems, Inc., Subcontract No.
_____________.
(d) If any restricted computer software is delivered under this subcontract with the copyright notice of 17 U.S.C.
401, it will be presumed to be published and copyrighted and licensed to the Company and the Government in
accordance with subparagraph (c)(3) of this clause, unless a statement substantially as follows accompanies such
copyright notice: "Unpublished--rights reserved under the copyright laws of the United States."

TheSwamp.org  (serving the CAD community since 2003)

scottcd

  • Newt
  • Posts: 52
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #12 on: March 07, 2009, 03:43:38 PM »
Quote
;;;     FIND.LSP
;;;     Copyright (C) 1997 by Autodesk, Inc.
;;;
;;;     Permission to use, copy, modify, and distribute this software
;;;     for any purpose and without fee is hereby granted, provided
;;;     that the above copyright notice appears in all copies and
;;;     that both that copyright notice and the limited warranty and
;;;     restricted rights notice below appear in all supporting
;;;     documentation.

Surely so long as this is included any modification is entirely within the intent of the release of the lisp originally?

AutoCAD Dos R9 - 2018 and BricCAD 18.2

gskelly

  • Newt
  • Posts: 185
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #13 on: March 07, 2009, 03:58:57 PM »
;;;     Use, duplication, or disclosure by the U.S. Government is subject to
;;;     restrictions set forth in FAR 52.227-19 (Commercial Computer
;;;     Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
;;;     (Rights in Technical Data and Computer Software), as applicable.

Looks to me like this portion is placing limitations on the actions / rights the
U.S. Government...

I second scottcd's comment.

But I am not a lawyer.
Bricscad v12

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to ssget the text with"[]" and replace it with pattern?
« Reply #14 on: March 07, 2009, 03:59:34 PM »
And that's why the code is still posted in this thread.  8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.