- 积分
- 7721
- 明经币
- 个
- 注册时间
- 2011-7-29
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
现在本人的想法是:能否在标高后面加多一项标识,即格式如下: “1,X1,100.12,200.12,10.30”;“2,X1,300.12,400.12,20.30”,其中X1的作用就是能让lisp程序知道这两个点要连成一条直线,当然连第二条直线就得用 X2等等依些类,第N条直线就用XN以下程序第一次运行时出现错误,第二次运行就正常了,希望高手帮忙解决,同时希望高手在此程序上添加此功能,X1形成的线放在一个属性层里,X2形成的线放在一个属性层里、Xn形成的线放在一个属性层里,谢谢了
;;;主程序开始
(defun c:test () ;_这里的函数名:test 你自己改一下
(setq laylist '("clayer" "属性层")) ;图层列表
(setq n 0)
(while (setq lay (nth n laylist)) ;如果 lay 不为 nil 则进行循环
(mla lay 1) ;创建图层
(setq n (1+ n))
)
(setq xianhao (getint "\n输入一个基准线号(整数):"))
(if (and (setq file (getfiled "选择文件" "" "*" 8)))
(SETQ F_ID (open file "r"))
)
(setq lay (getvar "clayer"));_获取当前层,
(setq os (getvar "osmode"))
(setvar "cmdecho" 0)
(setvar "clayer" "属性层");_设置"属性层"为当前层,如果"属性层"冻结状态会影响程序
(setvar "osmode" 0)
(setq xx nil)
(while (SETQ text0 (READ-LINE F_ID))
(setq n (vl-string-position (ascii ",") text0))
(setq n0 (vl-string-position (ascii ",") text0 (1+ n)))
(setq n1 (vl-string-position (ascii ",") text0 (1+ n0)))
(setq n2 (vl-string-position (ascii ",") text0 (1+ n1)))
(setq xh (substr text0 1 n)
XX0 (substr text0 (+ n 2) (- n0 (1+ n)))
x (atof (substr text0 (+ n0 2) (- n1 (1+ n0))))
y (atof (substr text0 (+ n1 2) (- n2 (1+ n1))))
p0 (list x y)
p1 (list (- (car p0) 0.38) (- (cadr p0) 0.13))
p2 (list (+ (car p0) 0.26) (- (cadr p0) 0.24))
p3 (polar p0 pi 0.02)
p4 (polar p0 0 0.02)
bg (substr text0 (+ n2 2))
)
(setq text1 (list '(0 . "TEXT")
'(100 . "AcDbEntity")
'(67 . 0)
'(8 . "ZDH")
(cons 10 p1)
'(40 . 0.2)
(cons 1 xh)
)
)
(setq text2 (list '(0 . "TEXT")
'(100 . "AcDbEntity")
'(67 . 0)
'(8 . "GCD")
(cons 10 p2)
'(40 . 0.4)
(cons 1 bg)
)
)
(setq dount (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(67 . 0)
'(8 . "GCD")
'(100 . "AcDbPolyline")
'(90 . 2)
'(70 . 129)
'(43 . 0.5)
'(38 . 0.0)
'(39 . 0.0)
(cons 10 p3)
'(40 . 0.5)
'(41 . 0.5)
'(42 . 1.0)
(cons 10 p4)
'(40 . 0.5)
'(41 . 0.5)
'(42 . 1.0)
'(210 0.0 0.0 1.0)
)
)
(entmake text1)
(entmake text2)
(entmake dount)
(if (/= xx0 xx) ;_if_1
(progn ;_progn_1
(if (/= xx nil)
(progn ;_progn_3
(command "")
(make_xianhao text-sp front-p0)
(setq xianhao (1+ xianhao))
) ;_end_progn_3
)
(command "pline" p0)
) ;_end_progn_1
(progn ;_progn_2
(command p0)
(setq front-p0 p0)
) ;_end_progn_2
) ;_end_if_1
(setq xx xx0)
)
(command "")
(make_xianhao text-sp front-p0)
(CLOSE F_ID)
(setvar "clayer" lay)
(setvar "osmode" os)
(setvar "cmdecho" 1)
(prompt "欢迎使用自动绘图程序")
(princ)
) ;_主程序结束
;;;获取多义线指定顶点坐标
(defun get-point (obj n)
(setq point-00 (vlax-safearray->list
(vlax-variant-value
(vla-get-coordinate obj n)
)
)
)
point-00
)
;;;;获取多义线顶点总数的一半值
(defun point-number (obj)
(setq data0 (vla-get-coordinates obj))
(setq data0 (vlax-safearray->list
(vlax-variant-value (vla-get-coordinates obj))
)
)
(setq k (length data0))
(setq k (fix (/ k 4)))
k
)
;;;创建如302、303的线号子程序
(defun make_xianhao (text-sp front-p0)
(setq ss (ssget "c"
front-p0
front-p0
'((0 . "LWPOLYLINE") (40 . 0.0))
)
)
;;(if (/= ss nil)
;; (progn;_progn_4
(setq obj (vlax-ename->vla-object (ssname ss 0)))
(setq number1 (point-number obj))
(setq number (1- number1))
(setq point-1 (get-point obj number))
(setq point-2 (get-point obj number1))
(setq ang (angle point-1 point-2)
p5 (polar point-1
ang
(/ (distance point-1 point-2) 2)
)
text-sp (polar p5 (- ang (* pi 0.5)) 0.2)
)
(setq text3 (list '(0 . "TEXT")
'(100 . "AcDbEntity")
'(67 . 0)
'(8 . "属性层")
'(100 . "AcDbText")
(cons 10 text-sp)
'(40 . 0.4)
(cons 1 (rtos xianhao 2 0))
(cons 50 ang)
'(41 . 0.8)
'(7 . "HZ")
)
)
(entmake text3)
)
(defun Mla (W_Lname W_Color / W_layer)
(setq W_layer (tblsearch "layer" W_Lname))
(if (= nil W_layer)
(command "_.layer" "m" W_Lname "c" W_Color "" "")
)
(if (/= (getvar "clayer") W_Lname)
(command "_.layer" "t" W_Lname "s" W_Lname "c" W_Color "" "")
)
(if (= (getvar "clayer") W_Lname)
(command "_.layer" "s" W_Lname "c" W_Color "" "")
)
(prin1)
)
测试数据
61,X1,-17.614,664.042,-2.29
62,X1,-12.384,662.55,-2.72
63,X1,-6.218,661.201,-2.67
64,X1,0.611,660.612,-1.51
65,X1,2.778,661.556,1.09
66,X2,-19.45,662.51,-3.85
67,X2,-17.614,659.946,-2.46
68,X2,-12.384,658.454,-2.18
69,X2,-8.565,654.5465,-2.71
70,X2,-1.736,653.958,-1.92
71,X2,0.431,654.902,2.09
|
|