Amending a 3D lisp routine

Amending a 3D lisp routine

Bencoleman164
Explorer Explorer
839 Views
4 Replies
Message 1 of 5

Amending a 3D lisp routine

Bencoleman164
Explorer
Explorer

I am trying to amend a lisp routine that currently reads selected text objects and places a vertical 3d line to the value of the number within the text object at the base point of each text object, for example a text object of 'x136.12' a vertical line is created to the length of 136.12 and is placed at the beginning of a text object. However, In some instances I need some 3D lines to be placed at the end of a text string because the 'x' character is at the end of the text string e.g. '136.12x'. I was wondering if it is possible to amend the below to place the 3D line either by recognising the 'x' character or to use a second lisp routine which I would just apply to text that has the 'x' at the end of the text string - that would place the 3D line at the end of the text string. 

 

(DEFUN txt23derr(S)
(IF(/= S "Function cancelled")
(PROGN(PRINC "error: ")(PRINC S)))
(SETVAR "CMDECHO" VCMDEC)
(setvar "osmode" vsnap)
(setq *error* verror)
(PRINC)
)
(DEFUN C:txt23d (/ awa kerroin e awal l luku p1 p2)
(SETQ VCMDEC(GETVAR "CMDECHO") vsnap (getvar "osmode")
verror *error* *error* tzt23derr)
(SETVAR "CMDECHO" 0)
(PROMPT "\nSelect Text objects:")
(SETQ AWA (SSGET))
(setq kerroin (getreal "\nZ scale factor?:"))
(if (not kerroin) (setq kerroin 1.0))
(setq l 0 awal (sslength awa) luku 0)
(setvar "osmode" 0)
(while (< l awal)
(if (= "TEXT" (cdr (assoc 0 (setq e (entget (ssname awa l))))))
(progn
(setq zeta (* kerroin (atof (cdr (assoc 1 e))))
apis (cdr (assoc 10 e))
epis (cadr (textbox e))
va (list (car apis) (cadr apis) 0)
oy (list (car apis) (cadr apis) zeta)
luku (1+ luku)
)
(command "line" va oy "")
)
)
(setq l (1+ l) )
)
(SETQ AWA NIL)
(SETVAR "CMDECHO" VCMDEC)
(setvar "osmode" vsnap)
(setq *error* verror)
(prompt (strcat "\n I created " (itoa luku) " lines!"))
(PRINC)
)

0 Likes
Accepted solutions (1)
840 Views
4 Replies
Replies (4)
Message 2 of 5

Sea-Haven
Mentor
Mentor

There is Box text by Lee-mac, Box Text | Lee Mac Programming .

 

It will give you a box that you can look at the points of the box.

(setq plent (entsel "\nPick rectang"))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))

You use (entlast) rather than selecting a entity. Part 2 is to look at where is  "X", is at start or end. You just get the midpoint of the correct vertices in co-ord.

