Room Area Calculate

Room Area Calculate

k005
Advisor Advisor
1,776 Views
21 Replies
Message 1 of 22

Room Area Calculate

k005
Advisor
Advisor

Hello friends

 

How can I print the actual area of the room in the middle of these two points by selecting the points P1 and P2?

 

unit : cm

 

room area : m²..

0 Likes
Accepted solutions (1)
1,777 Views
21 Replies
Replies (21)
Message 2 of 22

hak_vz
Advisor
Advisor

Try this.

 

(defun c:rarea ( / *error* p1 p2 dx dy str)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
	)
	(while 
		(and
			(setq p1 (getpoint "\nFirst point >"))
			(setq p2 (getpoint "\nSecond point >"))
		)
		(setq dx (apply '- (vl-sort (mapcar 'car (list p1 p2)) '>)))
		(setq dy (apply '- (vl-sort (mapcar 'cadr (list p1 p2)) '>)))
		(setq str (rtos (* dx dy 0.0001) 2 2))
		(cond 
			((not (vl-string-position (ascii ".") str))
				(setq str (strcat str ".00"))
			)
			((= (-(strlen str)(vl-string-position (ascii ".") str)) 2)
				(setq str (strcat str "0"))
			)
		)
		(entmakex
			(list
				'(0 . "TEXT")
				(cons 10 (mapcar '* (mapcar '+ p1 p2) (list 0.5 0.5)))
				(cons 50 0)
				(cons 1 (strcat str " m\U+00B2"))
			)
		)
		
	)
	(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.
Message 3 of 22

Sea-Haven
Mentor
Mentor

This is an excellent Learn lisp. 1st area=(x1-x2)*(y1-y2), mid point can be calculated as (x1 +x2)/2 (y1+y2)/2 

 

So start with (setq pt1 (getpoint "\nmessage "))

then look at what (car pt1) & (cadr pt1 ) reveal

 

The only way to learn is have a go. 

Message 4 of 22

k005
Advisor
Advisor

@hak_vz 

 

 

I don't understand the usage?

 

I'm just trying to reach the Real Field from point P1 and P2.

 

Your code runs in a continuous loop. Or I couldn't.

0 Likes
Message 5 of 22

hak_vz
Advisor
Advisor

@k005 wrote:

@hak_vz 

 

I don't understand the usage?

I'm just trying to reach the Real Field from point P1 and P2.

Your code runs in a continuous loop. Or I couldn't.


Code works in continuous loop. Pick two points along room diagonal and it creates area text at middle point of this two points. Y

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.
Message 6 of 22

Kent1Cooper
Consultant
Consultant

@k005 wrote:
Kent1Cooper_0-1627900385656.png.

So it appears you want the clouded upper-right corner bump-out deducted from the plain-rectangle area [which gives 4.6875 m², as compared to the full-rectangle a x b = 4.7025 m²].  That is not going to be possible if what you want is to pick P1 and P2 only.  You will need something more, such as to use the AREA command and have a routine take the result and put it into Text, or to have a door-opening header Line, turn off the doors' Layer, and use BOUNDARY or BPOLY to make a Polyline that's the actual shape of the room, and use its area.

Kent Cooper, AIA
Message 7 of 22

hak_vz
Advisor
Advisor

@k005 

Here is another version that asks to select text to modify

(defun c:rarea ( / *error* p1 p2 dx dy str)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
	)
	(while 
		(and
			(setq p1 (getpoint "\nFirst point >"))
			(setq p2 (getpoint "\nSecond point >"))
			(setq e (car (entsel "\nSelect text to assign area >")))
		)
		(setq dx (apply '- (vl-sort (mapcar 'car (list p1 p2)) '>)))
		(setq dy (apply '- (vl-sort (mapcar 'cadr (list p1 p2)) '>)))
		(setq str (rtos (* dx dy 0.0001) 2 2))
		(cond 
			((not (vl-string-position (ascii ".") str))
				(setq str (strcat str ".00"))
			)
			((= (-(strlen str)(vl-string-position (ascii ".") str)) 2)
				(setq str (strcat str "0"))
			)
		)
		
		(setq ent (entget e))
		(setq ent(subst (cons 1 (strcat str " m\U+00B2")) (assoc 1 ent) ent))
		(entmod ent)
	)
	(princ)
)

 

Also, read @Kent1Cooper post for non rectangular areas. In that case you have to create a polyline along inner edge of the room and take its area. Search older posts to this forum and you'll probably find code that works in that way and avoids doors and other obstacles. 

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.
Message 8 of 22

k005
Advisor
Advisor

@Kent1Cooper 

 

Yes . I want that part dropped.

 

* Now in this example that area is small... but not always this area is small.

0 Likes
Message 9 of 22

k005
Advisor
Advisor

@hak_vz 

 

I have tested...

 

My friend ;

I guess I couldn't explain the subject fully.. The cloudy part will be deducted. And I said can we do this from two points?

* Except for rectangular or square areas, I will make two calculations...

0 Likes
Message 10 of 22

Kent1Cooper
Consultant
Consultant

@k005 wrote:

 

.... The cloudy part will be deducted. And I said can we do this from two points? ....


If you draw a header line across the door opening, and turn off the Door Layer, a routine could then use the point halfway between the two picked points in a BOUNDARY command, and take the area of the resulting Polyline.

Kent Cooper, AIA
0 Likes
Message 11 of 22

k005
Advisor
Advisor

@Kent1Cooper 

 

Can we only proceed from P1 and P2?

0 Likes
Message 12 of 22

Kent1Cooper
Consultant
Consultant

@k005 wrote:

Can we only proceed from P1 and P2?


How could a routine possibly know about the cut-out corner from only those points?

Kent Cooper, AIA
Message 13 of 22

k005
Advisor
Advisor

@Kent1Cooper 

 

I have a suggestion:

*Area of triangle consisting of P1 and P2 *2 = Unfallen Area.

From this point on, it seemed to me that we could find the point that I did not give another name and calculate it... I am not sure...

 

1. Will the space be deducted ( Yes/No)
2. P1 and P2
3. Result text in the middle of P1/P2. ( text height : Textsize )

0 Likes
Message 14 of 22

Kent1Cooper
Consultant
Consultant

If the room and the cut-out corner are always orthogonal, it might be possible to get a routine to calculate the area and the cut-out reduction with just one additional point:

Kent1Cooper_0-1627909110656.png

But would there ever be further complications, such as more than one cut-out corner?

 

Kent Cooper, AIA
Message 15 of 22

k005
Advisor
Advisor

@Kent1Cooper 

 

@Kent1Cooper But would there ever be further complications, such as more than one cut-out corner?

 

Yes, maybe. But it's okay. We can go to the conclusion with P1 P2 P3.

0 Likes
Message 16 of 22

hak_vz
Advisor
Advisor

Try this version that edits predefined text. You have scenario with selection of three points. In case there is no cut-out select p2 and p3 at same point.

 

(defun c:rarea ( / *error* p1 p2 dx dy dxx dyy str)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
	)
	(while 
		(and
			(setq p1 (getpoint "\nFirst point >"))
			(setq p2 (getpoint "\nSecond point >"))
			(setq p3 (getpoint "\nThird point >"))
			(setq e (car (entsel "\nSelect text to assign area >")))
		)
		(setq dx (apply '- (vl-sort (mapcar 'car (list p1 p2)) '>)))
		(setq dy (apply '- (vl-sort (mapcar 'cadr (list p1 p2)) '>)))
		(setq dxx (apply '- (vl-sort (mapcar 'car (list p2 p3)) '>)))
		(setq dyy (apply '- (vl-sort (mapcar 'cadr (list p2 p3)) '>)))

		(setq str (rtos (* (-(* dx dy) (* dxx dyy)) 0.0001) 2 2))
		(cond 
			((not (vl-string-position (ascii ".") str))
				(setq str (strcat str ".00"))
			)
			((= (-(strlen str)(vl-string-position (ascii ".") str)) 2)
				(setq str (strcat str "0"))
			)
		)
		
		(setq ent (entget e))
		(setq ent(subst (cons 1 (strcat str " m\U+00B2")) (assoc 1 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.
Message 17 of 22

k005
Advisor
Advisor

@hak_vz 

 

 

 

I have tested in the example attached drawing.

but the result is 4.47 m². requested 4.69 m²

0 Likes
Message 18 of 22

hak_vz
Advisor
Advisor
Accepted solution

I receive 4.69.  You should pick points along same diagonal. P1 and p2 are outer ones, and P3 at cut-off. If you pick points as you presented in your sample then result is 4.47. So for correct result take diagonal that passes through cut- off.

Untitled.png

 

 

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.
Message 19 of 22

Kent1Cooper
Consultant
Consultant

@k005 wrote:

.... We can go to the conclusion with P1 P2 P3.


 

(defun C:ACCT (/ P1 P2 P3 areafull areacorner area); = Area with Corner Cutout Text
  (setvar 'dimzin 0); don't suppress trailing zeroes
  (setq
    P1 (getpoint "\nFirst overall corner: ")
    P2 (getpoint P1 "nOpposite overall corner: ")
    P3 (getpoint "\nCut-out internal corner: ")
    areafull (mapcar 'abs (mapcar '- P2 P1))
    areacorner (mapcar 'min (mapcar 'abs (mapcar '- P3 P1)) (mapcar 'abs (mapcar '- P3 P2)))
    area (- (* (car areafull) (cadr areafull)) (* (car areacorner) (cadr areacorner)))
  ); setq
  (command "_.text"
    "_mc" (mapcar '/ (mapcar '+ P1 P2) '(2 2 2))
    "" "" (strcat (rtos (/ area 10000) 2 2) " m²")
  ); command
  (princ)
); defun

If you have the virtual corner inside the column at the cut-out corner to Osnap to, you can use it and the opposite corner, or the other two corners [the ones labeled P1 & P2] -- either combination works, and if that hidden corner isn't there, you can snap to it with APParent-intersection snap.

If there's no cutout, you can pick P3 anywhere on any edge of the rectangular room perimeter.

And it doesn't require Text already there to edit, but puts it in for you [in the current Style on the current Layer].

 

Kent Cooper, AIA
Message 20 of 22

k005
Advisor
Advisor

@hak_vz 

 

Thank you very much, it's ok. 🤗

0 Likes