pmadhwal7 Posted August 19, 2023 Posted August 19, 2023 Hi, can anybody help me actually i have multiple text which i want to move at block insertion point as i am doing it through move command one by one but it take lots of time is any lisp available to move all text to block insertion point Before After Drawing2.dwg Quote
BIGAL Posted August 19, 2023 Posted August 19, 2023 Its a easy move select the text then look for the block using (ssget "CP" pts a small search window of points. Yes select all correct text. You have 347 posts so you should be starting to have a go yourself, I am sure if you google will find code for finding objects close by. Quote
Emmanuel Delay Posted August 21, 2023 Posted August 21, 2023 (edited) This should work ;; mttb for Move Text To Block (defun c:mttb ( / i j ss texts blocks ent ip1 ip2 dst ind) (setq ss (ssget (list (cons 0 "TEXT,INSERT")))) ;; lets make 2 selections. Texts and blocks (setq texts (ssadd)) (setq blocks (ssadd)) (setq i 0) (repeat (sslength ss) (setq ent (entget (ssname ss i))) (if (= "INSERT" (cdr (assoc 0 ent))) (ssadd (ssname ss i) blocks) (ssadd (ssname ss i) texts) ) (setq i (+ i 1)) ) ;; now we loop over the blocks, for each block we fine a text that's closest to that block. ;; (we could have chosen the the other way around) (setq i 0) (repeat (sslength blocks) (setq ip1 (cdr (assoc 10 (entget (ssname blocks i))))) (setq dst nil) ;; this holds the closest distance block-text (setq ind nil) ;; this holds the index j for the closest distance (setq j 0) (repeat (sslength texts) (setq ip2 (cdr (assoc 10 (entget (ssname texts j))))) (if (= nil dst) (progn ;; first try (setq dst (distance ip1 ip2)) (setq ind j) ) (progn ;; next we see if we find anything better (if (< (distance ip1 ip2) dst) (progn (setq dst (distance ip1 ip2)) (setq ind j) ) ) ) ) (setq j (+ j 1)) ) ;; change insert point of TEXT (setq ent (ssname texts ind)) (entmod (subst (cons 10 ip1) ;; insert point of the block (assoc 10 (entget ent)) (entget ent) )) (setq i (+ i 1)) ) ;; this grips the text objects. Notr really needed, but why not (sssetfirst nil texts) (princ) ) EDIT Oh yes, you can add this line of code. (ssdel ...) will remove the text from the list. In that case the variable texts should be empty at the end, then nothing gets gripped at the end ;; change insert point of TEXT (setq ent (ssname texts ind)) (entmod (subst (cons 10 ip1) ;; insert point of the block (assoc 10 (entget ent)) (entget ent) )) ;; we can remove the TEXT from the selection. No need to keep using it after we found a match (ssdel (ssname texts ind) texts) Edited August 21, 2023 by Emmanuel Delay 1 Quote
pmadhwal7 Posted August 22, 2023 Author Posted August 22, 2023 On 8/21/2023 at 1:55 PM, Emmanuel Delay said: This should work ;; mttb for Move Text To Block (defun c:mttb ( / i j ss texts blocks ent ip1 ip2 dst ind) (setq ss (ssget (list (cons 0 "TEXT,INSERT")))) ;; lets make 2 selections. Texts and blocks (setq texts (ssadd)) (setq blocks (ssadd)) (setq i 0) (repeat (sslength ss) (setq ent (entget (ssname ss i))) (if (= "INSERT" (cdr (assoc 0 ent))) (ssadd (ssname ss i) blocks) (ssadd (ssname ss i) texts) ) (setq i (+ i 1)) ) ;; now we loop over the blocks, for each block we fine a text that's closest to that block. ;; (we could have chosen the the other way around) (setq i 0) (repeat (sslength blocks) (setq ip1 (cdr (assoc 10 (entget (ssname blocks i))))) (setq dst nil) ;; this holds the closest distance block-text (setq ind nil) ;; this holds the index j for the closest distance (setq j 0) (repeat (sslength texts) (setq ip2 (cdr (assoc 10 (entget (ssname texts j))))) (if (= nil dst) (progn ;; first try (setq dst (distance ip1 ip2)) (setq ind j) ) (progn ;; next we see if we find anything better (if (< (distance ip1 ip2) dst) (progn (setq dst (distance ip1 ip2)) (setq ind j) ) ) ) ) (setq j (+ j 1)) ) ;; change insert point of TEXT (setq ent (ssname texts ind)) (entmod (subst (cons 10 ip1) ;; insert point of the block (assoc 10 (entget ent)) (entget ent) )) (setq i (+ i 1)) ) ;; this grips the text objects. Notr really needed, but why not (sssetfirst nil texts) (princ) ) EDIT Oh yes, you can add this line of code. (ssdel ...) will remove the text from the list. In that case the variable texts should be empty at the end, then nothing gets gripped at the end ;; change insert point of TEXT (setq ent (ssname texts ind)) (entmod (subst (cons 10 ip1) ;; insert point of the block (assoc 10 (entget ent)) (entget ent) )) ;; we can remove the TEXT from the selection. No need to keep using it after we found a match (ssdel (ssname texts ind) texts) message flash Unknown command "MTTB". Press F1 for help Quote
pmadhwal7 Posted August 22, 2023 Author Posted August 22, 2023 On 8/20/2023 at 4:33 AM, BIGAL said: Its a easy move select the text then look for the block using (ssget "CP" pts a small search window of points. Yes select all correct text. You have 347 posts so you should be starting to have a go yourself, I am sure if you google will find code for finding objects close by. actually i used firstly google search but i didn't found correct answer then i came here Quote
Emmanuel Delay Posted August 22, 2023 Posted August 22, 2023 Copy paste my code to a empty text file. Save it as (for example) "place-the-insertion-point-of-block.lsp". Make sure the extenson is .lsp, and not .lsp.txt Then slide that file in your drawing, in the Autocad window. Or... what did you do with the code? Quote
BIGAL Posted August 23, 2023 Posted August 23, 2023 (edited) "Then slide that file in your drawing, in the Autocad window." In Windows often referred to as "Drag and drop". Open explorer, find the lisp file "place-the-insertion-point-of-block.lsp" click once, then hold left mouse button down and DRAG the file over to your CAD screen than let go, ie DROP. You can do the same with a dwg it will open the file. Edited August 23, 2023 by BIGAL Quote
pmadhwal7 Posted August 23, 2023 Author Posted August 23, 2023 18 hours ago, Emmanuel Delay said: Copy paste my code to a empty text file. Save it as (for example) "place-the-insertion-point-of-block.lsp". Make sure the extenson is .lsp, and not .lsp.txt Then slide that file in your drawing, in the Autocad window. Or... what did you do with the code? yes i do same, after that message flash Quote
nod684 Posted August 23, 2023 Posted August 23, 2023 Tested the code by @Emmanuel Delay and it's working perfectly fine on my side 1 Quote
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.