(setq mp (mapcar '* (mapcar '+ (car co-ord) (cadr co-ord)) '(0.5 0.5)))

This should return 0 for "Xabcd" and 4 for "abcdx"

(setq pos (vl-string-position 88 (strcase str))) ; 88= X

Have a go if get stuck just ask here.

 

 

0 Likes
Message 3 of 5

komondormrex
Mentor
Mentor

check the following

(DEFUN txt23derr(S)
	(IF(/= S "Function cancelled")
		(PROGN (PRINC "error: ") (PRINC S)))
	(SETVAR "CMDECHO" VCMDEC)
	(setvar "osmode" vsnap)
	(setq *error* verror)
	(PRINC)
)
(DEFUN C:txt23d (/ awa kerroin luku text_value number)
	(SETQ VCMDEC(GETVAR "CMDECHO") vsnap (getvar "osmode")
	      verror *error* *error* tzt23derr
	)
	(SETVAR "CMDECHO" 0)
	(PROMPT "\nSelect Text objects:")
	(setq kerroin (getreal "\nZ scale factor?:"))
	(if (not kerroin) (setq kerroin 1.0))
	(setq luku 0)
	(setvar "osmode" 0)
  	(if (SETQ AWA (SSGET '((0 . "text") (1 . "x*,*x"))))
	  	(foreach text (vl-remove-if 'listp (mapcar 'cadr (ssnamex awa)))
		  (setq text_value (cdr (assoc 1 (entget text)))) 
		  (cond
		    ((and (= "x" (substr text_value 1 1)) (not (zerop (setq number (atof (substr text_value 2))))))
			(setq start_point (mapcar '+ (cdr (assoc 10 (entget text))) (car (textbox (entget text)))))
		    )
		    ((and (= "x" (substr text_value (strlen text_value) 1)) (not (zerop (setq number (atof (substr text_value 1 (1- (strlen text_value))))))))
			(setq start_point (mapcar '+ (cdr (assoc 10 (entget text))) (list (caadr (textbox (entget text))) (caar (textbox (entget text))))))
		    )
		    (t (setq number nil)) 
		  )
		  (if number
		    (progn
		      (setq zeta (* kerroin number)
			    start_point (list (car start_point) (cadr start_point) 0)
			    end_point (list (car start_point) (cadr start_point) zeta)
		      )
		      (command "_line" start_point end_point "")
		      (setq luku (1+ luku))
		    )
	    	  )
		)
	)
	(SETVAR "CMDECHO" VCMDEC)
	(setvar "osmode" vsnap)
	(setq *error* verror)
	(prompt (strcat "\n I created " (itoa luku) " lines!"))
	(PRINC)
)
0 Likes
Message 4 of 5

Bencoleman164
Explorer
Explorer

Thanks for the amended LISP, much appreciated! It is almost there, the text objects where the 'x' is at the start of the text is spot on, its where the 'x' is at the end where it seems to be off a little. I have attached a drawing with the lisp applied - could this be something to do with the format of the text in my specific drawing?

Bencoleman164_0-1734336883462.png

 

0 Likes
Message 5 of 5

komondormrex
Mentor
Mentor
Accepted solution

@Bencoleman164 wrote:

could this be something to do with the format of the text in my specific drawing?


nope. this is how textbox works with rotated texts. replaced it with et function.

(DEFUN txt23derr(S)
	(IF(/= S "Function cancelled")
		(PROGN (PRINC "error: ") (PRINC S)))
	(SETVAR "CMDECHO" VCMDEC)
	(setvar "osmode" vsnap)
	(setq *error* verror)
	(PRINC)
)
(DEFUN C:txt23d (/ awa kerroin luku text_value number)
	(SETQ VCMDEC(GETVAR "CMDECHO") vsnap (getvar "osmode")
	      verror *error* *error* tzt23derr
	)
	(SETVAR "CMDECHO" 0)
	(PROMPT "\nSelect Text objects:")
	(setq kerroin (getreal "\nZ scale factor?:"))
	(if (not kerroin) (setq kerroin 1.0))
	(setq luku 0)
	(setvar "osmode" 0)
  	(if (SETQ AWA (SSGET '((0 . "text") (1 . "x*,*x"))))
	  	(foreach text (vl-remove-if 'listp (mapcar 'cadr (ssnamex awa)))
		  (setq text_value (cdr (assoc 1 (entget text)))) 
		  (cond
		    ((and (= "x" (substr text_value 1 1)) (not (zerop (setq number (atof (substr text_value 2))))))
				(setq start_point (car (acet-geom-textbox (entget text) 0)))
			)
		    ((and (= "x" (substr text_value (strlen text_value) 1)) (not (zerop (setq number (atof (substr text_value 1 (1- (strlen text_value))))))))
				(setq start_point (cadr (acet-geom-textbox (entget text) 0)))
			)
		    (t (setq number nil)) 
		  )
		  (if number
		    (progn
		      (setq zeta (* kerroin number)
			    start_point (list (car start_point) (cadr start_point) 0)
			    end_point (list (car start_point) (cadr start_point) zeta)
		      )
		      (command "_line" start_point end_point "")
		      (setq luku (1+ luku))
		    )
	    	  )
		)
	)
	(SETVAR "CMDECHO" VCMDEC)
	(setvar "osmode" vsnap)
	(setq *error* verror)
	(prompt (strcat "\n I created " (itoa luku) " lines!"))
	(PRINC)
)
0 Likes