杂草lsp需要自动化
如何更改下面的代码,它不会每次都询问腿部长度和偏移量。如何将变量放入此代码中?偏移0.1mm,腿长1.2mm?此外,它还可以删除旧的多段线,而无需询问。在这之后,我只需要写杂草和选择多段线,这就是它。
(textscr)
(princ(strcat
"\n\n=========================WEED.LSP==========================="
"\n\nWEED removes extranious verticies from LINEs or a POLYLINE."
"\nShort segments less than the specified leg length ...AND..."
"\nhaving an offset distance less than the minimum distance"
"\nare removed. Try different combinations to get the result"
"\ndesired. Changes can be undone by entering the U command"
"\ntwice. The routine will convert LINEs to a POLYLINE providing"
"\nthat all line segments endpoints match exactly. Additional"
"\nverticies that have been added by a Spline or Fit curve can"
"\nbe treated like \"real\" verticies, or can be ignored."
"\n\nExample: "
"\nEnter offset distance: 10 <Enter number or pick 2 pts>"
"\nEnter leg length: 100 <Enter number or pick 2 pts>"
"\n\nAll included verticies having the longest leg less than 100"
"\nAND being less than 10 from the original line will be removed."
"\nIf you wish offset to control select a large leg length."
"\nIf you wish leg length to control select a large offset."
"\nJerry Workman CIS 70717,3564"
"\nLoading..."))
;*----- Debugging stuff, load this file by entering LD<RETURN>
;(defun c:ld() (load "weed"))
;(defun c:ed() (command "q" "d:\\acad\\support\\weed.lsp"))
;*----- Error Routine
(defun w-error (s) (redraw) (grtext)
(princ "\nWeed Error: ") (princ s)
(exit)
)
;*----- Exit Routine
(defun exit()
(if (boundp 'f) (setq f (close f)))
(setvar "cmdecho"cmdecho)
(setvar "blipmode" blipmode)
(setq *error* olderr)
(princ)
)
;*----- Extract a field from a list
(defun fld (num lst) (cdr (assoc num lst)))
;*----- Plot a temporary X
(defun blip (blpoint / s x1 y1 x2 y2 p1 p2 p3 p4)
(setq s(/ (getvar "viewsize") 100) ; 1/100 of viewsize
x1 (+ (car blpoint) s)
y1 (- (cadr blpoint) s)
x2 (- (car blpoint) s)
y2 (+ (cadr blpoint) s)
p1 (list x1 y1) p2 (list x2 y2)
p3 (list x2 y1) p4 (list x1 y2))
(grdraw p1 p2 -1) (grdraw p3 p4 -1)
)
;*----- Convert a line to a polyline entity
(defun line2pline(ent / dat etype epnt ss1 ss2)
(if ent (progn
(setq dat (entget ent)
etype (fld 0 dat))
(if (= etype "LINE") (progn
(princ "\nConverting LINE to PLINE")
(setq epnt (fld 10 dat)
ss1 (ssadd ent)
ss2 (ssget "C" (getvar "EXTMIN") (getvar "EXTMAX")))
(ssdel ent ss2)
(command "pedit" ss1 "y" "j" ss2 "" "x")
(ssname (ssget epnt) 0) ; return the new entity name
)
;else return nil
(progn (princ "\nNot a Line")
nil)
)
);else
(progn
(princ "\nNothing selected")
nil)
)
)
;*-----Get a polyline or line entity
(defun fetch(/ pl etyp flgs ans)
(setq etyp nil)
(while (not (or (= etyp "LINE") (= etyp "POLYLINE"))) (progn
(setq ename nil)
(setq e (car (entsel "\nSelect a PolyLine or Line: ")))
(if e (progn
(setq pl (entget e)
etyp (fld 0 pl)
enamee)
(if (or (= etyp "LINE") (= etyp "POLYLINE")) (progn
(princ (strcat "\n" etyp " selected"))
(if (= etyp "LINE")
(setq e (line2pline e)
enamee
pl (entget e))
))
;else
(progn (princ "\nThat's not a LINE or POLYLINE, it's a ") (princ etyp))
); end if
); end progn
; else
(princ "\nNothing Selected")
); end if
)); end while
(setq flgs (fld 70 pl))
(setq closed (=(boole 1 flgs 1) 1))
(if closed (princ "\nClosed Polyline"))
(cond
((=(boole 1 flgs 2) 2) (progn
(setq ptyp "F")
(princ "\nFit curve verticies have been added")))
((=(boole 1 flgs 4) 4) (progn
(setq ptyp "S")
(princ "\nSpline curve verticies have been added...")))
(t (setq ptyp "N")) ;Normal polyline
)
(if(/= ptyp "N") (progn
(initget "Y N")
(if(= (getkword "\nDecurve polyline during weeding:") "Y")
(setq ptyp "N"))
))
)
;*----- Check vertex type
(defun vt_ok ()
(if (= etype "VERTEX")
(cond
((= ptyp "F") (or(=(boole 1 flags 1) 1) (= flags 0)))
((= ptyp "S") (>(boole 1 flags 9) 0))
(t (=(boole 1 flags 25) 0)) ;"N" normal, 1 8 16 off
)
;else
t
)
)
;*----- extract the list containing vertex coordinates
(defun get_vertex(/ vert etype sub_ent flags)
(setq vert nil
etype nil)
(while (and e (null vert) (/= etype "SEQEND")) (progn
(setq v (entnext e)
e v
etype nil)
(if e (progn
(setq sub_ent (entget v)
flags (fld 70 sub_ent)
etype (fld 0sub_ent))
;(princ "flags =")(princ flags)
(if (vt_ok)
(if (= etype "VERTEX")
(setq vert_cnt (1+ vert_cnt)
vert (fld 10 sub_ent))
; else return
nil
)
)
))
))
)
;*----- Add a vertex to the temporary file for the new pline
(defun add_vert(vt)
(if (null f) (setq f (open "weedtmp.$$$" "w")))
(prin1 vt f)
(princ "\n" f)
)
;*----- Read a vertex from the temporary file for the new pline
(defun read_vert(/ pt)
(setq pt (read-line f))
(if pt (read pt) nil)
)
;*----- Read new polyline from the tempory file
(defun retrieve()
(setq f (open "weedtmp.$$$" "r"))
(command ".PLINE")
(setq v (read_vert))
(while v (progn
(command v)
(setq v (read_vert))
))
(command "")
;(command "del" "weedtmp.$$$")
)
;*----- Check the internal angle and leg lengths then add or delete
(defun check_it(/ ang dist1 dist2 dist offset off)
(setq ang12(abs(angle v1 v2))
ang13(abs(angle v1 v3))
ang (abs(- ang12 ang13))
dist1(distance v1 v2)
dist2(distance v2 v3)
dist (max dist1 dist2) ; largest distance
off (* dist1 (sin ang))
offset (+ p_off off)
p_offoffset
)
(if
(and
(< offset max_offset) ;offset distance criteria
(< dist min_dist) ;minimum leg length criteria
)
;then skip middle vertex
(progn (blip v2) ;mark the deleted vertex
(setq v2 v3
v3 (get_vertex)
skip_cnt (1+ skip_cnt))
(princ "\nSkipping vertex # ") (princ (- vert_cnt 2))
; (princ (strcat ", max_offset " (rtos max_offset 2 2) "
; min_dist " (rtos min_dist 2 2)))
; (princ (strcat ", offset " (rtos offset 2 2) " dist " (rtos dist 2 2)))
)
;else add first vertex to list
(progn
(add_vert v2)
(setq v1 v2
v2 v3
v3 (get_vertex)
p_off0)
); end progn
); end if
)
;*----- The main routine...
(defun C:WEED( / v1 v2 v3 ename v skip_cnt vert_cnt cmdecho blipmode f
olderr max_offset min_dist closed spline fit e_del
p_off vstart ptyp)
(setq cmdecho(getvar "cmdecho")
blipmode (getvar "blipmode")
olderr *error*
*error*w-error
;*error* nil
skip_cnt 0
p_off 0
f nil
vert_cnt 0
)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(initget (+ 1 2 4))
(setq max_offset (getdist "\nEnter offset distance: "))
(initget (+ 1 2 4))
(setq min_dist (getdist "\nEnter leg length: "))
(initget "Y N")
(setq e_del (getkword "\nDelete original Polyline : "))
(if (null e_del) (setq e_del "Y"))
(fetch)
(princ "\nChecking polyline verticies...")
(setq v1 (get_vertex)
vstart v1
v2 (get_vertex)
v3 (get_vertex))
(add_vert v1)
(while v3 (check_it))
(if (< (distance v1 v2) min_dist)
(progn (setq skip_cnt (1+ skip_cnt))
(princ "\nSkipping vertex # ") (princ vert_cnt))
;else
(add_vert v1)
); end if
(add_vert v2)
(if closed (add_vert vstart))
; Delete old line and draw new Pline
(if (> skip_cnt 0) (progn
(close f)
(if (= e_del "Y") (entdel ename))
(retrieve)
(princ (strcat "\n" (itoa skip_cnt) " verticies removed "
"out of " (itoa vert_cnt) " tested ("
(rtos(/ (* 100.0 skip_cnt) vert_cnt) 2 2)
") percent"))
)
;else
(princ "\nNothing to change!")
)
(exit)
)
你难道没有想过这个lisp是在1987年写的吗?直到现在,还没有人需要它实现自动化。
每个人的需求都是不同的,对你来说自动化只会对你有用。
这是学习lisp的绝佳机会,您可以完成例程,每次出现提示信息时,您都可以为该变量设置自己的值。然后你会有自己的个性化、自动化版本 只为我。。。谢谢 你可能会抓住一个心地善良的人。
但它为你提供了一个尝试自己的理想机会。lisp可以按原样工作,所以请尝试修补它,直到你让它做你想做的事情。 我已经尝试在lsp中编码值。我只有错误,但我会让它发挥作用。
好吧,这并不完全是没有人,因为我自己发现,做OP要求的事情很有用。我没有修改lisp,但是,我添加了一个带有命令宏的按钮。
在这种情况下,宏将为:Weed>Offset 0.1>leg length 1.2>Delete original Polyline N(或Y)
Weed;.1;1.2;N;
你的意思是:
sub weeding()
Weed;.1;1.2;N;
end sub
??
这行不通。我试着用宏录制器录制http://www.cadstudio.cz/dl_file.asp?ID=548但似乎什么都没有记录。 CUI>创建新命令
非常感谢你! 删除提示的修改实际上非常简单,更改:
第260-266行:
(initget (+ 1 2 4))
(setq max_offset (getdist "\nEnter offset distance: "))
(initget (+ 1 2 4))
(setq min_dist (getdist "\nEnter leg length: "))
(initget "Y N")
(setq e_del (getkword "\nDelete original Polyline : "))
(if (null e_del) (setq e_del "Y"))
收件人:
(setq max_offset 0.1)
(setq min_dist 1.2)
(setq e_del "N")
(根据需要更改这些值,我刚刚使用了nestly发布的示例)
页:
[1]