Jump to content
pmadhwal7

Lsp to select text

Recommended Posts

pmadhwal7

Need a lsp which is allow me to select an particular text in all layouts tabs at once.

Share this post


Link to post
Share on other sites
tombu

There's ways to modify, but I don't believe you can select objects in multiple layouts at the same time.

Share this post


Link to post
Share on other sites
Roy_043
1 hour ago, tombu said:

but I don't believe you can select objects in multiple layouts at the same time.

Sure you can. But you must then process the selected entities programmatically without using command calls.

Share this post


Link to post
Share on other sites
rlx


(defun c:t1 (/ ss txt i e edat s)
  (defun *error* (msg) (princ msg))
  (cond
    ((not (setq txt (getstring "\nString to search : "))) (alert "No text was specified"))
    (t
     (setq txt (strcase (strcat "*" txt "*")))
     (foreach lay (cons "Model" (layoutlist))
       (setvar "CTAB" lay)
       (if (setq ss (ssget "X" (list '(0 . "TEXT") (cons 410 (getvar "CTAB")))))
         (repeat (setq i (sslength ss))
           (setq e (ssname ss (setq i (1- i))) edat (entget e) s (cdr (assoc 1 edat)))
           (if (wcmatch (strcase s) txt)
             (command "chprop" e "" "col" 1 "")
           )
         )
       )
       (setq ss nil)
     )
    )
  )
  (princ)
)

 

Share this post


Link to post
Share on other sites
Roy_043

@rlx

Yes of course that would be a possibility. I must admit I never do this. Anyway the OP is terribly vague, I don't know what the goal is here.

BTW: getstring will not return nil.

Share this post


Link to post
Share on other sites
rlx

Yeah you're right about the getstring , was more sort of cancel related and could have added check for empty string "" or "*" to be able to select all strings but decided to leave it with that because of as you say the vagueness of the request so expected it to be one of those snowball questions where every solution generates another question / request haha.

Share this post


Link to post
Share on other sites
pmadhwal7
Posted (edited)
12 hours ago, rlx said:

 


(defun c:t1 (/ ss txt i e edat s)
  (defun *error* (msg) (princ msg))
  (cond
    ((not (setq txt (getstring "\nString to search : "))) (alert "No text was specified"))
    (t
     (setq txt (strcase (strcat "*" txt "*")))
     (foreach lay (cons "Model" (layoutlist))
       (setvar "CTAB" lay)
       (if (setq ss (ssget "X" (list '(0 . "TEXT") (cons 410 (getvar "CTAB")))))
         (repeat (setq i (sslength ss))
           (setq e (ssname ss (setq i (1- i))) edat (entget e) s (cdr (assoc 1 edat)))
           (if (wcmatch (strcase s) txt)
             (command "chprop" e "" "col" 1 "")
           )
         )
       )
       (setq ss nil)
     )
    )
  )
  (princ)
)

Sir the code you posted is changing colour of the text and I want to select the entity and export it to excel or change the layers or anything else... please help me just like select similar command

 

 

Edited by pmadhwal7

Share this post


Link to post
Share on other sites
rlx

Like a said a snow ball question haha. Code was meant as a learning example, for those willing...

 

Have a look at it later , first have little job to do now.

 

An example of your drawing and how the output should look like would be helpful since I only use my mindreading powers in a casino.

Share this post


Link to post
Share on other sites
pmadhwal7

Like this image

20191008_145728.jpg

Share this post


Link to post
Share on other sites
rlx

if my eye is not deceiving me Sheet No. is just a separate text object and you want the text next to it , same for Patch Length. Or even 'worse' , the text's you want are attributes?

Need dwg and output format, either posted here or as P.M. , else no-can-do.

Share this post


Link to post
Share on other sites
pmadhwal7

Yes sir like sheet number text highlights after selection the same process I want to in all layouts, select it and export to excel or change the layers of particular object attachment is available

example.dwg

Share this post


Link to post
Share on other sites
rlx
Posted (edited)

To get you started.

Barely tested  (I'm a little busy at the moment)

 

(defun c:t2 (/ ss1 ss2 i result-list)
  (vl-load-com) (defun *error* (msg) (princ msg))
  (foreach lay (layoutlist)
    (setvar "CTAB" lay)
    (and
      (setq ss1 (ssget "_X" (list (cons 0 "*TEXT")(cons 1 "Patch Length*")(cons 410 (getvar "CTAB")))))
      (setq ss2 (ssget "_X" (list (cons 0 "*TEXT")(cons 1 "#*of #*")(cons 410 (getvar "CTAB")))))
      (setq result-list (cons (list (ssname ss2 0)(ssname ss1 0)) result-list))
    )
    (setq ss1 nil ss2 nil)
  )
  (if (yes_no "Change layer?") (chg_lay result-list))
  (if (yes_no "Write to csv file?") (csv-lst result-list))
  (princ)
)

(defun chg_lay (lst / new-lay pair item)
  (setq new-lay (getstring "\nEnter new layer : "))
  (if (and (vl-consp lst) new-lay (not (eq new-lay "")) (tblsearch "layer" new-lay))
    (foreach pair lst (foreach item pair (vla-put-layer (vlax-ename->vla-object item) new-lay)))
     ; remove complete cond if you want no error message when something went wrong
    (cond
      ((null new-lay)(princ "\nLayername kaput"))
      ((eq new-lay "")(princ "\nLayername void"))
      ((not (tblsearch "layer" new-lay))(princ (strcat "\nLayer name " new-lay " not present in drawing")))
      ((not (vl-consp lst))(princ "\nEmpty bucketlist"))
      (t (princ "\nDunno what's wrong, just know it is"))
    ); end cond
  )
  (princ)
)

(defun csv-lst (lst / csv-fn csv-fp pair item)
  (cond
    ((not (vl-consp lst))(princ "\nEmpty bucketlist"))
    ((not (setq csv-fn (getfiled "Enter name for (new) csv file" (getvar 'dwgprefix) "csv" 1)))
     (princ "\nNo name was provided for csv file"))
    ((not (setq csv-fp (open csv-fn "w")))(princ "\nUnable to create csv file"))
    (t (foreach item lst (write-line
      (strcat (cdr (assoc 1 (entget (car item)))) ";" (cdr (assoc 1 (entget (cadr item))))) csv-fp))
    )
  )
  (if csv-fp (progn (close csv-fp)(gc)))
  (if (and csv-fn (setq csv-fn (findfile csv-fn)))(startapp "notepad" csv-fn))
)

; (yes_no "Do you like snow")
(defun yes_no ( $m / f p i r ) (and (= (type $m) 'STR) (setq f (vl-filename-mktemp ".dcl")) (setq p (open f "w"))
  (write-line (strcat "yesno:dialog{label=\"" $m "?\";ok_cancel;}") p) (progn (close p)(gc) t) (setq i (load_dialog f))
    (new_dialog "yesno" i) (progn (action_tile "accept" "(done_dialog 1)")(action_tile "cancel" "(done_dialog 0)")
      (setq r (start_dialog))(unload_dialog i)(vl-file-delete f) t)(if (= r 1) t nil)))

🀄

Edited by rlx

Share this post


Link to post
Share on other sites
pmadhwal7

Share this post


Link to post
Share on other sites
rlx

then you haven't cut-copy-pasted the code right and your missing probable the last )

 

have attached the file.

 

gotta go now....

 

🐉

Pmadhwal7.lsp

  • Like 1

Share this post


Link to post
Share on other sites
mhupp

might not be exactly what you need but could be modified to meet your needs.

 

;;----------------------------------------------------------------------;;
;; Copy object(s) To All Layouts (excluding current and Model)
(defun C:CTAL (/ *error* _ss2lst llst olst)
  (vl-load-com)
  (defun *error* (msg)
    (and *AcadDoc* (vla-endundomark *AcadDoc*))
    (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
      (princ (strcat "\nError: " msg))
    )
  )
  (defun _ss2lst (ss / i l)
    (if ss
      (repeat (setq i (sslength ss))
        (setq l (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) l))
      )
    )
  )

  (vla-startundomark
    (cond
      (*AcadDoc*)
      ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
    )
  )

  (if (eq (getvar 'CVPORT) 1)
    (progn
      (princ "\nSelect object(s) to copy to all other layouts: ")
      (if (setq llst (list "Model" (getvar 'CTAB))
                olst (_ss2lst (ssget "_:L" (list (cons 410 (getvar 'CTAB)))))
          )
        (vlax-for layout (vla-get-layouts *AcadDoc*)
          (if (not (member (vla-get-name layout) llst))
            (vlax-invoke *AcadDoc* 'CopyObjects olst (vla-get-block layout))
          )
        )
      )
    )
    (alert "\n ** Command cannot be executed in ModelSpace! **")
  )

  (*error* nil)
  (princ)
)

 

Share this post


Link to post
Share on other sites
BIGAL

If it is an attribute then much easier to do. Have some sample lisps.

Share this post


Link to post
Share on other sites
pmadhwal7
14 hours ago, rlx said:

then you haven't cut-copy-pasted the code right and your missing probable the last )

 

have attached the file.

 

gotta go now....

 

🐉

Pmadhwal7.lsp 3.09 kB · 2 downloads

i don't want to change the color i just want to select that text after that i can delete or export to the excel for any type of error checking...

Share this post


Link to post
Share on other sites
pmadhwal7
3 hours ago, BIGAL said:

If it is an attribute then much easier to do. Have some sample lisps.

no sir it's a text...

Share this post


Link to post
Share on other sites
rlx
4 minutes ago, pmadhwal7 said:

i don't want to change the color i just want to select that text after that i can delete or export to the excel for any type of error checking...

 

All the text's are in a variable 'result-list' , in the program I just gave you 2 options what you can do with with them, change layer or export. What you want to do next with them is entirely up to you.

  • Like 1

Share this post


Link to post
Share on other sites
BIGAL

Nice one rlx (cons 1 "#*of #*") will try to remember that 

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...