jr.roberto.santos Posted December 27, 2021 Share Posted December 27, 2021 hello everyone, I'd like to share an idea based on the Leemac script (Escape Wildcards). is working fine, but I would like help for code optimization. 1: Searches the text according to the wildcard setting 2: selects all texts found 3: If the wildcard is found, it creates the layer and changes the blocks to its layers. 4: Sets the color of the layer 5: converts to block (HDV1_CONVERT) As you can see in the attachment, when I run the script for the first time, the alert appears. Is there any way to accept the alert automatically? Regards ::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ;;Autocad Electrical String Match and convert ;;search wildcard text and convert to component (block: HDV1_CONVERT) ;;http://www.lee-mac.com/escapewildcards.html Reference (defun c:CALL_TAG1 ();; START (vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "TAG_1\r") (vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "CALL_TAG2\r") ) (defun c:CALL_TAG2 () (vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "TAG_2\r") (vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "CALL_TAG3\r") ) (defun c:CALL_TAG3 () (vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "TAG_3\r") ;;(vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "CALL_TAG4\r") ;;... ) (defun c:TAG_1 (/ ss) ;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ;; Set of variables (setq 1_sequence "@@###`.@@@`.###A") (setq 1_layer "TAG1_LAYER_A") (setq 1_color "0,255,0") (setq 2_sequence "@@###`.@@@`.###B") (setq 2_layer "TAG2_LAYER_B") (setq 2_color "0,0,255") (setq 3_sequence "@@###`.@@@`.###C") (setq 3_layer "TAG3_LAYER_C") (setq 3_color "0,255,255") ;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ (if (setq ss (car (cdr (ssgetfirst)))) (command "._zoom" "1" ss "") (progn (C:SEARCH_BY_WILDCARD1) (C:SendToNewLayer1) (princ) );; progn );; if ) ;#################################################################################### ;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$CALL_SCRIPT_JANSSEN_TAG_002 (defun c:TAG_2 (/ ss) (if (setq ss (car (cdr (ssgetfirst)))) (command "._zoom" "1" ss "") (progn (C:SEARCH_BY_WILDCARD2) (C:SendToNewLayer2) (princ) );; progn );; if ) ;#################################################################################### ;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$CALL_SCRIPT_JANSSEN_TAG_003 (defun c:TAG_3 (/ ss) (if (setq ss (car (cdr (ssgetfirst)))) (command "._zoom" "1" ss "") (progn (C:SEARCH_BY_WILDCARD3) (C:SendToNewLayer3) (princ) );; progn );; if ) ;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ;;http://www.lee-mac.com/escapewildcards.html Reference (vl-load-com);;CARREGAR OUTRO LISP ;;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ (defun c:SEARCH_BY_WILDCARD1 ( / str ) (if (/= "" (setq str 1_sequence)) (sssetfirst nil (ssget "_X" (list '(0 . "TEXT") (cons 1 (LM:escapewildcards str)) ) ) ) ) (princ) ) ;;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ;; Escapes wildcard special characters in a supplied string (defun LM:escapewildcards ( str ) (if (wcmatch str str) ; (if (wcmatch str str) ; (strcat "`" (substr str 1 1) (LM:escapewildcards (substr str 2))) (strcat (substr str 1 1) (LM:escapewildcards (substr str 2))) ) str ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SELECIONAR E JOGAR PARA A SUA CAMADA;;;;;;;;;;;;;;;;; ; Changes selected objects to Layer ;NovaCamada criar uma camada nova e jogar os Selecionar pra dentro (defun c:SendToNewLayer1 () (if (setq ss (car (cdr (ssgetfirst)))) (tolayer1 (ssget "_P") ;;selection exclude lock layer 1_layer ) (progn (princ) );; progn );; if ) (defun tolayer1 ( ss lay / i e ) ;;; ss - pickset ;;; lay -layer name (repeat (setq i (sslength ss)) (entmod (subst (cons 8 lay) (assoc 8 (entget (setq e (ssname ss (setq i (1- i)))))) (entget e) ) ) ) (command "-LAYER" "_N" 1_layer"") (command "-LAYER" "color" "Truecolor" 1_color 1_layer"") (command "-LAYER" "set" 1_layer"") (vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "SEARCH_BY_WILDCARD1\r") (vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "AETAGSCH _P\r\r\r_qsave\r") ) ;;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ;;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ;;http://www.lee-mac.com/escapewildcards.html Reference (defun c:SEARCH_BY_WILDCARD2 ( / str ) (if (/= "" (setq str 2_sequence)) (sssetfirst nil (ssget "_X" (list '(0 . "TEXT") (cons 1 (LM:escapewildcards str)) ) ) ) ) (princ) ) ;;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ;; Escapes wildcard special characters in a supplied string (defun LM:escapewildcards ( str ) (if (wcmatch str str) ; (if (wcmatch str str) ; (strcat "`" (substr str 1 1) (LM:escapewildcards (substr str 2))) (strcat (substr str 1 1) (LM:escapewildcards (substr str 2))) ) str ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SELECIONAR E JOGAR PARA A SUA CAMADA;;;;;;;;;;;;;;;;; ; Changes selected objects to Layer ;NovaCamada criar uma camada nova e jogar os Selecionar pra dentro (defun c:SendToNewLayer2 () (if (setq ss (car (cdr (ssgetfirst)))) (tolayer2 (ssget "_P") ;;selection exclude lock layer 2_layer ) (progn (princ) );; progn );; if ) (defun tolayer2 ( ss lay / i e ) ;;; ss - pickset ;;; lay -layer name (repeat (setq i (sslength ss)) (entmod (subst (cons 8 lay) (assoc 8 (entget (setq e (ssname ss (setq i (1- i)))))) (entget e) ) ) ) (command "-LAYER" "_N" 2_layer"") (command "-LAYER" "color" "Truecolor" 2_color 2_layer"") (command "-LAYER" "set" 2_layer"") (vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "SEARCH_BY_WILDCARD2\r") (vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "AETAGSCH _P\r\r\r_qsave\r") ) ;;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ;;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ;;http://www.lee-mac.com/escapewildcards.html Reference (defun c:SEARCH_BY_WILDCARD3 ( / str ) (if (/= "" (setq str 3_sequence)) (sssetfirst nil (ssget "_X" (list '(0 . "TEXT") (cons 1 (LM:escapewildcards str)) ) ) ) ) (princ) ) ;;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ;; Escapes wildcard special characters in a supplied string (defun LM:escapewildcards ( str ) (if (wcmatch str str) ; (if (wcmatch str str) ; (strcat "`" (substr str 1 1) (LM:escapewildcards (substr str 2))) (strcat (substr str 1 1) (LM:escapewildcards (substr str 2))) ) str ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SELECIONAR E JOGAR PARA A SUA CAMADA;;;;;;;;;;;;;;;;; ; Changes selected objects to Layer ;NovaCamada criar uma camada nova e jogar os Selecionar pra dentro (defun c:SendToNewLayer3 () (if (setq ss (car (cdr (ssgetfirst)))) (tolayer3 (ssget "_P") ;;selection exclude lock layer 3_layer ) (progn (princ) );; progn );; if ) (defun tolayer3 ( ss lay / i e ) ;;; ss - pickset ;;; lay -layer name (repeat (setq i (sslength ss)) (entmod (subst (cons 8 lay) (assoc 8 (entget (setq e (ssname ss (setq i (1- i)))))) (entget e) ) ) ) (command "-LAYER" "_N" 3_layer"") (command "-LAYER" "color" "Truecolor" 3_color 3_layer"") (command "-LAYER" "set" 3_layer"") (vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "SEARCH_BY_WILDCARD3\r") (vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "AETAGSCH _P\r\r\r_qsave\r") ) ;;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ SEARCH_AND_CONVERT.zip Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.