# Display the Area by Picking Rectangle

## Recommended Posts

Hi All..

I need lisp routine by Clicking Two Diagonal corners like Rectangle, After finished picking need to display that rectangle area result at Command line. and disappear the drawn rectangle.

Procedure for executing lisp is 1. Pick point 1
2.Pick at Final corner point 2
3. And Displays the Rectangle area result at Command line & Disappear drawn the rectangle.

Kindly help me. i have to check the areas between different points.

##### Share on other sites

Area on the fly.

```(defun c:aof (/ 1p 2p)
;; aof =  Area on the fly.	;;
(and (setq 1p (getpoint "\nSpecify base point : "))
(setq 2p (getcorner "\nOpposite point : " 1p))
(princ (* (distance 1p (list (car 2p) (cadr 1p))) (distance 2p (list (car 2p) (cadr 1p))))
)
)
(princ)
)```

##### Share on other sites
13 hours ago, Tharwat said:

Quote

Thank you very much, As said it is Area on fly   Is it Possible?  same Area result at command  line can we see also  length =   , Width =

Edited by structo
##### Share on other sites

Here is another version posted over at AUGI. Look at Tharwat code and have a go.

Can get the 4 points of the rectang then use Tharwat code and modify the Alert shown here.

```(defun c:2ptarea ( / obj )
(command "rectang" (getpoint "pick p1 then drag") pause)
(setq obj (vlax-ename->vla-object (entlast)))
(alert (strcat "area is " (rtos (vla-get-area obj))))
(command "erase" "l" "")
(princ)
)```
```(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast)))))
(setq
p1 (nth 0 co-ord)
p2 (nth 1 co-ord)
p3 (nth 2 co-ord)
p4 (nth 3 co-ord)
)```

Ps have a go 1st, I have it solved and happy to compare.

##### Share on other sites
```(defun c:aof (/ 1p 2p wd ht)
;; aof =  Area on the fly.	;;
(and (setq 1p (getpoint "\nSpecify base point : "))
(setq 2p (getcorner "\nOpposite point : " 1p))
(setq wd (distance 1p (list (car 2p) (cadr 1p)))
ht (distance 2p (list (car 2p) (cadr 1p)))
)
(princ (strcat "\nWidth = " (rtos wd 2 4) " Height = " (rtos ht 2 4) " Area = " (rtos (* wd ht) 2 4)
)
)
)
(princ)
)```

##### Share on other sites

It is awesome, Thank you Tharwat

##### Share on other sites
1 hour ago, structo said:

It is awesome, Thank you Tharwat

You're welcome anytime.

##### Share on other sites

With visual drag box.

```(defun c:2ptarea ( / co-ord x y )
(command "rectang" (getpoint "pick p1 then drag") pause)
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast)))))
(setq
p1 (nth 0 co-ord)
p2 (nth 1 co-ord)
p3 (nth 2 co-ord)
p4 (nth 3 co-ord)
)
(setq x (abs(- (car p1)(car p2))))
(setq parea (* x y))
(alert (strcat "area is " (rtos parea 2 2)  " Length is " (rtos X 2 2)  " Height is " (rtos Y 2 2)))
(command "erase" "l" "")
(princ)
)```

##### Share on other sites

another, delta

```(defun c:tt (/ p1 p2 en obj )
(and
(setq p1 (getpoint "Specify point "))
(setq p2 (getcorner p1 "opposite corner "))
(setq en (entmakex (list '(0 . "LINE") (cons 10 p1) (cons 11 p2))))
(setq obj (vlax-ename->vla-object en))
(princ
(strcat
"\nArea="
(rtos
(apply '*
(mapcar
'(lambda (a b) (+ a (abs b)))
'(0 0) (vlax-get obj 'delta)
)
)
2
3
)
" M\U+00B2"
)
)
(entdel en)
)
(princ)
)```

WCS

##### Share on other sites

Nice idea  " M\U+00B2"

##### Share on other sites

Nice hanhphuc & BIGAL..

How to see the result in Bold font style?

##### Share on other sites
14 hours ago, structo said:

Nice hanhphuc & BIGAL..

How to see the result in Bold font style?

Font style in command line?

0 acFontRegular

1 acFontItalic

2 acFontBold

3 acFontBoldItalic

```(vla-put-textfontstyle
acFontBold ;2
)```

; error : Automation Error E_NOTIMPL; [IAcadPreferencesDisplay] function [TEXTFONTSTYLE] not implemented yet

Edited by hanhphuc
##### Share on other sites

Structo the idea behind using Alert rather than  princ is that it pops up in front of you no need to look down on command line.

##### Share on other sites

hi hanhphuc,

I dont want Entire command line in bold style, after executing lisp, result should be in bold style.

##### Share on other sites
8 hours ago, structo said:

hi hanhphuc,

I dont want Entire command line in bold style, after executing lisp, result should be in bold style.

Is not a good practice. alert as BIGAL easier

```(defun c:tt ()

;;<snippet>

;;acFontBold <-- refer to previous snippet
(getstring "\nEnter to continue.. ")
;;acFontRegular

(princ)
)```

i prefer

```
( grtext -1 "AREA= xxx " )

```

Edited by hanhphuc
##### Share on other sites
```(Defun c:Demo (/ p1 p2)
(if
(and
(setq p1 (getpoint "Specify point "))
(setq p2 (getcorner p1 "opposite corner "))
)
(princ
(strcat
"\nArea="
(rtos (* (abs (- (Car p1) (Car p2)))
)
2
3
)
)
)
)
(princ)
)```

##### Share on other sites

Pbe its posted elsewhere as well, and in other post wants Area, Length & Height. Think it was forums/Autodesk.

##### Share on other sites

Apologies guys...

##### Share on other sites
2 hours ago, Jonathan Handojo said:

Apologies guys...

I knew from the start that this discussion will inevitably leads to that link you posted.

Edited by pBe
##### Share on other sites
2 hours ago, pBe said:

I knew from the start that this discussion will inevitably leads to that link you posted.

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

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.