矩形中的点
在LISP中,我可以选择一个矩形并自动为我定位4个角点吗? http://www.cadtutor.net/forum/showthread.php?35846-多段线点lisp例程 这可能有点简单,由您决定如何处理点列表,因为它很简单,不会检查您选择了什么。pline中的顶点数量相同。(setq obj2 (vlax-ename->vla-object (car(entsel))))
(setq co-ords (vlax-safearray->list (vlax-variant-value (vlax-get-property obj2 "Coordinates" ))))
(setq I 0)
(repeat (/(length co-ords) 2)
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2))
)
(princ co-ordsxy)
谢谢Bigal
我运行了那个代码,它给出了4个点的坐标。
要使用这4个点的位置,我需要每个角的名称吗?
例如,P1 P2 P3 P4的一条线
问候Tony
你好
使用以下简单代码,将第四个坐标分配给变量名“l”,每个坐标分配给变量,从p1、p2、p3和p4开始
(and (setq s (car (entsel "\nSelect Polyline with four coordinates :")))
(or (= (cdr (assoc 0 (setq e (entget s)))) "LWPOLYLINE")
(alert "Invliad object. Try again")
)
(or (= (cdr (assoc 90 (setq e (entget s)))) 4)
(alert "Invliad number of coordinates")
)
(mapcar '(lambda (p) (and (= (car p) 10) (setq l (cons (cdr p) l)))) e)
(mapcar 'set '(p1 p2 p3 p4) l)
)
很好的一个Tharwat。
Tunzagibbo由于点位于列表中,您也可以通过使用此方法检索每个垂直点来获得每个角点。
; the list of points starts with item zero not 1
; want 3rd point
(setq pt3 (nth 2 co-ordsxy))
; want 4th point
(setq pt4 (nth 3 co-ordsxy))
谢谢Bigal
如果你不介意的话,还有一个问题。
我有一个矩形,我用“setq”将其命名为INNERSHAPE
然后我想用你的代码找到INNERSHAPE的4个角,而不必在屏幕上再次选择该形状
该形状的质心是否也可以在相同的操作中定位?
问候Tony
谢谢你,比格尔。 嗨Bigal
我认为这应该行得通,但似乎没有得到4分(最后4行)
(defun InnerShape (/ InnerShape co-ords I xy co-ordsxy Innerpt1 Innerpt2 Innerpt3 Innerpt4)
(setq InnerShape (vlax-ename->vla-object (entlast))) ;my name choice "InnerShape"
(setq co-ords (vlax-safearray->list (vlax-variant-value
(vlax-get-property InnerShape "Coordinates" )))) ;my name choice "InnerShape"
(setq I 0)
(repeat (/(length co-ords) 2)
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2)))
(princ co-ordsxy)
(setq Innerpt1 (nth 0 co-ordsxy) :always start with 0 NOT 1
Innerpt2 (nth 1 co-ordsxy)
Innerpt3 (nth 2 co-ordsxy)
Innerpt4 (nth 3 co-ordsxy))
)
见上文。如果您希望坐标按创建顺序(线是如何绘制的),您需要
(setq co-ordsxy (reverse co-ordsxy))
页:
[1]
2