明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1933|回复: 9

问一个关于图块操作的问题

[复制链接]
发表于 2005-5-30 17:45:00 | 显示全部楼层 |阅读模式
cad图中有几个块(n1         n2                 n3                         n4)我想按这个顺序把四个图块的插入点输出到文件中,请飞哥及各位高手指点一下
发表于 2005-5-31 00:10:00 | 显示全部楼层
不知道你是要图块的定义点还是图形中快的插入点,给你编了个小程序,是按插入点提取的。 (defun c:ExporBlktInsPnt (/ en sset fOpen InsPnt EachBlk BlkList ExportFile)
(setq ExportFile (strcat (getvar "dwgprefix") "BlktInsPnt.txt");路径自己定,这里只是个例子
BlkList (list "nmxl0" "nmxl1" "nmxl2_en" "btl0-2_en");块名列表,这里只是个例子
)
(foreach EachBlk BlkList
(setq Index 0
sset (ssget "X" (list '(0 . "insert") (cons 2 EachBlk)))
)
(if sset
(repeat (sslength sset)
(setq en (ssname sset index)
index (1+ index)
)
(if (not fOpen)
(setq fOpen (open ExportFile "w"))
)
(setq InsPnt (cdr(assoc 10 (entget en))))
(princ (car InsPnt ) fopen)
(princ "," fopen)
(princ (cadr InsPnt ) fopen)
(princ "," fopen)
(princ (caddr InsPnt ) fopen)
(princ "\n" fopen)
)
)
)
(if fOpen
(close fopen)
)
(princ)
)
发表于 2005-5-31 08:39:00 | 显示全部楼层
什么叫按顺序?按谁的顺序?
 楼主| 发表于 2005-5-31 08:40:00 | 显示全部楼层
楼上的代码我看了,对于给定的几个块可以实现,但我想实现的功能是对屏幕上某一层内的所有块从左到右依次把插入点输出到文件中,还有没有别的办法,谢谢
发表于 2005-5-31 08:43:00 | 显示全部楼层
又是一个不愿意一次性把要求说清楚的,楼顶说按顺序,现在又说屏幕上某一层内,不知道还有什么其他的。。。2楼的工夫算白费了。。。
 楼主| 发表于 2005-5-31 10:03:00 | 显示全部楼层
不好意思,开始没有表达清楚,我想把断面图内的桩位(是画在桩位层 中的)从左到右的顺序输出到文件中


国语学的太差,多包含,不知道有没有表达清楚?
发表于 2005-5-31 20:49:00 | 显示全部楼层
本帖最后由 作者 于 2005-5-31 21:11:11 编辑

什么叫做从左到右输出?请说清楚点,我不想猜谜语,下面这个程序是按插入点的X坐标从小到大输出,以下程序没有考虑容错,请自己解决。 (defun c:ExporBlktInsPnt (/ en sset fOpen
layers BlkLayer EachLayer InsPnt
ExportFile InsList
)
(defun ai_table1 (table_name bit / tbldata table_list just_name)
(setq tbldata nil)
(setq table_list '())
(setq table_name (xstrcase table_name))
(while (setq tbldata (tblnext table_name (not tbldata)))
(setq just_name (cdr (assoc 2 tbldata)))
(cond
((= "" just_name)) ; Never return null Shape names.
((and (= 1 (logand bit 1))
(or (and (= table_name "LAYER") (= just_name "0"))
(and (= table_name "LTYPE")
(= just_name "CONTINUOUS")
)
)
)
)
((and (= 2 (logand bit 2))
(= table_name "BLOCK")
(= 1 (logand 1 (cdr (assoc 70 tbldata))))
)
)
((and (= 4 (logand bit 4))
;; Check for Xref dependents only.
(zerop (logand 4 (cdr (assoc 70 tbldata))))
(not (zerop (logand 48 (cdr (assoc 70 tbldata))))) )
)
((and (= 8 (logand bit 8))
(not (zerop (logand 4 (cdr (assoc 70 tbldata)))))
)
)
;; Vports tables can have similar names, only display one.
((member just_name table_list)
)
(T (setq table_list (cons just_name table_list)))
)
)
(cond
((and (= 16 (logand bit 16))
(= table_name "LTYPE")
)
(setq table_list
(cons "BYBLOCK"
(cons "BYLAYER" table_list)
)
)
)
(t)
)
table_list
) ;end defun (defun SortList
(Blist / i j len num1 num2 Temp NumList AtomList SortedList)
(if (listp Blist)
(progn
(setq len (length Blist))
(if (> len 1)
(progn
(foreach AtomList Blist
(setq NumList (cons (car AtomList) NumList))
)
(setq i 0
Temp "temp"
NumList (reverse NumList)
)
(repeat (1- len)
(setq j 0)
(while (< j (- len i 1))
(setq num1 (nth j NumList)
num2 (nth (1+ j) NumList)
)
(if (< num2 num1)
(setq NumList (subst Temp num2 NumList)
NumList (subst num2 num1 NumList)
NumList (subst num1 Temp NumList)
)
)
(setq j (1+ j))
)
(setq i (1+ i))
)
(setq i 0)
(repeat len
(setq SortedList
(cons (assoc (nth i NumList) Blist) SortedList)
)
(setq i (1+ i))
)
(setq SortedList (reverse SortedList))
)
(setq SortedList Blist)
)
)
)
SortedList
)
;;===========主函数部分==============
(setq layers (ai_table1 "layer" 2))
(print "当前所有层:")
(foreach EachLayer (acad_strlsort layers)
(print EachLayer)
)
(setq BlkLayer (getstring "\n请从上述层中指定一个层:"))
(if (and BlkLayer (member BlkLayer layers))
(progn
(setq ExportFile (strcat (getvar "dwgprefix") "BlktInsPnt.txt")
;路径自己定,这里只是个例子
Index 0
sset (ssget "X" (list '(0 . "insert") (cons 8 BlkLayer)))
)
(if sset
(repeat (sslength sset)
(setq en (ssname sset index)
index (1+ index)
)
(setq InsList (cons (cdr (assoc 10 (entget en))) InsList))
)
)
(setq InsList (SortList InsList)
index 0
) (if (not fOpen)
(setq fOpen (open ExportFile "w"))
)
(foreach InsPnt InsList
(princ (car InsPnt) fopen)
(princ "," fopen)
(princ (cadr InsPnt) fopen)
(princ "," fopen)
(princ (caddr InsPnt) fopen)
(princ "\n" fopen)
)
(if fOpen
(close fopen)
)
)
)
(princ)
)
发表于 2005-5-31 21:53:00 | 显示全部楼层
请教


sset        (ssget "X" (list '(0 . "insert") (cons 2 EachBlk)))


的意思
 楼主| 发表于 2005-6-1 09:21:00 | 显示全部楼层
对,就是按照X坐标从小到大输出,谢谢先,回去研究一下代码
 楼主| 发表于 2005-6-1 11:27:00 | 显示全部楼层
本帖最后由 作者 于 2005-6-1 15:38:58 编辑

。 。 (setq SortedList Blist)
)
)
)
SortedList
)
为什么加(setq SortedList Blist)这句,好像不对吧 再问一个问题(xstrcase table_name)是什么意思?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-17 10:33 , Processed in 0.188807 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表