如何将不规则曲线(非圆弧)与其它线合成多段线
小弟试了很久了。用pedit无法将不规则曲线变为多段线。将图转化为r12格式,再打开,可将曲线本身变为多段线,但用peidt时却没有了合并选项(J) ;;思路:判断ptlist(spline的各个节点的表)中前后两点的斜率是否一样。
;;BY LUCAS(龙龙仔)<BR>;;将spline等分为n个弧,再转为pline<BR>;;只对2D spline有效, 3D spline要改用3dpoly<BR>;;程序其实有个bug,对直线的spline会出错,用一个偷懒的办法解决了.
(defun C:SPLINE_TO_PLINE (/ HOLDECHO OS SSS NUMPT N<BR> ED ED1 PTST PTEND SS2 PT1 PT2<BR> PT3 J ENT NNO SS SSL<BR> ptlist b )
(defun VAL1 (N SS INDEX)<BR> (cdr (assoc N (entget (ssname SS INDEX))))<BR> )
(defun CH_IT (NOS)<BR> (if (assoc NOS ED)<BR> (progn<BR> (if (assoc NOS ENT)<BR> (setq ENT (subst (assoc NOS ED) (assoc NOS ENT) ENT))<BR> (setq ENT (append ENT (list (assoc NOS ED))))<BR> )<BR> (entmod ENT)<BR> )<BR> )<BR> )
(setq HOLDECHO (getvar "cmdecho"))<BR> (setvar "cmdecho" 0)<BR> (command "_.undo" "group")<BR> (setq OS (getvar "osmode"))<BR> (setvar "osmode" 0)<BR> (prompt "\nPlease pick the spline: ")<BR> (setq SSS (ssget '((0 . "spline"))))<BR> (if SSS ;if1<BR> (progn;progn1<BR> (initget (+ 1 2 4))<BR> (setq NUMPT<BR> (getint<BR> "\nPlease specify the accuracy of conversion: "<BR> )<BR> )<BR> (setq N 0)<BR> (setq SSL (sslength SSS))<BR> (repeat SSL ;repeat1<BR> (prompt (strcat "\r余 " (itoa (- SSL N)) " 个物件 "));相当于进度条<BR> (setq ED1 (ssname SSS N))<BR> (setq ED (entget ED1))
(setq ptlist (pp ed))<BR> (leo ptlist)<BR> <BR> (setq PTST (cdr (assoc 10 ED)) ;取得起点坐标<BR> PTEND (cdr (assoc 10 (reverse ED)));取得终点坐标<BR> )
(if (= b 123)<BR> (progn ;progn3<BR> (command "erase" ed1 "")<BR> (command "pline" ptst ptend "")<BR> (setq N (1+ N))<BR> );end progn3
(progn ;progn2<BR> (command "_.divide" ED1 (* 2 NUMPT))<BR> (setq SS2 (ssget "p"))<BR> (if (= (logand (cdr (assoc 70 ED)) 1) 1)<BR> (setq J 1)<BR> (setq J 0)<BR> )<BR> (setq PT3 PTST)<BR> (setq SS (ssadd))<BR> (repeat NUMPT;repeat2<BR> (setq PT2 (VAL1 10 SS2 J))<BR> (if (/= NUMPT (/ (+ J 2) 2))<BR> (setq PT1 (VAL1 10 SS2 (+ 1 J)))<BR> (setq PT1 PTEND)<BR> )<BR> (command "_.arc" PT3 PT2 PT1)<BR> (ssadd (entlast) SS)<BR> (setq PT3 PT1)<BR> (setq J (+ 2 J))<BR> );end repeat2<BR> (command "_.pedit" (ssname SS 1) "" "j" SS "" "")<BR> (setq ENT (entget (entlast)))<BR> (foreach NNO '(6 8 62 48)<BR> (CH_IT NNO)<BR> )<BR> (command "_.erase" SS2 ED1 "")<BR> (setq N (1+ N))<BR> );end progn2<BR> );end if2<BR> );end repeat1<BR> (prompt (strcat "\r完成转换 ")<BR> )<BR> );end progn1<BR> (alert "Nothing selected!!")<BR> );end if1<BR> (setvar "osmode" OS)<BR> (command "_.undo" "end")<BR> (setvar "cmdecho" HOLDECHO)<BR> (princ)<BR>)<BR>(defun pp (obj /)<BR>(vl-load-com)<BR>(MASSOC 10 obj)<BR>)
(defun massoc (key alist / x nlist)<BR>(foreach x alist<BR>(if (eq key (car x))<BR>(setq nlist (cons (cdr x) nlist))<BR>)<BR>)<BR>(reverse nlist)<BR>)
;判断一个表中的各点的是不是在一直线上<BR>(defun leo (listpoint / listnumber listpoint ang1 ang a list_pt)<BR> (setq list_pt listpoint)<BR> (setq listnumber (length list_pt))<BR> (if (>= listnumber 2)<BR> (setq ang1 (angle (car list_pt) (cadr list_pt)))<BR> )<BR> (setq a 1)<BR> (while (and (>= listnumber 2) (= a 1))<BR> (setq ang (angle (car list_pt) (cadr list_pt)))<BR> (if (equal ang1 ang 0.000001)<BR> (setq a 1)<BR> (setq a 2)<BR> )<BR> (setq ang1 ang)<BR> (setq list_pt (cdr list_pt))<BR> (setq listnumber (length list_pt))<BR> )<BR> (if (= listnumber 1)<BR> (setq b 123)<BR> (setq b 456) ;b在主程序中设成变量<BR> )<BR>)<BR>(print)<BR>(prompt "\nType SPLINE_TO_PLINE to run")<BR>(print)<BR> ???????????????? 不明白吗?上面的程序就是将SPLINE线转成PLINE线。这样您就可以对转换成的线条进行编辑了。 牛 PEDIT有几项条件:
1. 必须是连续性的(continuous)。
2. 必须有头有尾,如X.Y.O,Ø等形皆不行。
3. 各线段线性质,如Line. Pline,Lwpline.Spline....等必须相同。
页:
[1]