Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hi all, here are some dynamic block and i would like to count them, these blocks have linear parameter and linear stretch, attri label XX is their own name. i tried with this program and it can't get the length of stretch distrance
(defun c:CT (/ ss blocks attrTag attrValue attrList countTable resultTable acadDoc modelSpace tableInsertionPoint table inputValue)
;; 设置属性标签
(setq attrTag "XX")
;; 获取用户输入的通配符值
(setq inputValue (getstring "\n请输入属性值的通配符(例如T4*): "))
;; 选择所有包含属性标签为XX的块
(prompt "\n选择包含属性标签为XX的块: ")
(setq ss (ssget '((0 . "INSERT") (66 . 1))))
(if ss
(progn
;; 初始化属性值列表
(setq attrList '())
;; 遍历选择的块
(setq i 0)
(while (< i (sslength ss))
(setq ent (ssname ss i))
(setq entData (entget ent))
;; 获取块的属性
(setq attEnt (entnext ent))
(setq distance1 nil)
(while (and attEnt (/= (cdr (assoc 0 (entget attEnt))) "SEQEND"))
(setq attData (entget attEnt))
(if (= (cdr (assoc 2 attData)) attrTag)
(progn
(setq attrValue (cdr (assoc 1 attData)))
;; 检查属性值是否符合通配符
(if (wcmatch attrValue inputValue)
(progn
;; getting linear para distance(assume that attribute label is 'distance1')
(setq distance1 (cdr (assoc 1 (entget (entnext ent)))))
(setq attrList (cons (list attrValue distance1) attrList))
)
)
)
)
(setq attEnt (entnext attEnt))
)
(setq i (1+ i))
)
;; Count the number of blocks with the same attribute value and linear parameter distance
(setq countTable '())
(foreach attrPair attrList
(setq attrValue (car attrPair))
(setq distance1 (cadr attrPair))
(setq found nil)
(foreach item countTable
(if (and (equal (car item) attrValue) (equal (cadr item) distance1))
(progn
(setq found t)
(setq countTable (subst (list attrValue distance1 (1+ (caddr item))) item countTable))
)
)
)
(if (not found)
(setq countTable (cons (list attrValue distance1 1) countTable))
)
)
;; 获取当前文档和模型空间
(setq acadDoc (vla-get-activedocument (vlax-get-acad-object)))
(setq modelSpace (vla-get-modelspace acadDoc))
;; setting insert point for sheet
(setq tableInsertionPoint (getpoint "\n指定表格插入点: ")) ;;select insert point
(if (not tableInsertionPoint)
(setq tableInsertionPoint '(0 0 0)) ; 默认插入点为原点
)
;; create sheet
(setq table (vla-addtable modelSpace
(vlax-3d-point tableInsertionPoint)
(+ (length countTable) 2) ; 行数(属性值数量 + 表头)
3 ; 列数(属性值、数量和线性参数距离)
450.0 ; 行高
1700.0)) ; 列宽
;; setting sheet title
(vla-settext table 0 0 "动态块统计")
(vla-setcelltextheight table 0 0 100) ; 标题文字高度
(vla-setcelltextstyle table 0 0 "LPA") ; 标题文字样式
;; setting sheet head
(vla-settext table 1 0 "属性值")
(vla-settext table 1 1 "数量")
(vla-settext table 1 2 "线性参数距离")
(vla-setcelltextheight table 1 0 100) ; 表头文字高度
(vla-setcelltextheight table 1 1 100)
(vla-setcelltextheight table 1 2 100)
(vla-setcelltextstyle table 1 0 "LPA") ; 表头文字样式
(vla-setcelltextstyle table 1 1 "LPA")
(vla-setcelltextstyle table 1 2 "LPA")
;; about filling data to sheet
(setq row 2)
(foreach item countTable
(vla-settext table row 0 (car item)) ; 属性值
(vla-settext table row 1 (itoa (caddr item))) ; 数量
(vla-settext table row 2 (cadr item)) ; 线性参数距离
(vla-setcelltextheight table row 0 100) ; 数据文字高度
(vla-setcelltextheight table row 1 100)
(vla-setcelltextheight table row 2 100)
(vla-setcelltextstyle table row 0 "LPA") ; 数据文字样式
(vla-setcelltextstyle table row 1 "LPA")
(vla-setcelltextstyle table row 2 "LPA")
(setq row (1+ row))
)
;; 提示完成
(princ "\n表格已创建并插入到图形中。") ;;sheet has inserted to the drawing
)
(princ "\n未选择任何块。") ;;doesn't selected any block
)
(princ)
)
in my exception, the third colume should show me the distance i stretch the block, value can't be see in here:
so my problem is :
1. how to get the value i need? i tried vlax-get-propety but return error
2. how to modify the program to function as I expected
Solved! Go to Solution.