LISP to add elevation given elevation and number of stairs

LISP to add elevation given elevation and number of stairs

Nathan_Tigner
Advocate Advocate
1,524 Views
11 Replies
Message 1 of 12

LISP to add elevation given elevation and number of stairs

Nathan_Tigner
Advocate
Advocate

I am looking for lisp that will ask the user for an elevation and number of stairs, then return 2 pieces of text.

 

text 1: 

SLAB

FFE=(user input elevation + number of stairs*.067)

 

Text 2:

GARAGE

(number of stairs) STEPS

G=(user input elevation)

 

Obviously the math is easy, I am just trying to save time as this could be done hundreds of times on any given project. It also could prevent potential user error.

 

Thank everyone!

0 Likes
Accepted solutions (4)
1,525 Views
11 Replies
Replies (11)
Message 2 of 12

pbejse
Mentor
Mentor

@Nathan_Tigner wrote:

text 1:  SLAB,  FFE=(user input elevation + number of stairs*.067)

Text 2: GARAGE(number of stairs) STEPS G=(user input elevation)


What is the result for this two input? 

0.60 elevation | 4 number of stairs for SLAB prompt ( is that really stairs or steps?)

0.75 elevation  |  5 number of steps for GARAGE ( is the number of steps is from the the SLAB prompt?

 

0 Likes
Message 3 of 12

Nathan_Tigner
Advocate
Advocate

I think I did a bad job of explaining. The bold would be calculated from the 2 user inputs. Everything else is just text.

 

Text 1:

SLAB

FFE=(ELEVATION + STEPS*.067)

 

Text 2:

GARAGE

STEPS STEPS

G=ELEVATION

 

I am trying to end up with something that looks like this

nathantignerT6ZWV_0-1644678577406.png

 

0 Likes
Message 4 of 12

pbejse
Mentor
Mentor
Accepted solution

@Nathan_Tigner wrote:

I think I did a bad job of explaining. The bold would be calculated from the 2 user inputs. Everything else is just text.

 


Try this demo

(Defun c:demo ( / Elev steps ffe ipnt)
(setq name '("SLAB" "GARAGE"))
  (if (and
	(setq Elev (getdist "\nElevation: "))
	(setq Steps (getint "\nNumber of steps: "))
	(setq ffe ( + Elev (* 0.067 Steps)))
	)

    (foreach itm (list
		   (list (car name)
		       (strcat (car name) "\\PFFE=" (rtos ffe 2 2)))
		   (list (cadr name)
		       (strcat (cadr name)"\\P" (itoa steps) " STEP\\PG=" (rtos Elev 2 2)))
		   )
      
      (if (setq ipnt (getpoint (strcat "\nPick text insertion point for " (Car itm))))
	(entmakex
	      (list
	        (cons 0 "MTEXT")
		(cons 100 "AcDbEntity")
	        (cons 100 "AcDbMText")
	        (cons 10 ipnt)
		'(71 . 2) 
		'(72 . 5) 
	        (cons 1 (cadr itm))
	              
	        )
	      )
	    )
      )
    )
(princ)
)

 Command: DEMO

Elevation: 749.08

Number of steps: 1

Pick text insertion point for SLAB
Pick text insertion point for GARAGE

 

HTH

 

0 Likes
Message 5 of 12

hak_vz
Advisor
Advisor
Accepted solution

Try this

 

 

 

(defun c:steps (/ tpe elevation steps ffe pt str st_str)
	(initget 1 "SLAB GARAGE")
	(setq tpe (strcase(getkword "\nslab or garage >")))
	(cond 
		((= tpe "SLAB")
		    (prompt "\n___SLAB___")
			(initget (+ 1 2 4))
			(setq elevation (getreal "\nElevation >"))
			(initget (+ 1 2 4))
			(setq steps (getint "\nNumber of steps >"))
			(setq ffe (rtos(+ elevation (* 0.67 steps))2 2))
			(setq pt (getpoint "\nPick text location"))
			(setq str (strcat "SLAB" "\\P" "FFE = " ffe))
		)
		((= tpe "GARAGE")
			(prompt "\n___GARAGE___")
			(initget (+ 1 2 4))
			(setq elevation (getreal "\nElevation >"))
			(initget (+ 1 2 4))
			(setq steps (getint "\nNumber of steps >"))
			(if (= steps 1) (setq st_str " STEP")(setq st_str " STEPS"))
			(setq pt (getpoint "\nPick text location"))
			(setq str (strcat "GARAGE" "\\P" (itoa steps) st_str "\\P" "G = " (rtos elevation 2 2)))
		)
	)
	(cond 
		((and pt)
			(entmakex
				(list
					(cons 0 "MTEXT")	
					(cons 100 "AcDbEntity")
					(cons 100 "AcDbMText")
					(cons 1 str)
					(cons 10 pt)
					(cons 40 (getvar 'textsize))
					(cons 41 0.0)
					(cons 50 0.0)
					(cons 71 5)
					(cons 72 1)
				)
			)
			)
	)
	(princ)
)

 

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 6 of 12

Nathan_Tigner
Advocate
Advocate

This works perfectly. I did have one question. On some projects I might need a second line in the first text. It would look like:

 

SLAB

FFE=701.34

FND=701.34

 

The FND number would be exactly the same as the FFE, So how would I change the lisp so that it would add both FFE and FND?

 

Thank you so much for the help! 

0 Likes
Message 7 of 12

pbejse
Mentor
Mentor
Accepted solution

@Nathan_Tigner wrote:

The FND number would be exactly the same as the FFE, So how would I change the lisp so that it would add both FFE and FND?

Here you go

(Defun c:demo ( / Elev steps ffe ipnt)
(setq name '("SLAB" "GARAGE"))
(initget 1 "Y N")
  (if (and
	(setq Fnd (getkword "\nInclude FND on Text[Yes/No]: "))
	(setq Elev (getdist "\nElevation: "))
	(setq Steps (getint "\nNumber of steps: "))
	(setq ffe ( + Elev (* 0.067 Steps)))
	)
    (foreach itm (list
		   (list (car name)
		       (strcat (car name) "\\PFFE=" (rtos ffe 2 2)
			       (if (eq Fnd "Y") (strcat "\\PFND=" (rtos ffe 2 2) ) "")))
		   (list (cadr name)
		       (strcat (cadr name)"\\P" (itoa steps) " STEP\\PG=" (rtos Elev 2 2)))
		   )
      
      (if (setq ipnt (getpoint (strcat "\nPick text insertion point for " (Car itm))))
	(entmakex
	      (list
	        (cons 0 "MTEXT")
		(cons 100 "AcDbEntity")
	        (cons 100 "AcDbMText")
	        (cons 10 ipnt)
		'(71 . 2) 
		'(72 . 5) 
	        (cons 1 (cadr itm))
	              
	        )
	      )
	    )
      )
    )
(princ)
)

Command: DEMO
Include FND on Text[Yes/No]: N
Elevation: 12.35
Number of steps: 2
Pick text insertion point for SLAB
Pick text insertion point for GARAGE

 

Command: DEMO
Include FND on Text[Yes/No]: Y
Elevation: 23.56
Number of steps: 4
Pick text insertion point for SLAB
Pick text insertion point for GARAGE

0 Likes
Message 8 of 12

hak_vz
Advisor
Advisor
Accepted solution

@Nathan_Tigner wrote:

SLAB

FFE=701.34

FND=701.34


 

Here is modified code for that case. It also takes into account using users coordinate system. Text location is picked so that cursor location represent upper left corner of MTEXT object .

(defun c:steps (/ tpe elevation steps ffe  str st_str a b pt pt2)
	(initget 1 "SLAB GARAGE")
	(setq tpe (strcase(getkword "\nslab or garage >")))
	(cond 
		((= tpe "SLAB")
		    (prompt "\n___SLAB___")
			(initget (+ 1 2 4))
			(setq elevation (getreal "\nElevation >"))
			(initget (+ 1 2 4))
			(setq steps (getint "\nNumber of steps >"))
			(setq ffe (rtos(+ elevation (* 0.67 steps))2 2))
			(initget "Yes No")
			(setq fnd(getkword "\nAdd FND (Yes No) >"))
			(setq pt (getpoint "\nPick text location"))
			(if (= fnd "Yes")
				(setq str (strcat "SLAB" "\\P" "FFE = " ffe "\\P" "FND = " ffe))
				(setq str (strcat "SLAB" "\\P" "FFE = " ffe))
			
			)
			
		)
		((= tpe "GARAGE")
			(prompt "\n___GARAGE___")
			(initget (+ 1 2 4))
			(setq elevation (getreal "\nElevation >"))
			(initget (+ 1 2 4))
			(setq steps (getint "\nNumber of steps >"))
			(if (= steps 1) (setq st_str " STEP")(setq st_str " STEPS"))
			(setq pt (getpoint "\nPick upper left text corner >"))
			(setq str (strcat "GARAGE" "\\P" (itoa steps) st_str "\\P" "G = " (rtos elevation 2 2)))
		)
	)
	(cond 
		((and pt)
			(vlax-invoke-method 
				(vlax-ename->vla-object
					(entmakex
						(list
							(cons 0 "MTEXT")	
							(cons 100 "AcDbEntity")
							(cons 100 "AcDbMText")
							(cons 1 str)
							(cons 10 (trans pt 1 2))
							(cons 40 (getvar 'textsize))
							(cons 41 0.0)
							(cons 50 0.0)
							(cons 71 5)
							(cons 72 1)
						)
					)
				)
				'getboundingbox 'a 'b
			)
			(setq
				a (vlax-safearray->list a)
				b (vlax-safearray->list b)
				d(mapcar '* (mapcar '- b a) '(0.5 -0.5))
			)
			(command "_.move" (entlast) "" "_non" (trans '(0 0) 1 2) "_non" (trans d 1 2))
		)
	)
	(princ)
)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 9 of 12

Nathan_Tigner
Advocate
Advocate

You guys rock. Thanks so much for helping me out. Now I just need to figure out how to specify text style and layer.

0 Likes
Message 10 of 12

hak_vz
Advisor
Advisor

@Nathan_Tigner wrote:

You guys rock. Thanks so much for helping me out. Now I just need to figure out how to specify text style and layer.


			(entmakex
				(list
					(cons 0 "MTEXT")	
					(cons 100 "AcDbEntity")
					(cons 100 "AcDbMText")
					(cons 1 str)
					(cons 7 "TEXT STYLE")
					(cons 8 "LAYER NAME")
					(cons 10 pt)
					(cons 40 (getvar 'textsize))
					(cons 41 0.0)
					(cons 50 0.0)
					(cons 71 5)
					(cons 72 1)
				)
			)

@Nathan_Tigner 

To add layer name and text add i.e change this two lines in my code

(cons 7 "TEXT STYLE")
(cons 8 "LAYER NAME")

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 11 of 12

Nathan_Tigner
Advocate
Advocate

Worked perfectly. I was trying to get it to prompt the user for a rotation for the mtext, but I could only get it to work with a static rotation using (cont 50).

0 Likes
Message 12 of 12

hak_vz
Advisor
Advisor

@Nathan_Tigner 

Check this. Change layer and text style.

(defun c:steps (/ deg_to_rad rotation tpe elevation steps ffe  str st_str a b pt pt2)
	(defun deg_to_rad (deg)(* pi (/ deg 180.0)))
	(initget 1 "SLAB GARAGE")
	(setq tpe (strcase(getkword "\nslab or garage >")))
	(cond 
		((= tpe "SLAB")
		    (prompt "\n___SLAB___")
			(initget (+ 1 2 4))
			(setq elevation (getreal "\nElevation >"))
			(initget (+ 1 2 4))
			(setq steps (getint "\nNumber of steps >"))
			(setq ffe (rtos(+ elevation (* 0.67 steps))2 2))
			(initget "Yes No")
			(setq fnd(getkword "\nAdd FND (Yes No) >"))
			(setq pt (getpoint "\nPick text location"))
			(if (= fnd "Yes")
				(setq str (strcat "SLAB" "\\P" "FFE = " ffe "\\P" "FND = " ffe))
				(setq str (strcat "SLAB" "\\P" "FFE = " ffe))
			
			)
			(setq rotation (getreal "\nEnter mtext rotation deg <def = 0> >>"))
			(if (null rotation)(setq rotation 0))
			
		)
		((= tpe "GARAGE")
			(prompt "\n___GARAGE___")
			(initget (+ 1 2 4))
			(setq elevation (getreal "\nElevation >"))
			(initget (+ 1 2 4))
			(setq steps (getint "\nNumber of steps >"))
			(if (= steps 1) (setq st_str " STEP")(setq st_str " STEPS"))
			(setq pt (getpoint "\nPick upper left text corner >"))
			(setq str (strcat "GARAGE" "\\P" (itoa steps) st_str "\\P" "G = " (rtos elevation 2 2)))
			(setq rotation (getreal "\nEnter mtext rotation deg <def = 0> >>"))
			(if (null rotation)(setq rotation 0))
		)
	)
	(cond 
		((and pt)
			(vlax-invoke-method 
				(vlax-ename->vla-object
					(entmakex
						(list
							(cons 0 "MTEXT")	
							(cons 100 "AcDbEntity")
							(cons 100 "AcDbMText")
							(cons 1 str)
							(cons 10 (trans pt 1 2))
							(cons 40 (getvar 'textsize))
							(cons 7 "STANDARD")
							(cons 8 "LAYER NAME")
							(cons 41 0.0)
							(cons 50 (deg_to_rad rotation))
							(cons 71 1)
							(cons 72 1)
						)
					)
				)
				'getboundingbox 'a 'b
			)
			(setq
				a (vlax-safearray->list a)
				b (vlax-safearray->list b)
				d(mapcar '* (mapcar '- b a) '(0.5 -0.5))
			)
			(setq ent (entget(entlast)))
			(setq ent(subst (cons 71 5)(assoc 71 ent) ent))
			(entmod ent)
		)
	)
	(princ)
)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes