下面是另一个-使用一些列表操作和visual lisp(在学习LM的代码后):
- ; Pline's vertices to txt file
- (defun C:test ( / LM:group-n SS i o e L fp opn )
-
- ;; Group by Number - Lee Mac
- ;; Groups a list 'l' into a list of lists, each of length 'n'
-
- (defun LM:group-n ( l n / r )
- (if l
- (cons
- (reverse (repeat n (setq r (cons (car l) r) l (cdr l)) r))
- (LM:group-n l n)
- )
- )
- )
- (cond
- (
- (not
- (progn
- (setq SS (ssget '((0 . "*POLYLINE"))))
- (repeat (setq i (sslength SS))
- (setq o (vlax-ename->vla-object (setq e (ssname SS (setq i (1- i))))))
- (if (vlax-property-available-p o 'Coordinates)
- (setq L (cons (cons (cdr (assoc 210 (entget e))) (LM:group-n (vlax-get o 'Coordinates) 3)) L))
- )
- ); repeat
- L
- )
- )
- (princ "\nInvalid objects selected.")
- )
- ( (not (setq fp (getfiled "Create vertices data" "" "txt" 1)))
- (princ "\nText file not specified.")
- )
- ( (setq opn (open fp "w"))
- (princ "X \tY \tZ" opn)
- (mapcar
- '(lambda (a b)
- (mapcar
- '(lambda (x)
- (princ
- (strcat "\n"
- (vl-string-left-trim "\t"
- (vl-string-right-trim ", "
- (apply 'strcat (mapcar '(lambda (n) (strcat "\t" (rtos n 2 2) ", ")) (trans x a 1)))
- )
- )
- )
- opn
- )
- )
- b
- )
- )
- (mapcar 'car L)
- (mapcar 'cdr L)
- )
- (close opn)
- (initget "Yes No")
- (if (= "Yes" (cond ((getkword "\nDo you want to open the file? [Yes/No] <Yes>: ")) ("Yes")))
- (startapp "explorer" fp)
- )
- )
- ); cond
- (princ)
- );| defun |; (vl-load-com) (princ)
|