Add prefix to text

Add prefix to text

Anonymous
Not applicable
1,870 Views
5 Replies
Message 1 of 6

Add prefix to text

Anonymous
Not applicable

Hi guys,

 

I need some customization in the lisps resources I have found here and other websites. I have written some programs in VBA but I have no idea of LISP but been using others LISP files in the past which have been very helpful.

 

Basically I am using the following code (by others) and did some tweaking. If I draw a pline in CAD in mm, this routine puts the text underneath in m showing the line length.

 

I would like to add 2 features and if someone could help:

 

1. Add suffix to the text "m"

2. Iff the text number is less than 1.8m it should also add prefix "P1 " otherwise add prefix "M1 "

 

So in short, if a draw a line less than 1.8m long i should see text under the line "P1 xxm"

if line length is equal to or more than 1.8m i should see "M1 xxm"

 

Thanks in advance

 

(Defun c:BRR (/ pt1 pt2) ; Text over Polyline

(setvar "cmdecho" 0)
(if (setq pt1 (getpoint "\nPick the first Point: "))
(progn
(command "_Pline" pt1)
(while (> (getvar "CMDACTIVE") 0)
(if (setq pt2 (getpoint pt1 "\nPick Next point:"))
(progn
(entmakex
(list
(cons 0 "TEXT")
(cons 10
(Setq p_ (polar
(mapcar '(lambda (x y)
(* 0.5 (+ x y))
)
pt1
pt2
)
(+ (setq ang (angle pt1 pt2)) (/ pi 2.0))
(- 360)
)
)
)
(cons 11 p_)
(cons 40 175)
(Cons 50 ang)
'(72 . 4)
'(73 . 3)

(cons 1
((rtos (/ (distance pt1 pt2) 1000.0) 2 2)
)
)
)
(setq pt1 pt2)
(command pt2)
)
(command "")
)
)
)
)
(princ)
)

0 Likes
Accepted solutions (2)
1,871 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution
(Defun c:BRR (/ pt1 pt2 d p_) ; Text over Polyline
  
  (setvar "cmdecho" 0)
  (if (setq pt1 (getpoint "\nPick the first Point: "))
    (progn
      (command "_Pline" pt1)
      (while (> (getvar "CMDACTIVE") 0)
	(if (setq pt2 (getpoint pt1 "\nPick Next point:"))
	  (progn
	    (entmakex
	      (list
		(cons 0 "TEXT")
		(cons 10
		      (Setq p_ (polar
				 (mapcar '(lambda (x y)
					    (* 0.5 (+ x y))
					    )
					 pt1
					 pt2
					 )
				 (+ (setq ang (angle pt1 pt2)) (/ pi 2.0))
				 (- 360)
				 )
			    )
		      )
		(cons 11 p_)
		(cons 40 175)
		(Cons 50 ang)
		'(72 . 4)
		'(73 . 3)
		
		(cons 1 (strcat (if (< (setq d (distance pt1 pt2)) 1800)
				  "M1 "
				  "")
				(rtos (/ d 1000.0) 2 2)
				"m"))))
	    (setq pt1 pt2)
	    (command "_non" pt2)
	    )
	    (command "")
	    )
	  )
	)
      )
    (princ)
    )
0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

....

1. Add suffix to the text "m"

2. Iff the text number is less than 1.8m it should also add prefix "P1 " otherwise add prefix "M1 "

....

(cons 1
((rtos (/ (distance pt1 pt2) 1000.0) 2 2)
)
....


Try replacing the above excerpt [which has an extraneous ( in it -- is that not causing an error?] with this:

....

(cons 1

  (strcat

    (if (< (distance pt1 pt2) 1800) "P1 " "M1 ")

    (rtos (/ (distance pt1 pt2) 1000) 2 2)

    "m"

  ); strcat

); cons

....

 

[Note that I removed the .0 from the 1000 number.  It doesn't hurt to have it, but it's not necessary here.  People include it out of fear that in a division, if they use an integer the result will be rounded down to an integer, but that happens only when both numbers in the division are integers.  The (distance) function always returns a real number, so there is no risk in this case.  And in a comparison like the  <  function, there really is no difference at all between 1800 and the 1800.0 that some people would be tempted to use.]

Kent Cooper, AIA
Message 4 of 6

Anonymous
Not applicable

Thank you very much. Works like a charm now. It really helps me now to put bracings on plan. M1 is for metal bracings that come in 1.8 to 2.4m plan length and anything below is the plywood bracing P1.

 

Thanks a lot

0 Likes
Message 5 of 6

Anonymous
Not applicable

@ВeekeeCZ Apologies, I have to ask again. Can I have this solved routine edited so that it does not ask for 2nd point but instead ask for the distance which I can type and enter?

0 Likes
Message 6 of 6

ВeekeeCZ
Consultant
Consultant

The code already allows you to do that. You need to set that in mm.

0 Likes