FINDANDSELECTTXT_v1_00...............................free

Command: FINDTXT

Simple routine to find ans select TEXT and MTEXT objects that their content match exactly the text given by the user.

Command: FINDTXTWCM

As above but selects objects that contain frase given by the user. Lower or uppercase doesn't matter.

 

Code:

;;; ================================================
;;;        FINDandSELECTTXT_v1_00.LSP
;;;        
;;;        Written by Andrzej Kalinowski,     www.autolisps.blogspot.com
;;;        v1.00 - 08.04.2020 - first release
;;;
;;;        Command: FINDTXT
;;;              Simple routine to find ans select TEXT and MTEXT objects that their content match exactly the text given by the user.
;;;
;;;        Command: FINDTXTWCM
;;;              Simple routine to find and select TEXT and MTEXT objects that contain frase given by the user. Lower or uppercase doesn't matter.
;;;
;;; ================================================
(defun c:FINDTXT (/  sset1 text1)
    (setq text1 (GET_TEXT_FINDTXT ) )
    (if (setq sset1 (ssget "_A" (list (cons 0 "TEXT,MTEXT") (cons 1 text1)    )))
        (progn
            (sssetfirst nil)
            (sssetfirst nil sset1)
            (princ "Total objects selected:  ") (princ (sslength sset1) )
        );progn
    );if
    (princ)
);defun
(defun c:FINDTXTWCM (  / sset1 text1 txtcntnt i1 curobj sset2)
    (setq text1 (strcase (GET_TEXT_FINDTXT ) ) )
    (if (setq sset1 (ssget "_A" '( (0 . "TEXT,MTEXT")  ) ) )
        (progn
            (setq sset2 (ssadd) )
            (repeat (setq i1 (sslength sset1) )
                (setq curobj (ssname sset1 (setq i1 (1- i1) ) ) )
                (if (/= nil (vl-string-search text1 (strcase (vlax-get (vlax-ename->vla-object curobj) 'TextString) ) ) )
                    (ssadd curobj sset2);adding elements from sset1 to sset2
                );end if
            );repeat
            (sssetfirst nil)
            (sssetfirst nil sset2)
            (princ "Total objects selected:  ") (princ (sslength sset2) )
        );progn
    );if
    (princ)
);defun
;;; ================================================
;                     DCL SECTION                                         
;;; ================================================
(defun GET_TEXT_FINDTXT (   / file1 dcl_id result1 tmploc)
    (setq tmploc (getvar "MYDOCUMENTSPREFIX") )
    (setq file1 (open (strcat tmploc "\\window1.dcl") "w") )
    (write-line
             "dialog1 : dialog
                { label = \"Text seeker\"; 
                    : edit_box { label = \"Set text:\"; key = \"Swindow\";  mnemonic = \"W\"; width = 40; allow_accept = true; } 
                    ok_cancel;  
                }"
        file1
    )
    (close file1)
    (setq dcl_id (load_dialog (strcat tmploc "\\window1.dcl")))
    (if(not(new_dialog "dialog1" dcl_id))(exit))
    (mode_tile "Swindow" 2);sets window active
    (action_tile "accept" "(setq result1 (get_tile \"Swindow\")) (done_dialog)")
    (action_tile "cancel" "(done_dialog) ")
    (vl-file-delete (strcat tmploc "\\window1.dcl"))
    (start_dialog)
    (unload_dialog dcl_id)

    result1
);defun

;;; ================================================

Example:

Version history:
1.00 - 08.04.2020 - first release


 Compatibility:
-All Autocad
versions

Remarks:
-The application comes with the long command names listed above. To create your own short aliases for these commands, go to ACAD.PGP file or Menu Manage->Customization->Edit aliases->Edit Aliases.


Download file: FINDandSELECTTXT_v1_00.FAS

No comments:

Post a Comment