- 积分
- 59892
- 明经币
- 个
- 注册时间
- 2004-6-15
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2004-8-25 10:58:00
|
显示全部楼层
;;思路:判断ptlist(spline的各个节点的表)中前后两点的斜率是否一样。
;;BY LUCAS(龙龙仔) ;;将spline等分为n个弧,再转为pline ;;只对2D spline有效, 3D spline要改用3dpoly ;;程序其实有个bug,对直线的spline会出错,用一个偷懒的办法解决了.
(defun C:SPLINE_TO_PLINE (/ HOLDECHO OS SSS NUMPT N ED ED1 PTST PTEND SS2 PT1 PT2 PT3 J ENT NNO SS SSL ptlist b )
(defun VAL1 (N SS INDEX) (cdr (assoc N (entget (ssname SS INDEX)))) )
(defun CH_IT (NOS) (if (assoc NOS ED) (progn (if (assoc NOS ENT) (setq ENT (subst (assoc NOS ED) (assoc NOS ENT) ENT)) (setq ENT (append ENT (list (assoc NOS ED)))) ) (entmod ENT) ) ) )
(setq HOLDECHO (getvar "cmdecho")) (setvar "cmdecho" 0) (command "_.undo" "group") (setq OS (getvar "osmode")) (setvar "osmode" 0) (prompt "\nPlease pick the spline: ") (setq SSS (ssget '((0 . "spline")))) (if SSS ;if1 (progn;progn1 (initget (+ 1 2 4)) (setq NUMPT (getint "\nPlease specify the accuracy of conversion: " ) ) (setq N 0) (setq SSL (sslength SSS)) (repeat SSL ;repeat1 (prompt (strcat "\r余 " (itoa (- SSL N)) " 个物件 "));相当于进度条 (setq ED1 (ssname SSS N)) (setq ED (entget ED1))
(setq ptlist (pp ed)) (leo ptlist) (setq PTST (cdr (assoc 10 ED)) ;取得起点坐标 PTEND (cdr (assoc 10 (reverse ED)));取得终点坐标 )
(if (= b 123) (progn ;progn3 (command "erase" ed1 "") (command "pline" ptst ptend "") (setq N (1+ N)) );end progn3
(progn ;progn2 (command "_.divide" ED1 (* 2 NUMPT)) (setq SS2 (ssget "p")) (if (= (logand (cdr (assoc 70 ED)) 1) 1) (setq J 1) (setq J 0) ) (setq PT3 PTST) (setq SS (ssadd)) (repeat NUMPT;repeat2 (setq PT2 (VAL1 10 SS2 J)) (if (/= NUMPT (/ (+ J 2) 2)) (setq PT1 (VAL1 10 SS2 (+ 1 J))) (setq PT1 PTEND) ) (command "_.arc" PT3 PT2 PT1) (ssadd (entlast) SS) (setq PT3 PT1) (setq J (+ 2 J)) );end repeat2 (command "_.pedit" (ssname SS 1) "" "j" SS "" "") (setq ENT (entget (entlast))) (foreach NNO '(6 8 62 48) (CH_IT NNO) ) (command "_.erase" SS2 ED1 "") (setq N (1+ N)) );end progn2 );end if2 );end repeat1 (prompt (strcat "\r完成转换 ") ) );end progn1 (alert "Nothing selected!!") );end if1 (setvar "osmode" OS) (command "_.undo" "end") (setvar "cmdecho" HOLDECHO) (princ) ) (defun pp (obj /) (vl-load-com) (MASSOC 10 obj) )
(defun massoc (key alist / x nlist) (foreach x alist (if (eq key (car x)) (setq nlist (cons (cdr x) nlist)) ) ) (reverse nlist) )
;判断一个表中的各点的是不是在一直线上 (defun leo (listpoint / listnumber listpoint ang1 ang a list_pt) (setq list_pt listpoint) (setq listnumber (length list_pt)) (if (>= listnumber 2) (setq ang1 (angle (car list_pt) (cadr list_pt))) ) (setq a 1) (while (and (>= listnumber 2) (= a 1)) (setq ang (angle (car list_pt) (cadr list_pt))) (if (equal ang1 ang 0.000001) (setq a 1) (setq a 2) ) (setq ang1 ang) (setq list_pt (cdr list_pt)) (setq listnumber (length list_pt)) ) (if (= listnumber 1) (setq b 123) (setq b 456) ;b在主程序中设成变量 ) ) (print) (prompt "\nType SPLINE_TO_PLINE to run") (print)
|
|