Jump to content

Help lisp assign 2D text to "3D text" and "3D block" nearest.


Recommended Posts

Posted

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.

 123123.png

TEST 02.03.2022.dwg

Posted

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.

 

image.thumb.png.2f1ee4569bdb8db28a3c0e88226e2fdd.png

 

Some on else jump in bit busy with real work. 

Posted

Ah, just get the block in the middle of the text 😄

 Capture.png

Posted

Try This

 

Animation23666.gif.d7e3eb1e0905aa127c8591e7c9f982af.gif

 

(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

  • Thanks 1
Posted

Thank you. 
Can you help me add code convert text 2D to text 3D?

Posted

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

  • Thanks 1
Posted (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 by mhupp
  • Like 1
  • Thanks 1
Posted
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)
)

 

  • Like 1
Posted (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 by mhupp
lol forgot to put non in
  • Thanks 1
Posted

(setvar 'osmode 16384) is all off, but most times I use 0

  • Like 1

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...