试试这个行不行:
 - (defun c:tt (/ *error* ang cmdecho en endpt line-en list-pt lst ltscale os ptlst ss ssn startpt vh)
- (defun *error* ( msg )
- (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
- (progn (princ (strcat "\n错误: " msg)) (vl-cmdf "_undo" "e") (vl-cmdf "_undo" 1) (setvar "CMDECHO" CMDECHO))
- )
- (princ)
- )
- (defun list-pt (lst)
- (if lst
- (cons
- (list
- (car lst)
- (cadr lst)
- (caddr lst)
- )
- (list-pt (cdddr lst))
- )
- )
- )
- (setq cmdecho (getvar "CMDECHO"))
- (setvar "CMDECHO" 0)
- (vl-cmdf "_undo" "be")
- (setq os (getvar "OSMODE"))
- (setvar "OSMODE" 16384)
- (setq startpt (getpoint "\n第一点:")
- endpt (getpoint startpt "\n第二点:")
- line-en (entmakex
- (list '(000 . "LINE")
- '(100 . "AcDbEntity")
- '(100 . "AcDbLine")
- (cons 10 startpt)
- (cons 11 endpt)
- )
- )
- )
- (setvar "OSMODE" os)
- (setq LtScale (getvar "LtScale"))
- (vl-cmdf "LtScale" (* LtScale 0.001))
- (setq ss (ssget "_f" (list startpt endpt) '((0 . "*line,CIRCLE,ELLIPSE,ARC")))
- ssn (sslength ss)
- ang (angle startpt endpt)
- )
- (vl-cmdf "LtScale" LtScale)
- (if (or (<= (* pi 0.25) ang (* pi 0.75))
- (<= (* pi 1.25) ang (* pi 1.75))
- )
- (setq VH "h")
- (setq VH "v")
- )
- (while (setq en (ssname ss (setq ssn (1- ssn))))
- (setq lst (vl-catch-all-apply
- 'vlax-safearray->list
- (list
- (vlax-variant-value
- (vla-intersectwith (vlax-ename->vla-object line-en) (vlax-ename->vla-object en) acExtendNone)
- )
- )
- )
- ptlst (if (vl-catch-all-error-p lst)
- nil
- (list-pt lst)
- )
- )
- (cond ((= VH "v")
- (mapcar '(lambda (x) (entmake (list '(0 . "XLINE") '(100 . "AcDbEntity") '(100 . "AcDbXline") (cons 10 x) (cons 11 '(0 1 0))))) ptlst)
- )
- ((= VH "h")
- (mapcar '(lambda (x) (entmake (list '(0 . "XLINE") '(100 . "AcDbEntity") '(100 . "AcDbXline") (cons 10 x) (cons 11 '(1 0 0))))) ptlst)
- )
- )
- )
- (vl-cmdf "_erase" line-en "")
- (vl-cmdf "_undo" "e")
- (setvar "CMDECHO" CMDECHO)
- (princ)
- )
|