Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: LISP to calculate area of rectangle

  1. #1
    Member
    Join Date
    2006-06
    Location
    Moncton, NB, CANADA
    Posts
    18

    Default LISP to calculate area of rectangle

    A colleague of mine, came to me requesting a lisp that calculate's the area of a rectangle. He wants to be able to run the routine, start the rectangle, be able to see the area of the rectangle before closing the rectangle.

    Any suggestions?
    John Nason
    Architectural Technologist

  2. #2
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043

    Default Re: LISP to calculate area of rectangle

    I think you will have to use (getpoint.... then use (grread... while you use (getcorner...
    I don't know if that is possible, but that is what came to mind while reading your post.

  3. #3
    Certified AUGI Addict rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Houston
    Posts
    7,520

    Default Re: LISP to calculate area of rectangle

    Quote Originally Posted by john.nason
    A colleague of mine, came to me requesting a lisp that calculate's the area of a rectangle. He wants to be able to run the routine, start the rectangle, be able to see the area of the rectangle before closing the rectangle.

    Any suggestions?
    Try this. You will have to wrap this in a (defun) if desired. While the command is running, the area will be displayed in the status bar.
    Code:
    ; --------------------------------
    (setq r0 0.0
          r45  (* 0.25 pi)
          r90  (* 0.5 pi)
          r135 (* 0.75 pi)
          r180 pi
          r225 (* 1.25 pi)
          r270 (* 1.5 pi)
          r315 (* 1.75 pi)
    )
    (setq pt1 (getpoint "\nSelect first point: ") time T)
    (while time
        (setq drag (grread t 1 1))
        (cond ((= (car drag) 5) ;<- moving cursor
    	   (setq pt2 (cadr drag))
    	   (setq xdim (abs (- (car pt1)(car pt2))))
    	   (setq ydim (abs (- (cadr pt1)(cadr pt2))))	   
    	   (setq myarea (* xdim ydim))
    	   (grtext -1 (strcat "Area = " (rtos myarea)))
    	   (setq vec (angle pt1 pt2))	   
    	   (cond ((and (>= vec 0.0) (< vec r90))
    		  (setq x r0 y r90)
    		 )
    		 ((and (>= vec r90) (< vec r180))
    		  (setq x r180 y r90)
    		 )
    		 ((and (>= vec r180) (< vec r270))
    		  (setq x r180 y r270)
    		 )		 
    		 ((>= vec r270)
    		  (setq x r0 y r270)
    		 )
               )
               (setq pt3 (polar pt1 x xdim) pt4 (polar pt1 y ydim))		    
    	   (redraw)
    	   (grvecs (list 7 pt1 pt3 7 pt3 pt2 7 pt2 pt4 7 pt4 pt1))
    	  )
    	  ((= (car drag) 3) ;<- picked point
    	   (setq time nil)
    	   (command "._pline" pt1 pt3 pt2 pt4 "_C")
    	  )
        )
    )

  4. #4
    Member
    Join Date
    2006-06
    Location
    Moncton, NB, CANADA
    Posts
    18

    Default Re: LISP to calculate area of rectangle

    Thats awesome, thanks. Now I can't get it to work. :S

    I'm just getting into writing Lisps ... and I'm not that dangerous yet.
    John Nason
    Architectural Technologist

  5. #5
    Certified AUGI Addict rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Houston
    Posts
    7,520

    Default Re: LISP to calculate area of rectangle

    Quote Originally Posted by john.nason
    Now I can't get it to work.
    What doesn't work about it?

  6. #6
    Member
    Join Date
    2006-06
    Location
    Moncton, NB, CANADA
    Posts
    18

    Default Re: LISP to calculate area of rectangle

    I put the code into a text file, added the defun d:rar to it, and I get the message below.



    Command: _appload rar.lsp successfully loaded.


    Command: ; error: An error has occurred inside the *error* functionbad
    function: "malformed list on input"
    John Nason
    Architectural Technologist

  7. #7
    Member
    Join Date
    2006-06
    Location
    Moncton, NB, CANADA
    Posts
    18

    Default Re: LISP to calculate area of rectangle

    Quote Originally Posted by rkmcswain
    What doesn't work about it?
    This is what I saved as rar.lsp

    Code:
    (defun c:rar ()
    
     ; --------------------------------
    (setq r0 0.0
          r45  (* 0.25 pi)
          r90  (* 0.5 pi)
          r135 (* 0.75 pi)
          r180 pi
          r225 (* 1.25 pi)
          r270 (* 1.5 pi)
          r315 (* 1.75 pi)
    )
    (setq pt1 (getpoint "\nSelect first point: ") time T)
    (while time
        (setq drag (grread t 1 1))
        (cond ((= (car drag) 5) ;<- moving cursor
    	   (setq pt2 (cadr drag))
    	   (setq xdim (abs (- (car pt1)(car pt2))))
    	   (setq ydim (abs (- (cadr pt1)(cadr pt2))))	   
    	   (setq myarea (* xdim ydim))
    	   (grtext -1 (strcat "Area = " (rtos myarea)))
    	   (setq vec (angle pt1 pt2))	   
    	   (cond ((and (>= vec 0.0) (< vec r90))
    		  (setq x r0 y r90)
    		 )
    		 ((and (>= vec r90) (< vec r180))
    		  (setq x r180 y r90)
    		 )
    		 ((and (>= vec r180) (< vec r270))
    		  (setq x r180 y r270)
    		 )		 
    		 ((>= vec r270)
    		  (setq x r0 y r270)
    		 )
               )
               (setq pt3 (polar pt1 x xdim) pt4 (polar pt1 y ydim))		    
    	   (redraw)
    	   (grvecs (list 7 pt1 pt3 7 pt3 pt2 7 pt2 pt4 7 pt4 pt1))
    	  )
    	  ((= (car drag) 3) ;<- picked point
    	   (setq time nil)
    	   (command "._pline" pt1 pt3 pt2 pt4 "_C")
    	  )
        )
    )
    John Nason
    Architectural Technologist

  8. #8
    Certified AUGI Addict rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Houston
    Posts
    7,520

    Default Re: LISP to calculate area of rectangle

    John,

    You are missing the closing parenthesis at the end of the file.

    You may also want to make all the variables local by changing the defun line to:

    Code:
    (defun c:rar (/ DRAG MYAREA PT1 PT2 PT3 PT4 R0 R135 R180 R225 R270 R315 R45 R90 TIME VEC X XDIM Y YDIM)
    Let's see if that fixes it.

    FYI: The Visual Lisp editor would have helped you locate the error and compile the list of variables.

  9. #9
    Member
    Join Date
    2006-06
    Location
    Moncton, NB, CANADA
    Posts
    18

    Default Re: LISP to calculate area of rectangle

    Thats wonderful! Thanks man.
    John Nason
    Architectural Technologist

  10. #10
    Member
    Join Date
    2006-06
    Location
    Moncton, NB, CANADA
    Posts
    18

    Default Re: LISP to calculate area of rectangle

    Now to add another aspect to it ...

    Can that translate the size of the rectangle as well??

    And what about overiding the units to read back in metres to two decimal places.
    John Nason
    Architectural Technologist

Page 1 of 2 12 LastLast

Similar Threads

  1. Calculate Rentable Area
    By pfaudler in forum Revit - API
    Replies: 1
    Last Post: 2012-04-19, 10:57 PM
  2. Lisp for rectangle
    By RRS1987 in forum AutoLISP
    Replies: 2
    Last Post: 2011-10-24, 02:58 AM
  3. 2011: how to calculate the surface area in revit?
    By leemengsh528058 in forum Revit Architecture - General
    Replies: 1
    Last Post: 2011-09-10, 06:30 PM
  4. Replies: 1
    Last Post: 2009-04-24, 02:18 PM
  5. how does revit calculate the area of walls
    By Max Lloyd in forum Revit Architecture - General
    Replies: 2
    Last Post: 2006-02-13, 04:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •