lazysea 发表于 2003-6-6 10:09:00

请分析一下这个程序 是一个关于路灯方面的?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;draw the polyline
;;;and check the layer of "NUM"
(defun c:plg ()
(setq s_bp(getvar "blipmode"))
(setq s_cmd(getvar "cmdecho"))
(setq s_os(getvar "osmode"))
(setvar "blipmode" 0)
(setvar "cmdecho" 0)
(setvar "osmode" 0)
(setq ss (ssget "x" (list (cons 0 "line") (cons 8 "PLINE"))))
(command "zoom" "e" "")
(command "-layer" "m" "POLY" "c" 1 "" "")
(setq sl (sslength ss) i 0)
(setq inf_lt '())
(repeat sl
    (setq l_nam (ssname ss i))
    (setq inf_lt (cons (list l_nam 0) inf_lt))
    (setq i (1+ i))
    );;end of repeat
(setq inf_lt (reverse inf_lt))
(setq i 0)
(repeat sl
    (setq l_nam (ssname ss i))
    (setq mk_lt (assoc l_nam inf_lt))
    (setq mark (last mk_lt))
    (setq pln_v '() head '() tail '() start '())
    (if (/= 3 mark)
      (progn
(setq l_da (entget l_nam))
(cond
((or(= 0 mark)(= 2 mark))
   (setq head (cdr (assoc 10 l_da)) tail (cdr (assoc 11 l_da)) start head)
   (setq inf_lt (subst (list l_nam (+ mark 1)) mk_lt inf_lt))
   )
((= 1 mark)
   (setq head (cdr (assoc 11 l_da)) tail (cdr (assoc 10 l_da)) start head)
   (setq inf_lt (subst (list l_nam (+ mark 2)) mk_lt inf_lt))
   )
);;end of cond
(if (and head tail)(setq pln_v (list tail head)));;initilize the "pln_v" with reverse order
(while (not (equal tail start))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;select the list of adjist vertist
(setq p1 (list (+ 0.01 (car tail))(+ 0.01 (nth 1 tail))) p2 (list (- (car tail) 0.01) (- (nth 1 tail) 0.01)))
(setq s_nea (ssget "_c" p1 p2) v_nea '())
(if s_nea
    (progn
      (setq snea_l (sslength s_nea) j 0 )
      (repeat snea_l
(setq l_na (ssname s_nea j))
(if (/= l_nam l_na)
(progn
    (setq mk (last (assoc l_na inf_lt)))
    (if (/= 3 mk)
      (progn
(setq l_da1 (entget l_na))
(setq pt1 (cdr (assoc 10 l_da1)) pt2 (cdr (assoc 11 l_da1)))
(cond
((and (or(= 0 mk)(= 2 mk))(equal tail pt1)(not (equal head pt2)))
   (setq lst (list mk l_na pt2 1))
   (setq v_nea (cons lst v_nea))
   )
((and (or(= 0 mk)(= 1 mk))(equal tail pt2)(not (equal head pt1)))
   (setq lst (list mk l_na pt1 2))
   (setq v_nea (cons lst v_nea))
   )
);;end of cond
);;end of progn
      );;end of if
    );;end of progn
);;end of if
(setq j (1+ j))
);;end of repeat
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;calculate the angle and update
;;;select the path ,update the general vertist list
;;;and update the vertist list of the polyline
      (setq vnea_l (length v_nea))
      (if (= vnea_l 1)
(progn
(setq sel_ln (car v_nea))
(setq info1 (car sel_ln) info2 (last sel_ln) l_na1 (nth 1 sel_ln))
(setq pt (nth 2 sel_ln) pln_v (cons pt pln_v));;update the vertist list of the polyline
(setq inf_lt (subst (list l_na1 (+ info1 info2)) (list l_na1 info1) inf_lt))
(setq head tail tail pt)
);;end of progn
(progn   ;;;else (main body of the function)
(setq sel_ln (car v_nea))
(setq ang0 (angle tail head) pi2 (* 2 pi) nextv (nth 2 sel_ln) h 1)
(setq ang1 (angle tail nextv))
(setq mina (- ang1 ang0))
(if (minusp mina) (setq mina (+ pi2 mina)))
(repeat (1- vnea_l)
    (setq l_v (nth h v_nea))
    (setq v_wt (nth 2 l_v) info1 (car l_v) info2 (last l_v))
    (setq ang (-(angle tail v_wt) ang0))
    (if (minusp ang) (setq ang (+ pi2 ang)))
    (if (< ang mina)(setq mina ang nextv v_wt sel_ln l_v));;select the right side
    (setq h (1+ h))
    );;end of repeat
(setq info1 (car sel_ln) info2 (last sel_ln) l_na2 (nth 1 sel_ln))
(setq pln_v (cons nextv pln_v));;update the vertist list of the polyline
(setq inf_lt (subst (list l_na2 (+ info1 info2)) (list l_na2 info1) inf_lt))
(setq head tail tail nextv)
);;end of progn
);;end of if
      )
    (progn
      (command "circle" tail 200 "")
      (exit)
      );;end of progn
    );;end of if
);;end of while
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;draw the polyline
;;;and check the layer of "NUM"
(if (and head tail)
(progn
    (setq ang 0)
    (setq pln_v (reverse pln_v))
    (setq plv_l (length pln_v) r 0)
    (repeat (- plv_l 2)
      (setq angl (- (angle (nth r pln_v)(nth (1+ r)pln_v))(angle (nth(1+ r)pln_v)(nth (+ 2 r)pln_v))))
      (if (< angl (- pi)) (setq angl (+ angl (* 2 pi))))
      (if (> angl pi) (setq angl (- angl (* 2 pi))))
      (setq ang (+ ang angl))
      (setq r (1+ r))
      );;end of repeat
    (setq angl(- (angle (nth r pln_v)(nth (1+ r)pln_v))(angle (nth 0 pln_v)(nth1 pln_v))))
    (if (< angl (- pi)) (setq angl (+ angl (* 2 pi))))
    (if (> angl pi) (setq angl (- angl (* 2 pi))))
    (setq ang (+ ang angl))
    (if (equal ang (* 2 pi)pi )
      (progn
(command "_pline");;draw the polyline
(setq k 0 )
(repeatplv_l
(setq pt (nth k pln_v))
(command pt)
(setq k (1+ k))
);;end of repeat
(command "")
(setq num_lt (ssget "_wp" pln_v (list (cons 0 "text")(cons 8 "NUM"))))
(if num_lt
(progn
    (setq num_no (sslength num_lt))
    (setq id 0)
    (repeat num_no
      (setq num_da (entget (ssname num_lt id)))
      (setq num_xy (cdr (assoc 10 num_da)))
      (setq num_tt (cdr (assoc 1 num_da)))
      (if (= 0 id)
(setq num0 num_tt)
(progn
(if (not (equal num_tt num0))
    (progn
      (command "-layer" "m" "chk2" "c" 2 "" "")
      (command "circle" num_xy 80 "")
      );;end of progn
    );;end of if
);;end of progn
);;end of if
      (setq id (1+ id))
      );;end of repeat
    (command "-layer" "m" "POLY" "c" 1 "" "")
    );;end of progn
);;end of if
);;end of progn
      );;end of if
    );;end of progn
);;end of if
);;end of progn
      );;end of if
    (setq i (1+ i))
    );;end of repeat
(setvar "blipmode" s_bp)
(setvar "cmdecho" s_cmd)
(setvar "osmode" s_os)
(princ)

无痕 发表于 2003-10-16 11:23:00

写这个程序主要是用来干什么?用来解决什么问题的?

gzy 发表于 2003-10-16 17:45:00

晕!
2楼说的对,你至少要告诉大家你的程序是干什么的,出现了什么你不能解决的问题,而且你的程序应该加上一些注释,便于别人也便于你自己阅读方便。

myfreemind 发表于 2003-10-16 23:13:00

是啊,关于路灯什么的?
页: [1]
查看完整版本: 请分析一下这个程序 是一个关于路灯方面的?