Hi all!
sime time ago i found a lisp in the net to create a rectangle by marking objects in a draw.
Very usefull every day!
But it would nice to get at the end of the lisp after creating the rectangle a output in the commandline about the length and with of the created rectangle.
someone here who can add the code for the lenght/width output?
many thanks!
(defun C:wer (/ AUSWAHL INDEX ELEM XYMIN XYMAX MINX MAXX MINY MAXY DATA A) (vl-load-com) (if(and(or (and (setq AUSWAHL (ssget "I")) (> (sslength AUSWAHL) 0)) (and (setq AUSWAHL (ssget)) (> (sslength AUSWAHL) 0)) ) (or(setq A (getreal "\nRandabstand <0> : ")) (setq A 0.0) ) ) (progn (setq INDEX -1) (repeat (sslength AUSWAHL) (vla-getboundingbox (vlax-ename->vla-object (ssname AUSWAHL (setq INDEX (1+ INDEX))) ) 'XYMIN 'XYMAX ) (setq DATA (cons (list (vlax-safearray->list XYMIN) (vlax-safearray->list XYMAX) ) DATA ) ) ) (setq MINX (-(eval (cons 'min (mapcar 'caar DATA)))A)) (setq MINY (-(eval (cons 'min (mapcar 'cadar DATA)))A)) (setq MAXX (+(eval (cons 'max (mapcar 'caadr DATA)))A)) (setq MAXY (+(eval (cons 'max (mapcar 'cadadr DATA)))A)) (vla-AddLightweightPolyline (if(=(vla-get-activespace(vla-get-activedocument(vlax-get-acad-object))) acModelSpace ) (vla-get-modelspace(vla-get-activedocument(vlax-get-acad-object))) (vla-get-paperspace(vla-get-activedocument(vlax-get-acad-object))) ) (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 9)) (list MINX MINY MAXX MINY MAXX MAXY MINX MAXY MINX MINY ) ) ) ) ) (princ) )
don´t now the autor of the lisp, can´t remember.
all creatits for sure to the autor!
MANY THANKS
regards
Ingo
Try with this code
(defun C:wer (/ AUSWAHL INDEX ELEM XYMIN XYMAX MINX MAXX MINY MAXY DATA A) (vl-load-com) (if(and(or (and (setq AUSWAHL (ssget "I")) (> (sslength AUSWAHL) 0)) (and (setq AUSWAHL (ssget)) (> (sslength AUSWAHL) 0)) ) (or(setq A (getreal "\nRandabstand <0> : ")) (setq A 0.0) ) ) (progn (setq INDEX -1) (repeat (sslength AUSWAHL) (vla-getboundingbox (vlax-ename->vla-object (ssname AUSWAHL (setq INDEX (1+ INDEX))) ) 'XYMIN 'XYMAX ) (setq DATA (cons (list (vlax-safearray->list XYMIN) (vlax-safearray->list XYMAX) ) DATA ) ) ) (setq MINX (-(eval (cons 'min (mapcar 'caar DATA)))A)) (setq MINY (-(eval (cons 'min (mapcar 'cadar DATA)))A)) (setq MAXX (+(eval (cons 'max (mapcar 'caadr DATA)))A)) (setq MAXY (+(eval (cons 'max (mapcar 'cadadr DATA)))A)) (vla-AddLightweightPolyline (if(=(vla-get-activespace(vla-get-activedocument(vlax-get-acad-object))) acModelSpace ) (vla-get-modelspace(vla-get-activedocument(vlax-get-acad-object))) (vla-get-paperspace(vla-get-activedocument(vlax-get-acad-object))) ) (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 9)) (list MINX MINY MAXX MINY MAXX MAXY MINX MAXY MINX MINY ) ) ) ) ) (print (strcat "Length is " (rtos ( - MAXX MINX)))) (print (strcat "Width is " (rtos ( - MAXY MINY))))
(print (strcat "Rectangle of " (rtos ( - MAXX MINX))"[Length]" " X " (rtos ( - MAXY MINY))"[Width]" " Created")) (princ) )
PERFECT!
i use it now with this code...
THANKS for quick help!
(defun C:wer (/ AUSWAHL INDEX ELEM XYMIN XYMAX MINX MAXX MINY MAXY DATA A) (vl-load-com) (if(and(or (and (setq AUSWAHL (ssget "I")) (> (sslength AUSWAHL) 0)) (and (setq AUSWAHL (ssget)) (> (sslength AUSWAHL) 0)) ) (or(setq A (getreal "\nRandabstand <0> : ")) (setq A 0.0) ) ) (progn (setq INDEX -1) (repeat (sslength AUSWAHL) (vla-getboundingbox (vlax-ename->vla-object (ssname AUSWAHL (setq INDEX (1+ INDEX))) ) 'XYMIN 'XYMAX ) (setq DATA (cons (list (vlax-safearray->list XYMIN) (vlax-safearray->list XYMAX) ) DATA ) ) ) (setq MINX (-(eval (cons 'min (mapcar 'caar DATA)))A)) (setq MINY (-(eval (cons 'min (mapcar 'cadar DATA)))A)) (setq MAXX (+(eval (cons 'max (mapcar 'caadr DATA)))A)) (setq MAXY (+(eval (cons 'max (mapcar 'cadadr DATA)))A)) (vla-AddLightweightPolyline (if(=(vla-get-activespace(vla-get-activedocument(vlax-get-acad-object))) acModelSpace ) (vla-get-modelspace(vla-get-activedocument(vlax-get-acad-object))) (vla-get-paperspace(vla-get-activedocument(vlax-get-acad-object))) ) (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 9)) (list MINX MINY MAXX MINY MAXX MAXY MINX MAXY MINX MINY ) ) ) ) ) (print (strcat (rtos ( - MAXX MINX)) " / " (rtos ( - MAXY MINY)) )) (princ) )
Here is another way to write it:
(defun c:wer ( / a b s ) (if (and (setq s (ssget)) (setq b (LM:ssboundingbox s)) ) (progn (initget 4) (setq a (cond ((getdist "\nRandabstand <0.0>: ")) (0.0))) (entmake (append '( (000 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") (090 . 4) (070 . 1) ) (mapcar '(lambda ( w x ) (cons 10 (mapcar '(lambda ( y z ) ((eval z) ((eval y) b) a)) w x)) ) '( (caar cadar) (caadr cadar) (caadr cadadr) (caar cadadr) ) '( (- -) (+ -) (+ +) (- +) ) ) ) ) (princ (strcat "\n" (rtos (+ a a (- (caadr b) (caar b)))) " / " (rtos (+ a a (- (cadadr b) (cadar b)))) ) ) ) ) (princ) ) ;; Selection Set Bounding Box - Lee Mac ;; Returns a list of the lower-left and upper-right WCS coordinates of a ;; rectangular frame bounding all objects in a supplied selection set. ;; s - [sel] Selection set for which to return bounding box (defun LM:ssboundingbox ( s / a b i m n o ) (repeat (setq i (sslength s)) (if (and (setq o (vlax-ename->vla-object (ssname s (setq i (1- i))))) (vlax-method-applicable-p o 'getboundingbox) (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list o 'a 'b)))) ) (setq m (cons (vlax-safearray->list a) m) n (cons (vlax-safearray->list b) n) ) ) ) (if (and m n) (mapcar '(lambda ( a b ) (apply 'mapcar (cons a b))) '(min max) (list m n)) ) ) (vl-load-com) (princ)
The above uses my Selection Set Bounding Box function.
Lee
@gringooo wrote:
.... it would nice to get at the end of the lisp after creating the rectangle a output in the commandline about the length and with of the created rectangle.
....
It doesn't look as though that routine would ever draw a non-orthogonal rectangle, but for anyone needing the dimensions of such a thing, this would report the size [in current drawing units] of a rectangle drawn at any angle and in any Coordinate System:
(vl-load-com); if needed
(prompt
(strcat
"\nRectangle is "
(rtos (distance (vlax-curve-getStartPoint (entlast)) (vlax-curve-getPointAtParam (entlast) 1)))
" x "
(rtos (distance (vlax-curve-getPointAtParam (entlast) 1) (vlax-curve-getPointAtParam (entlast) 2)))
"."
); strcat
); prompt
(princ)
gringooo wrote:
hi lee_mac,
nice to see you again. you write the code new just for fun. cool. works also perfekt! witch one makes a better job or is smoother for daily use?
Thank you gringooo
My code will be slightly more efficient due to the use of separate lists for the lower-left & upper-right coordinates of the bounding box, and also because entmake is faster for entity generation than the equivalent ActiveX methods or in-built commands.
My version also includes error trapping to account for objects which either do not support the getboundingbox method or return an error when the method is applied (as is the case with some objects found in the Autodesk Vertical applications).
Lee