CAD中 如何来自设置块的属性 及查找
现在有一个想法,就是在CAD里,设定每个块的属性。比如一个平面布置图,设置块得属性(如设备的大小)然后查找属于这个属性的数量有多少,比如这个平面图上有100个罐,现有5个5M3罐,通过一个命令或者方法,找出这5个罐,并处于选中状态。另,通过一个命令生成这个5M3罐的数量列表
最佳答案
回答者:网友
可以,请参考以下程序:
;*子程序:
;* 根据某一格式 FORMAT 中的第 N 项
;* 在 BP 点写 STR非还华音黑烧吧官台其ING
;*
(defun forwrt (bp str复还ing format n / for根来行未此检告危黑mat1 bpt)
(setq format1 (nth n format))
(cond ((= "M" (cadr format1))
(setq bpt (mapcar '+ bp (list (* 0.5 I1 (c环ar format1))
(* 0.5 width))))
(command "text" "m" bpt (* I1 (剂旧制余改止补田酒早nth 2 format1)) 0 string)
);cond -> 1
((= "L" (cadr format1))
(setq bpt (polar bp (* 0.25 pi) (* 3.0 I1)))
(command "text" bpt (* I1 (nth 2 format1)) 0 string)
);cond -> 2
);cond
);forwrt
;*
;*本程序用于自动生成材料表
;*使用 *.参城水镇MAT DQHEAD.DWG
;*1993.10.7-1993.10.11 W.Y.Z
;*
(defun c:element ( / olderr I1 format bass index temp templist
edata attval count first oneline chrct
maxs f numb malist width bp tbp )
;*初始化一些变量
(gc)
(modes '("cmdecho" "orthomode" "highlight"))
(setvar "cmdecho" 0)
(setvar "orthomode" 1)
(setvar "highlight" 0)
(setq olderr *error* *error* mye艺百川顾便注验rr I1 (getvar "use成ri1"))
(setq format '((180.0 9.0) (10.0 "M" 4.0) (45.0 "L" 4.0)
(65.0 "L" 4.0) (10.0 "M" 4.0) (10.0 "M" 4.0)
(40.0 "L" 4延调.0)))
;*得到带有属性的块的选择集 BASS
(setq bass (ssget "x" '((66 . 1) (0 . "INSERT") (8 . "0"))群乎提使议此的席重其))
;*把 BASS 转化成表
(if bass (progn
(setq index 0)
(repeat (s师鱼诉厚slength bass)
(setq temp (ssname bass inde绝读举维当x))
(setq templist (append templist (list temp)))
(setq index (1+ index))
);repeat
(setq bass templist)
;*统计属性名为 "E按所三齐注得随超复始量LEMENT" 的块各自异或亲场致说硫江于客等的数量
(foreach item bass
(setq ed持正上结见甲直ata (entget (entnext item)))
(if (and (= (dxf 2 edata) "ELEMENT")
(= (dxf 0 edata) "ATTRIB" )
(/= (dxf 1 edata) "" ));and
(progn
(setq attval (strcat "*" (strcase (dxf 1 edata))))
(if (assoc attval count)
(progn
(setq temp (assoc attval count))
(setq count (subst (cons attval (1+ (cdr temp)))
temp count))
);progn
(setq count (append count (list (cons attval 1))))
);if-assoc
);progn
);if-and
);foreach
));if-bass-progn
;*根据 COUNT 中的关键字,在 DQ.MAT 中查出
;*与关键字有关的参数形成 MALIST
(setq numb 1)
(if (findfile "DQ.MAT")
(progn ;***
(setq f (open "DQ.MAT" "r"))
(while (and (setq first (read-line f)) count)
(if (assoc first count)
;*把 FIRST 后一行的参数读入 TEMPLIST 中
(progn ;**
(setq oneline (read-line f)
maxs (strlen oneline)
templist nil
index 1 chrct 0
);setq
(while (<= index maxs)
(if (/= "," (substr oneline index 1))
(setq chrct (1+ chrct))
(setq temp (substr oneline (- index chrct) chrct)
templist (append templist (list temp))
chrct 0
);setq
);if-/=
(setq index (1+ index))
);while-<=
(setq temp (substr oneline (- index chrct) chrct)
templist (append templist
(list (itoa (cdr (assoc first count))))
(list temp));append
);setq
;*把 TEMPLIST 合入 MALIST
(setq templist (append (list (itoa numb)) templist)
malist (append malist (list templist))
numb (1+ numb)
);setq
;*在 COUNT 中消去 FIRST
(setq count (cdr (subst (car count)
(assoc first count) count)))
);progn **
;*若无则换行
(read-line f)
);if-assoc
);while-and
;*关闭 DQ.MAT
(close f)
;*判断 COUNT 是否为空
(if count
(foreach item count
(setq temp (car item))
(princ "\n")
(princ (substr temp 2))
(princ " 代号所标识的材料未找到.")
);foreach
(if attval (princ "\n全部代号所标识的材料都找到!"))
);if-count
);progn ***
(princ "\n未找到 DQ.MAT.")
);if-findfile
;*写材料
(if malist
(progn ;***
(setq width (* I1 (cadar format)))
(setvar "osmode" 512)
(initget 1)
(setq temp (getpoint "\n捕捉右边内框上一点 near to ..."))
(setvar "osmode" 0)
(command "insert" "dqhead" temp I1 "" "" )
(setq bp (polar temp pi (* I1 (caar format))))
;*画表格横线
(setq numb (+ 5 (* (/ (length malist) 5) 5)))
(command "line" (polar bp (* 1.5 pi) width)
(polar temp (* 1.5 pi) width)
""
);command-line
(command "array" (entlast) "" "r" numb 1 (- width))
;*画表格竖线
(setq tbp bp)
(foreach item (cdr format)
(command "pline" tbp (polar tbp (* 1.5 pi) (* numb width)) "")
(setq tbp (polar tbp 0 (* I1 (car item))))
);foreach
;*添材料表
(setq bp (polar bp (* 1.5 pi) width))
(foreach item malist
(setq tbp bp index 1)
(foreach item1 item
(forwrt tbp item1 format index)
(setq tbp (polar tbp 0 (* I1 (car (nth index format)))))
(setq index (1+ index))
);foreach-item1
(setq bp (polar bp (* 1.5 pi) width))
);foreach-item
);progn-***
(princ "\n无材料可添.")
);if-malist
;*把 MALIST 写入文件
;
;
;
;*恢复设置
(moder)
(setq *error* olderr)
(princ)
);*c:element