关于“GetClosestPo”的问题
你好这是我的brew(信贷->在Asmi网站的帮助下):
(defun c:getClosestPoint (/ obj pt1 pt2)
; Make variables local
(vl-load-com)
; Loads the extended AutoLISP functions
(setq
obj (car (entsel))
; Select an object / curve
pt1 (getpoint "\nGrab yourself a point:")
; As it says...
pt2 (vlax-curve-getClosestPointTo obj pt1)
; The actual "determination" of the closest point
); end of setq
(command "_.line" pt1 pt2 "")
; draw line between the 2 points
(princ)
; clean running
); end of defun
(princ)
;clean loading
是否可以以不必选择对象的方式修改此代码?我想一定有办法“得到离给定点最近的物体”。之后,AutoCad需要查找对象本身。
当有很多物体时,我知道很难精确,但这不是重点。我只想知道这是否可能,以及如何做到。
顺便说一句,像我想的那样,确定最近的点要容易得多。我希望我的问题的答案也是。
谢谢你帮我! 也许是这样的,但我不想对成千上万的物体这样做。。。。
(defun c:test (/ i ss pt ent lst Nrst)
(if (and (setq i -1 ss (ssget "_X" '((0 . "*LINE,CIRCLE,ELLIPSE,ARC"))))
(setq pt (getpoint "\nSelect a Point: ")))
(progn
(while (setq ent (ssname ss (setq i (1+ i))))
(setq lst
(cons
(cons ent (vlax-curve-getClosestPointto ent pt)) lst)))
(setq Nrst (car (vl-sort lst
(function
(lambda (a b)
(< (distance (cdr a) pt)
(distance (cdr b) pt)))))))
(entmakex (list (cons 0 "LINE")
(cons 10 pt)
(cons 11 (cdr Nrst))))))
(princ))
嗨,李,
这正是我需要知道的。非常感谢。
但是现在,对于学习部分。。。我弄不懂,那是因为我仍然缺乏知识。但是,我一直在进步。
如果你可以/想要的话,也许你可以再给我解释一下。
我很乐意。
干杯
当然,伙计:
(defun c:test (/ i ss pt ent lst Nrst)
(if (and (setq i -1 ;; Initiate Counter
ss (ssget "_X" '((0 . "*LINE,CIRCLE,ELLIPSE,ARC"))))
;; Get A SelectionSet of all CurveObjects to iterate through
(setq pt (getpoint "\nSelect a Point: ")) ;; Get Point from User
) ; end AND
(progn ;; Open Wrapper for 'then' statement
(while (setq ent (ssname ss (setq i (1+ i))))
;; While we can get an entity name in the SelectionSet
(setq lst
(cons
(cons ent (vlax-curve-getClosestPointto ent pt)) lst))
;; Make a list of entities and closest Points (in case we need the object also)
;; List looks like this:
;; ((<Entity name: 7ef038c0> . (-23.3336 30.6639 0.0))
;;(<Entity name: 7ef038c8> . (-46.4083 3.42278 0.0)) ...)
) ; end WHILE
(setq Nrst (car;; Get the First item of the Sorted List
(vl-sort lst
(function
(lambda (a b)
(< (distance (cdr a) pt)
(distance (cdr b) pt)))))))
;; Sort the list by distance from the original selected point
(entmakex (list (cons 0 "LINE")
(cons 10 pt)
(cons 11 (cdr Nrst))))))
;; Create a line from the user selected point to the nearest point
(princ)) ;; Exit Cleanly
两个缺点意味着:把一个新的项目放在列表中,作为第一个项目?
哦。。。这很难,但需要学习。 当与两个原子一起使用时,cons会形成一个点对,或者,当与一个原子/列表和另一个列表一起使用时,它会将原子/列表添加到列表的开头。 嗨,李,我想知道你Lisp程序的样子。
你能解释一下ENTMAKE和ENMAKEX之间的区别吗?
谢谢 我倾向于在entmake上使用entmakex,因为它返回新创建实体的实体名,这可能很有用。
所以有点像
(entmake(列表(cons 0“行”)
(cons 10 pt)
(cons 11(cdr NrstϨϨϨ)Ϩ)
(setq线(entlast)) 这将得到相同的结果:
(setq ent1 (ssname sset 0)) ; Gets the name of the first entity in sset.
(setq line (entmakex (list (cons 0 "LINE")
(cons 10 p1)
(cons 11 p2))))
李 谢谢李。
你现在不迟到吗?
这里是晚上8:30
页:
[1]
2