tuantrinhdp Posted March 2, 2022 Posted March 2, 2022 Hello everyone. Please help me write lisp about problem: - I have text and block follow the text, i want to assign the 2d text to 3d text and set the 2d text to 3d of the block. - If a block has no text attached, it will automatically delete it. TEST 02.03.2022.dwg Quote
BIGAL Posted March 2, 2022 Posted March 2, 2022 Ok if understand correct look for block donut if it touches text then move donut Z to text value, ok easy to do. Problem found this will find 2 donuts touching text so need a special search for text, maybe a Bounding box style solution check for down bottom. Some on else jump in bit busy with real work. Quote
tuantrinhdp Posted March 3, 2022 Author Posted March 3, 2022 Ah, just get the block in the middle of the text Quote
Kajanthan Posted March 3, 2022 Posted March 3, 2022 Try This (defun c:bi () (vl-load-com) (setvar "OSMODE" 0) (command "-LAYER" "S" "CAO DO" "") (setq ss (ssget (list (cons 0 "TEXT,INSERT") (cons 8 "CAO DO")))) (repeat (setq x (sslength ss)) (setq ent (ssname ss (setq x (- x 1)))) (setq itm (cdr (assoc 0 (entget ent)))) (if (eq itm "TEXT") (progn (setq ins (cdr (assoc 11 (entget ent)))) (setq val (cdr (assoc 1 (entget ent)))) (setq pnt (list (car ins) (cadr ins) (atof val))) (command "-INSERT" "donut" pnt 0.0002 0.0002 0) ) ) (if (eq itm "INSERT") (entdel ent)) ) (princ) ) Block insert.lsp 1 Quote
tuantrinhdp Posted March 3, 2022 Author Posted March 3, 2022 Thank you. Can you help me add code convert text 2D to text 3D? Quote
Kajanthan Posted March 3, 2022 Posted March 3, 2022 Sorry, Updated ....... (defun c:bi (/ ss ent itm val pnt ) (vl-load-com) (setvar "OSMODE" 0) (setvar "CMDECHO" 0) (command "-LAYER" "S" "CAO DO" "") (setq ss (ssget (list (cons 0 "TEXT,INSERT") (cons 8 "CAO DO")))) (repeat (setq x (sslength ss)) (setq ent (ssname ss (setq x (- x 1)))) (setq itm (cdr (assoc 0 (entget ent)))) (if (eq itm "TEXT") (progn (setq ins (cdr (assoc 11 (entget ent)))) (setq val (cdr (assoc 1 (entget ent)))) (setq pnt (list (car ins) (cadr ins) (atof val))) (command "-INSERT" "donut" pnt 0.0002 0.0002 0) (entmod (subst (list 10 (car ins) (cadr ins) (atof val)) (assoc 10 (entget ent)) (entget ent))) ) ) (if (eq itm "INSERT") (entdel ent)) ) (princ) ) Block insert.lsp 1 Quote
mhupp Posted March 3, 2022 Posted March 3, 2022 (edited) @Kajanthan Its always best to leave command as the last choice if you can do it another way. (setvar 'clayer "CAO DO") ;set current layer to No real reason to turn off snaps since your pulling points from entget and using entmod to update the text. especially if your not restoring them to the old value. user will start to question why their snaps are randomly getting turned off. Also prob also want to turn cmdecho back on before exit. Saw this for setting & restoring values after lisp is done. (setq lst (list 'cmdecho 'osmode) val (mapcar 'getvar lst) ) (mapcar 'setvar lst '(0 0)) ..... (mapcar 'setvar lst val) or old reliable (setq oldsnap (getvar 'osmode)) (setvar 'osmode 0) ..... (setvar 'osmode oldsnap) Edited March 3, 2022 by mhupp 1 1 Quote
Kajanthan Posted March 4, 2022 Posted March 4, 2022 15 hours ago, mhupp said: @Kajanthan Its always best to leave command as the last choice if you can do it another way. (setvar 'clayer "CAO DO") ;set current layer to No real reason to turn off snaps since your pulling points from entget and using entmod to update the text. especially if your not restoring them to the old value. user will start to question why their snaps are randomly getting turned off. Also prob also want to turn cmdecho back on before exit. Saw this for setting & restoring values after lisp is done. (setq lst (list 'cmdecho 'osmode) val (mapcar 'getvar lst) ) (mapcar 'setvar lst '(0 0)) ..... (mapcar 'setvar lst val) or old reliable (setq oldsnap (getvar 'osmode)) (setvar 'osmode 0) ..... (setvar 'osmode oldsnap) Hi @mhupp , sorry for uncompleted code. Because, I am learning Lisp code by myself. Your reply helpful for me. Thank you so much. reason for turn off snaps, " -INSERT" command. (command "-INSERT" "donut" pnt 0.0002 0.0002 0) corrected code here.... (defun c:bi (/ ss ent itm val pnt svr) (setq lst (list 'cmdecho 'osmode) svr (mapcar 'getvar lst) ) (mapcar 'setvar lst '(0 0)) (setvar 'clayer "CAO DO") (setq ss (ssget (list (cons 0 "TEXT,INSERT") (cons 8 "CAO DO")))) (repeat (setq x (sslength ss)) (setq ent (ssname ss (setq x (- x 1)))) (setq itm (cdr (assoc 0 (entget ent)))) (if (eq itm "TEXT") (progn (setq ins (cdr (assoc 11 (entget ent)))) (setq val (cdr (assoc 1 (entget ent)))) (setq pnt (list (car ins) (cadr ins) (atof val))) (command "-INSERT" "donut" pnt 0.0002 0.0002 0) (entmod (subst (list 10 (car ins) (cadr ins) (atof val)) (assoc 10 (entget ent)) (entget ent))) ) ) (if (eq itm "INSERT") (entdel ent)) ) (mapcar 'setvar lst svr) (princ) ) 1 Quote
mhupp Posted March 4, 2022 Posted March 4, 2022 (edited) Ah sorry didn't see that. Another tip for osmode. You can add non right before the point and it wont snap to anything. Like the temp override snap when you shift right click. Don't ask me why/how but even with osmode set to 0 if your zoomed out enough and using command with points. stuff will still snap to entity's so its always good to use "_non". This is one of the reasons why I try to limit the use of command. Its also good to wrap selections with if. because if the user doesn't select anything no point in running the rest of the code and it could error also. ; error : bad argument type <NIL> ; expected SELECTIONSET at [sslength] (if (setq ss (ssget '((0 . "TEXT,INSERT") (8 . "CAO DO")))) ; only need to use cons when using variables (repeat (setq x (sslength ss)) (setq ent (ssname ss (setq x (- x 1)))) (cond ;like if but better see below ((eq (setq itm (cdr (assoc 0 (setq txt (entget ent))))) "TEXT") ;setq txt so you dont need to run entget 4 other times (setq ins (cdr (assoc 11 txt))) ;this depends on the text justification see below (setq val (cdr (assoc 1 txt))) (setq pnt (list (car ins) (cadr ins) (atof val))) (command "-INSERT" "donut" "_non" pnt 0.0002 0.0002 0) (entmod (subst (cons 10 pnt) (assoc 10 txt) txt)) ;use pnt aswell ) ((eq "INSERT" itm) (entdel ent) ) ) ) (prompt "\nNothing Selected") ) Check to see if right insertion point is used (if (eq (cdr (assoc 10 txt)) '(0.0 0.0 0.0)) (setq ins (cdr (assoc 11 txt))) (setq ins (cdr (assoc 10 txt))) ) Cond Guide Self taught here as well. just keep at it and stuff will start to make more and more sense. From what I have seen your way ahead of me when I started out. Edited March 4, 2022 by mhupp lol forgot to put non in 1 Quote
BIGAL Posted March 4, 2022 Posted March 4, 2022 (setvar 'osmode 16384) is all off, but most times I use 0 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.