www.pudn.com > CADtool.rar > XY.LSP, change:2008-10-19,size:5392b


(vl-load-com) 
;;;------------------------------------------------------------- 
;;;************* write  x,y  to dwg 
(defun c:xy (/        ht       le       ll       ly       w        OblN     bzZiXingPinXin 
             agText   a1       b1       c1       d1       xStr     yStr     pp       p1 
             p2       p3       p4       strL1    strL2    bzWorldXY         ptWorldXY 
             ptWorldX ptWorldY 
            ) 
  (defun GetTextAngle (Pt / agPtpPt) 
    ;;获得某点处曲线的切线角度(-90~90度) 
    (setq pPt (vlax-curve-getClosestPointTo OblN Pt T)) 
    ;; 取得一点与曲线的垂足坐标 
    (setq agPtpPt (+ (angle pPt Pt) (/ pi 2))) 
    (setq agPtpPt (if 
                    (< (/ pi 2) agPtpPt (* pi 1.5)) 
                     (- agPtpPt pi) 
                     agPtpPt 
                  ) 
    ) 
    ;;把斜率调整为-pi/2~pi/2	 
    agPtpPt 
  ) ;_ 结束defun 
;;;======================================= 
  (defun GetChanKaoXian (/ nob obl) ;取得需要字线平等的线名称 
    (setq nob 2) 
 
    (while (> nob 1) 
      (princ "\n选择需要字线平行的线(只能选择一条线):") 
      (setq obl (ssget '((0 . "*line,arc")))) ; 创建选择集 obl 
      (setq nob (sslength obl)) 
    ) 
 
    (if (= nob 1) 
      (setq OblN (ssname obl 0)) ; OblN,取得需要字线平等的线名称 
      (setq OblN nil) 
    ) 
  ) 
;;;======================================= 
  (defun initTextF (/ pt str eTextN) 
    (setq pt (list 0 0)) 
    (setq str "初始化") 
    (command "text" pt ht 0 str) 
    (setq eTextN (entlast)) 
    (entdel eTextN) 
  ) ;_ 结束defun 
;;;以当前设置初始化文本高、宽 
;;;======================================= 
  (setvar "cmdecho" 0) 
 
  (setq ht (if (setq ht (getreal "\n输入字高(2.5mm):")) 
             ht 
             2.5 
           ) 
  ) 
  (if (<= ht 0) 
    (setq cdbl 2.5) 
  ) 
  (setq ll (/ ht 3)) 
  (setvar "osmode" 431) 
 
  (initTextF) 
 
  (setq bzZiXingPinXin "No") ; 默认标注文字不需要字线平行 
 
  (initget "W U _WCS UCS ") 
  (setq 
    bzWorldXY (if (setq bzWorldXY (getkword 
                                    "\n标注点在哪个坐标系下的坐标[世界坐标系(W)/当前坐标系(U)]<W>:" 
                                  ) 
                  ) 
                bzWorldXY 
                "WCS" 
              ) 
  )       ;默认标注世界坐标 
 
  (initget "S") 
  (setq p1 (getpoint "\n选择要标注的点[设置标注文字与特定线平行(S)]:")) 
  (while p1 
    (cond 
      ((listp p1) 
       (if (setq p2 (getpoint p1 "\n选择标注文字的位置:")) 
         (progn 
           (setq a1 (car p1) 
                 b1 (cadr p1) 
                 c1 (car p2) 
                 d1 (cadr p2) 
           ) 
 
           (if (= bzWorldXY "WCS") 
             (progn 
               (setq ptWorldXY (trans p1 1 0)) 
               (setq ptWorldX (car ptWorldXY) 
                     ptWorldY (cadr ptWorldXY) 
               ) 
 
               (setq xStr (strcat "X=" (rtos ptWorldY 2 3)) 
                     yStr (strcat "Y=" (rtos ptWorldX 2 3)) 
               ) 
             ) ;标注世界坐标 
 
             (setq xStr (strcat "X=" (rtos b1 2 3)) 
                   yStr (strcat "Y=" (rtos a1 2 3)) 
             ) 
           ) 
 
           (setvar "osmode" 0) 
 
           (setq le (strLength xStr) 
                 ly (strLength yStr) 
           ) 
           (if (< le ly) 
             (setq le ly) 
           ) 
           ;;确定x,y坐标分隔线长度 
 
           (if (= bzZiXingPinXin "Yes")              
             (setq agText (GetTextAngle (trans p2 1 0))) 
             (setq agText 0) 
           ) 
           ;;确定标注文字角度 
 
           (if (< c1 a1) 
             (setq pp (polar p2 (+ agText pi) le) 
                   p3 (polar pp (+ agText (/ pi 2)) ll) 
                   p4 (polar pp (+ agText (/ pi -2)) (+ ll ht)) 
             ) 
             (setq pp (polar p2 agText le) 
                   p3 (polar p2 (+ agText (/ pi 2)) ll) 
                   p4 (polar p2 (+ agText (/ pi -2)) (+ ll ht)) 
             ) 
           ) 
           (command "line" p1 p2 pp "") 
 
           (setq agText (/ (* agText 180) pi)) 
           ;;把斜率为转为角度制 
 
           (command "text" p3 ht agText xStr) 
           (command "text" p4 ht agText yStr) 
           (setvar "osmode" 431) 
 
           (if (= bzZiXingPinXin "Yes") 
             (progn 
               (initget "C") 
               (setq p1 (getpoint "\n选择要标注的点[取消标注文字与线平行设置(C)]:")) 
             ) 
             (progn 
               (initget "S") 
               (setq p1 (getpoint "\n选择要标注的点[设置标注文字与特定线平行(S)]:")) 
             ) 
           ) 
         ) 
 
         (setq p1 nil) 
       ) 
      ) 
      ((= p1 "S") 
       (GetChanKaoXian) 
       (if OblN 
         (progn 
           (setq bzZiXingPinXin "Yes") 
           (initget "C") 
           (setq p1 (getpoint "\n选择要标注的点[取消标注文字与线平行设置(C)]:")) 
         ) 
         (progn 
           (setq bzZiXingPinXin "No") 
           (initget "S") 
           (setq p1 (getpoint "\n选择要标注的点[设置标注文字与特定线平行(S)]:")) 
         ) 
       ) 
      ) 
      ((= p1 "C") 
       (setq bzZiXingPinXin "No") 
       (initget "S") 
       (setq p1 (getpoint "\n选择要标注的点[设置标注文字与特定线平行(S)]:")) 
      ) 
      (T (setq p1 nil)) 
    ) 
  ) 
  (setvar "osmode" 431) 
  (princ) 
) 
;;;-------------------------------------------------------------