;自动添加开孔号 ;若开孔号形如1、2、3……不带下标,程序可自动添加序号 ;若带有下标,则需形如1-2、2-2、3.1-4……的输入 ;本程序中用到了系统变量users1和useri1,请确保您使用的 ;其他二次开发的程序中没有引用这两项,再使用本程序。 ;made by 铁甲蚂蚁 (defun c:cn (/ pt1 pt2 pt ang pts txt) (vl-load-com) (setvar "cmdecho" 0) (setq pt1 (getpoint "\n指定直线端起点:\n")) (if (not pt1) (vl-exit-with-error "")) (setq pt2 (getpoint pt1 "\n指定直线端终点:\n")) (if (not pt2) (vl-exit-with-error "")) (setq ang (angle pt1 pt2)) (setq pt (list (* (cos ang) 5) (* (sin ang) 5) 0.0)) (setq pt (mapcar '+ pt pt2)) (setq pts (cons pt (read (getvar "users1")))) (setvar "users1" (vl-prin1-to-string pts)) (setvar "osmode" 0) (if (not (vl-string-search (vl-prin1-to-string pt1) (getvar "users1"))) (command "line" pt1 pt2 "") ) (command "circle" pt 5) (setq txt (getstring "输入开孔号:")) (setq txt (transcat_text txt)) (command "mtext" pt "j" "mc" "h" 5.5 pt txt "") (setvar "osmode" 247) (prin1) ) (defun transcat_text (txt / n) (if (or (= (ascii txt) 45) (= (ascii txt) 46)) (setq txt (strcat (itoa (getvar "useri1")) txt)) ) (if (/= txt "") (if (setq n (vl-string-position 46 txt)) ;(ascii ".")=46 (progn (setvar "useri1" (atoi (substr txt 1 n))) (setq txt (strcat "\\A;" (substr txt 1 n) "{\\H0.5x;\\S^" (substr txt (+ n 2)) ";}" ) ) ) (if (setq n (vl-string-position 45 txt)) ;(ascii "-")=45 (progn (setvar "useri1" (atoi (substr txt 1 n))) (setq txt (strcat "\\A;" (substr txt 1 n) "{\\H0.5x;\\S^" (substr txt (1+ n)) ";}" ) ) ) (setvar "useri1" (atoi txt)) ) ) (progn (setq txt (itoa (1+ (getvar "useri1")))) (setvar "useri1" (atoi txt)) ) ) )
|