水平有限,求助大神!!!
本帖最后由 suiran 于 2023-2-19 21:04 编辑程序运行时出现“Error: 类型不正确 - nil”错误,望大神给找找原因。搞了一天,头都大了:L
[*](defun c:recl( / ent dxf ptb i minymaxy minx maxx lengthx ss ptb0 ptb1)
[*](setvar "dimzin" 0)
[*](prompt "\n<<框选图元:>>")
[*](if (setq ss (ssget '((0 . "LWPOLYLINE,TEXT"))))
[*](progn
[*](repeat (setq i (sslength ss))
[*] (setq i (1- i))
[*] (setq ent (ssname ss i))
[*] (setq dxf (entget ent))
[*] (setq bianhao(cdr (assoc 1 dxf))) ;取编号
[*] (princ bianhao)
[*]
[*](setq ptb (mapcar 'cdr (vl-remove-if '(lambda(a)(/= (car a) 10)) dxf))) ;生成坐标值表
[*] (setq ptb (vl-sort ptb '(lambda(a b)
[*] (< (car a) (car b))))) ;坐标点按x轴从小到大排序
[*] (setq minx1 (car (car ptb))) ;生成x轴最小值
[*] (setq minx2 (car (cadr ptb))) ;生成x轴次小值
[*] (setq miny1 (cadr (car ptb))) ;生成x轴最小的Y值
[*] (setq miny2 (cadr (cadr ptb))) ;生成x轴次小的Y值
[*]
[*] (setq ptb (vl-sort ptb '(lambda(a b)
[*] (> (car a) (car b))))) ;坐标点按x轴从大到小排序
[*] (setq maxx3 (car (car ptb))) ;生成x轴最大值
[*] (setq maxx4 (car (cadr ptb))) ;生成x轴次大值
[*] (setq maxy3 (cadr (car ptb))) ;生成x轴最大的Y值
[*] (setq maxy4 (cadr (cadr ptb))) ;生成x轴次大的Y值
[*]
[*] (setq name (getvar "DWGName")) ;取文件名
[*] (setq lengthx (abs(- maxx3 minx1)));取绝对值生成最大长度
[*] (setq width1 (abs(- miny2 miny1)));取绝对值生成前宽
[*] (setq width2 (abs(- maxy4 maxy3)));取绝对值生成后宽
[*]
[*](princ name)
[*](princ width1)
[*](princ width2)
[*](princ lengthx)
[*]
[*](if (findfile "d:\\尺寸表.xls")
[*] (setq FF (open "d:\\尺寸表.xls" "a"))
[*] (progn(setq FF (open "d:\\尺寸表.xls" "w"))
[*] (write-line (strcat "图号" "\t"
[*] "编号" "\t"
[*] "前宽" "\t"
[*] "后宽" "\t"
[*] "图纸长度" "\r"
[*] )FF)))
[*]
[*](write-line (strcat name "\t"
[*] bianhao "\t"
[*] (rtos width1 2 2) "\t"
[*] (rtos width2 2 2) "\t"
[*] (rtos lengthx 2 2) "\r"
[*] )FF)
[*](close FF)
[*] )
[*] )
[*] )
[*](princ)
[*] )
(if (setq ss (ssget '((0 . "LWPOLYLINE,TEXT"))))
(progn (setq i (sslength ss))
(repeat (sslength ss)
(setq i (1- i))
liuhe 发表于 2023-2-19 16:12
(if (setq ss (ssget '((0 . "LWPOLYLINE,TEXT"))))
(progn (setq i (sslength ss))
(repeat ( ...
更改试了一下,还是不行呢 suiran 发表于 2023-2-19 18:44
更改试了一下,还是不行呢
你发图纸看qqqqqqqqqq 你的图形有两种图元,lw线条和text文字,文字只有一个(10 xy)点坐标,没办法求出width1、width2
所以一直报错。你需要把两种图元分开,其他的自己测试吧。 liuhe 发表于 2023-2-20 08:47
你的图形有两种图元,lw线条和text文字,文字只有一个(10 xy)点坐标,没办法求出width1、width2
所以 ...
哦,是这样啊,我明白了,知道原因就好改了。非常感谢! liuhe 发表于 2023-2-20 08:47
你的图形有两种图元,lw线条和text文字,文字只有一个(10 xy)点坐标,没办法求出width1、width2
所以 ...
请教一下,我想把每个图形的尺寸提取下来,包括文字,但是因为有2种图元,提取的数据类型老是错误,应该是逻辑不对,但是怎样修改才好呢?我能想到的是把2种图元分别提取,但是这样太麻烦了,有啥好方法?
(defun c:recl( / ent dxf ptb i minymaxy minx maxx lengthx ss ptb0 ptb1)
(setvar "dimzin" 0)
(prompt "\n<<框选图元:>>")
(setq ss (ssget '((0 . "LWPOLYLINE,*TEXT"))))
(progn
(repeat (setq i (sslength ss))
(setq i (1- i))
(setq ent (ssname ss i))
(setq dxf (entget ent))
(setq entype (cdr (assoc 0 dxf)))
(if (= entype "LWPOLYLINE")
(progn
(setq ptb (mapcar 'cdr (vl-remove-if '(lambda(a)(/= (car a) 10)) dxf))) ;生成坐标值表
(setq ptb (vl-sort ptb '(lambda(a b)
(< (car a) (car b))))) ;坐标点按x轴从小到大排序
(setq minx1 (car (car ptb))) ;生成x轴最小值
(setq minx2 (car (cadr ptb))) ;生成x轴次小值
(setq miny1 (cadr (car ptb))) ;生成x轴最小的Y值
(setq miny2 (cadr (cadr ptb))) ;生成x轴次小的Y值
(setq ptb (vl-sort ptb '(lambda(a b)
(> (car a) (car b))))) ;坐标点按x轴从大到小排序
(setq maxx3 (car (car ptb))) ;生成x轴最大值
(setq maxx4 (car (cadr ptb))) ;生成x轴次大值
(setq maxy3 (cadr (car ptb))) ;生成x轴最大的Y值
(setq maxy4 (cadr (cadr ptb))) ;生成x轴次大的Y值
(setq name (getvar "DWGName"))
(setq lengthx (abs(- maxx3 minx1)));取绝对值生成最大长度
(setq width1 (abs(- miny2 miny1)));取绝对值生成前宽
(setq width2 (abs(- maxy4 maxy3)));取绝对值生成后宽
(princ name)
(princ width1)
(princ width2)
(princ lengthx)
)
(progn(setq bianhao(cdr (assoc 1 dxf))) ;取编号
; (princ bianhao)
))
(if (findfile "d:\\尺寸表.xls")
(setq FF (open "d:\\尺寸表.xls" "a"))
(progn(setq FF (open "d:\\尺寸表.xls" "w"))
(write-line (strcat "图号" "\t"
"前宽" "\t"
"后宽" "\t"
"图纸长度" "\t"
"编号" "\r"
)FF)))
(write-line (strcat name "\t"
(rtos width1 2 2) "\t"
(rtos width2 2 2) "\t"
(rtos lengthx 2 2) "\t"
bianhao "\r"
)FF)
(close FF))
)
(princ)
) 由于你的文字图元和线条图元是有关联的,这两种图元如何产生关联你要清楚,通过这种关联,把关联的文字和线条分成一组,然后读取数据。而不是把图元简单分成两大类。这可能并不能实现你的目的
页:
[1]