这是李麦克的一个内接圆程序,怎么将图层从随层改为制定图层
;;; maximum circle inscribed in a closed polyline
;;; Gian Paolo Cattaneo
(defun C:Q11 (/ POLY POLY_vl Dx Dy Lp List_vert_poly list_p_int P_center dist step1 step2)
(prompt "\nSelect Polyline: ")
(while (setq POLY (ssname (ssget ":S" '((0 . "LWPOLYLINE"))) 0))
(progn
(setq i 1 timer (date2sec))
(setq step1 60) ;--> grid_1
(setq step2 20) ;--> grid_2
(setq POLY_vl (vlax-ename->vla-object POLY))
(setq list_vert_poly (LM:LWPoly->List POLY))
(grid_1)
(Point_int)
(grid+)
(Point_center)
(repeat 3
(grid_2)
(Point_center)
)
(entmake
(list
(cons 0 "CIRCLE")
(cons 8 (getvar "clayer"))
(cons 10 P_center)
(cons 40 dist)
)
)
(setq endtimer (date2sec))
(princ (strcat "time = "(rtos (- endtimer timer) 2 3) " seconds"))
(princ)
)
)
)
;; LWPolyline to Point List-Lee Mac
;; Returns a list of points describing the supplied LWPolyline
(defun LM:LWPoly->List ( ent / der di1 di2 inc lst par rad )
(setq par 0)
(repeat (cdr (assoc 90 (entget ent)))
(if (setq der (vlax-curve-getsecondderiv ent par))
(if (equal der '(0.0 0.0 0.0) 1e-8)
(setq lst (cons (vlax-curve-getpointatparam ent par) lst))
(if
(setq rad (distance '(0.0 0.0) (vlax-curve-getfirstderiv ent par))
di1 (vlax-curve-getdistatparam ent par)
di2 (vlax-curve-getdistatparam ent (1+ par))
)
(progn
(setq inc (/ (- di2 di1) (1+ (fix (* 25 (/ (- di2 di1) rad (+ pi pi)))))))
(while (< di1 di2)
(setq lst (cons (vlax-curve-getpointatdist ent di1) lst)
di1 (+ di1 inc)
)
)
)
)
)
)
(setq par (1+ par))
)
lst
)
; Restituisce una griglia di punti all'interno del getboundingbox della poly selezionata
; Returns a grid of points within the BoundingBox of the selected poly
(defun grid_1 (/ P1_ P2_ n P> )
(vla-getboundingbox POLY_vl 'p1 'p2)
(setq P1_ (vlax-safearray->list p1))
(setq P2_ (vlax-safearray->list p2))
(setq P1_ (list (car P1_) (cadr P1_)))
(setq P2_ (list (car P2_) (cadr P2_)))
(setq Dx (/ (- (car P2_) (car P1_)) step1))
(setq Dy (/ (- (cadr P2_) (cadr P1_)) step1))
(setq n 0)
(setq P> P1_)
(setq Lp (list P1_))
(repeat (* (1+ step1) step1)
(setq P> (list (+ (car P>) Dx) (cadr P>)))
(setq Lp (cons P> Lp))
(setq n (1+ n))
(if (= n step1)
(progn
(setq n 0)
(setq P1_ (list (car P1_) (+ (cadr P1_) Dy)))
(setq P> P1_)
(setq Lp (cons P> Lp))
)
)
)
(setq Lp (cdr Lp))
)
; Restituisce una griglia di punti intorno al punto centrale (provvisorio)
; Returns a grid of points around the center point (provisional)
(defun grid_2 (/ P1_P> n)
(setq list_p_int nil)
(setq P1_ (list (- (car P_center) (* Dx 2)) (- (cadr P_center) (* Dy 2))))
(setq Dx (/ (* 4 Dx) step2))
(setq Dy (/ (* 4 Dy) step2))
(setq n 0)
(setq P> P1_)
(setq list_p_int (list P1_))
(repeat (* (1+ step2) step2)
(setq P> (list (+ (car P>) Dx) (cadr P>)))
(setq list_p_int (cons P> list_p_int))
(setq n (1+ n))
(if (= n step2)
(progn
(setq n 0)
(setq P1_ (list (car P1_) (+ (cadr P1_) Dy)))
(setq P> P1_)
(setq list_p_int (cons P> list_p_int))
)
)
)
)
; restituisce la lista dei punti interni ad un poligono
; dati:- lista coordinate dei punti -> Lp
; - lista coordinate vertici poligono -> list_vert_poly
; Returns the list of points inside the polyline
(defun Point_int (/ P_distant n Pr cont attr p# Pa Pa_ Pb )
(setq P_distant (list (car (getvar "extmax")) (* 2 (cadr (getvar "extmax")))))
(setq list_p_int nil)
(foreach Pr Lp
(setq cont -1)
(setq attr 0)
(setq p# nil)
(setq Pa (nth (setq cont (1+ cont)) list_vert_poly))
(setq Pa_ Pa)
(repeat (length list_vert_poly)
(setq Pb (nth (setq cont (1+ cont)) list_vert_poly))
(if (= cont (length list_vert_poly)) (setq Pb Pa_))
(setq P# (inters Pa Pb Pr P_distant))
(if (/= P# nil) (setq attr (1+ attr)))
(setq Pa Pb)
)
(if (> (rem attr 2) 0) (setq list_p_int (cons Pr list_p_int)))
)
)
; Infittisce la griglia inserendo altri punti
; nel centro delle diagonali tra i punti interni
; Insert points (interior) to increase the density of the grid
(defun grid+ (/ G+)
(setq G+
(mapcar '(lambda ( x ) (list (+ (car x) (/ Dx 2)) (+ (cadr x) (/ Dy 2)))) list_p_int)
)
(setq list_p_int (append G+ list_p_int))
)
; Da una lista di punti restituisce quello più lontano da un oggetto
; dati:- lista dei punti -> list_p_int
; - oggetto -> POLY_vl
; Returns the farthest point from the polyline
(defun Point_center (/ Pa n Pvic)
(setq Dist 0.0000001)
(setq P_center nil)
(foreach Pa list_p_int
(setq Pvic (vlax-curve-getClosestPointTo POLY_vl Pa))
(if (> (distance Pa Pvic) Dist)
(progn
(setq P_center Pa)
(setq Dist (distance Pa Pvic))
)
)
)
(if (>= Dist 0.5)(setq Dist 0.5))
)
(defun date2sec ()
(setq s (getvar "DATE"))
(setq seconds (* 86400.0 (- s (fix s))))
)
(vl-load-com)
(princ)
本帖最后由 yaojing38 于 2022-12-31 21:37 编辑
(cons 8 (getvar "clayer"))改成 (cons 8 “你的图层”)? yaojing38 发表于 2022-12-31 21:24
(cons 8 (getvar "clayer"))改成 (cons 8 “你的图层”)?
q11
Select Polyline:
选择对象:
undo 当前设置: 自动 = 开,控制 = 全部,合并 = 是,图层 = 是
输入要放弃的操作数目或 [自动(A)/控制(C)/开始(BE)/结束(E)/标记(M)/后退(B)] <1>: e DXF 组不正确: (8) zm880928 发表于 2023-1-2 08:16
q11
Select Polyline:
选择对象:
没那么简单 新手不太懂。。。没弄懂怎么的这个插件 zm880928 发表于 2023-1-2 08:16
q11
Select Polyline:
选择对象:
yaojing38给出的是正确的,你不会全角连符号一起复制过去了吧?
人家说的“你的图层”是指你需要的图层名,要注意符号的正确性,保证它是一个有效字符串而不是一个变量 llsheng_73 发表于 2023-1-4 11:09
yaojing38给出的是正确的,你不会全角连符号一起复制过去了吧?
人家说的“你的图层”是指你需要的图层 ...
你说的对,我把getvar也复制进去了,谢谢大哥的解答:lol yaojing38 发表于 2023-1-2 11:46
新手不太懂。。。没弄懂怎么的这个插件
是我搞错了,你是对的,谢谢大哥:lol
页:
[1]