Jump to content

Display the Area by Picking Rectangle


structo

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.

Area Lisp by draw rectangle.jpg

Link to comment
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)
)

 

  • Like 1
Link to comment
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
Link to comment
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.

 

Link to comment
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)
)

 

  • Thanks 1
Link to comment
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 Y (abs (- (cadr p1)(cadr p4))))
(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)
)

 

  • Like 1
Link to comment
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

  • Like 3
Link to comment
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
  (vla-get-display (vla-get-preferences (vlax-get-acad-object)))
  acFontBold ;2 
)

p/s: BCAD
; error : Automation Error E_NOTIMPL; [IAcadPreferencesDisplay] function [TEXTFONTSTYLE] not implemented yet
 

 

 

Edited by hanhphuc
Link to comment
Share on other sites

hi hanhphuc,

 

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

 

 

Link to comment
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
Link to comment
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)))
		  (abs (- (Cadr p1) (Cadr p2)))
	       )
	       2
	       3
	 )
       )
     )
  )
  (princ)
)

 

Link to comment
Share on other sites

2 hours ago, Jonathan Handojo said:

Apologies guys...

GrText Demo 3

 

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

 

Edited by pBe
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...