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?
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
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.
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.Originally Posted by john.nason
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") ) ) )
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
What doesn't work about it?Originally Posted by john.nason
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
This is what I saved as rar.lspOriginally Posted by rkmcswain
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
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:
Let's see if that fixes it.Code:(defun c:rar (/ DRAG MYAREA PT1 PT2 PT3 PT4 R0 R135 R180 R225 R270 R315 R45 R90 TIME VEC X XDIM Y YDIM)
FYI: The Visual Lisp editor would have helped you locate the error and compile the list of variables.
Thats wonderful! Thanks man.
John Nason
Architectural Technologist
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