需要有关边界框Mo的帮助
我现在有一个非常基本的LISP例程。它是为了在一张12x9的图纸上居中放置一组对象而写的(有些人不在乎他们的图纸是否居中……讨厌)。。简而言之,它会提示用户使用SSGET选择对象。然后要求用户提供2个点,可以是包含对象组最外层界限的任何两个相对点。在建立SSGET和2个点后,我会根据2个点的中心将组移动到12x9图纸的中心。
我们绘制等距图,因此命令捕捉“I”和“S”。我让它按标准对齐,因此初学者可以快速将光标移动到任何给定组的范围。。见下面的代码
(DEFUN C:CEN (/ *ERROR* oldsnap oldos)
(defun *error* (msg)
(if oldos (setvar "osmode" oldos))
(if oldsnap (setvar "snapmode" oldsnap))
(if msg (prompt msg))
(princ)
)
(setvar "cmdecho" 0)
(setq oldsnap (getvar "snapmode")
(setq oldos (getvar "osmode"))
(princ "\nSelect Object(s) to CENTER within the titleblock. ")
(SETQ CENT3R (SSGET ))
(command "snap" "s" "s" "")
(setvar "snapmode" 0)
(SETQ P1 (GETpoint "\nFirst corner of rectangle: "))
(setvar "osmode" 0)
(setq p2 (getCORNER P1 "\nSecond corner of rectangle: "))
(COMMAND "MOVE" CENT3R "" "m2p" p1 p2 "M2P" "0,0" "12,9")
(command "snap" "s" "i" "")
(setvar "snapmode" oldsnap)
(setvar "OSMODE" OLDOS)
(SETQ CENT3R NIL)
(*ERROR* NIL)
(PRINT)
)
我想使用BoundingBox函数自动获取SSGET的坐标,而不是要求用户获取矩形的第一个和第二个点。请参阅下面获取边界框坐标的代码。有人能帮我把这两个放在一起吗?谢谢,上帝保佑。
(defun c:test ( / OBJ Point1 Point2 )
(vl-load-com)
(princ "\nSelect an object: ")
(setq OBJ (vlax-ename->vla-object (ssname (ssget) 0)))
(if OBJ
(progn
;;OBJ is a vla-object
;;Point1 is the lower left point of the bounding box around the object
;;Point2 is the upper right point of the bounding box around the object
(vla-getboundingbox OBJ 'Point1 'Point2)
;;Point1 and Point2 are returned as a safearray and need to be converted to a list
(setq Point1 (vlax-safearray->list Point1))
(setq Point2 (vlax-safearray->list Point2))
(princ (strcat "\n The lower left corner is " (rtos (car Point1) 2 2) ", " (rtos (cadr Point1) 2 2)))
(princ (strcat "\nThe upper right corner is " (rtos (car Point2) 2 2) ", " (rtos (cadr Point2) 2 2)))
)
)
(princ) ) 下面是使用我的选择集边界框函数的快速草稿:
(defun c:cen ( / s l )
(and (setq s (ssget "_:L"))
(setq l (LM:ssboundingbox s))
(command "_.move" s ""
"_non"(apply 'mapcar (cons '(lambda ( a b ) (/ (+ a b) 2.0)) l))
"_non" '(6.0 4.5)
)
)
(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 - 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) 李先生,你又来了!我非常感谢您在CAD导师社区中为帮助这些人和我自己所做的不懈努力和奉献!你的日常工作完美无瑕!我祝你和你的家人一切顺利!:值得注意:
不客气!感谢您的感激和良好祝愿,我很高兴代码对您有所帮助。
李
页:
[1]