明细表汇总中零件数量统计
本帖最后由 xianaihua 于 2011-11-2 17:17 编辑在机械设计中,将大量的图纸的明细表各属性统计成数据文件(txt、mdb、xls)后,各零部件数量、重量的统计,特别是数量的统计,是很麻烦的事。本人通过摸索,用递归的方法解决了这一问题。
统计方法:先找出该零件代号在父装配中的数量,再找出父装配在更上一级父装配中数量。。。,以此类推,直到查询到最顶级装配,最后,将这些数量相乘,便得出该零部件的总数量。
首先将提取的明细表数据构建一个列表(在本例中,本人只列出了三个)
;;;bomlst:是通过一些方法获得的零部件明细表列表(具体方法在此不作讨论)
;;;其中每行的第一列为零部件代号;
;;; 第二列为零部件所属装配代号;
;;; 第三列为零部件在所属装配中的数量;
(setq bomlst '(
("sub-assembly1-1" "assembly" "2")
("sub-assembly1-2" "assembly" "3")
("sub-assembly1-3" "assembly" "1")
("pat1-1" "assembly" "3")
("pat1-2" "assembly" "2")
("pat1-3" "assembly" "5")
("sub-assembly2-1" "sub-assembly1-1" "2")
("sub-assembly2-2" "sub-assembly1-1" "2")
("sub-assembly2-3" "sub-assembly1-1" "4")
("pat2-1" "sub-assembly1-1" "3")
("pat2-2" "sub-assembly1-2" "4")
("pat1-3" "sub-assembly1-1" "2")
("pat3-1" "sub-assembly1-3" "2")
("pat3-2" "sub-assembly1-3" "3")
("pat2-1" "sub-assembly1-2" "1")
("none" "sub-assembly2-2" "3")
("none" "sub-assembly2-1" "3")
)
)
通过运行程序会得到这样的结果(保存到txt文件中)
("sub-assembly1-1" "assembly" "2" "2")
("sub-assembly1-2" "assembly" "3" "3")
("sub-assembly1-3" "assembly" "1" "1")
("pat1-1" "assembly" "3" "3")
("pat1-2" "assembly" "2" "2")
("pat1-3" "assembly" "5" "5")
("sub-assembly2-1" "sub-assembly1-1" "2" "4")
("sub-assembly2-2" "sub-assembly1-1" "2" "4")
("sub-assembly2-3" "sub-assembly1-1" "4" "8")
("pat2-1" "sub-assembly1-1" "3" "6")
("pat2-2" "sub-assembly1-2" "4" "12")
("pat1-3" "sub-assembly1-1" "2" "4")
("pat3-1" "sub-assembly1-3" "2" "2")
("pat3-2" "sub-assembly1-3" "3" "3")
("pat2-1" "sub-assembly1-2" "1" "3")
("none" "sub-assembly2-2" "3" "12")
("none" "sub-assembly2-1" "3" "12")
其中第四项为统计的每个零部件的重数量。
大佬,弄个动态图看看效果
学习了好好研究下 学习了好好研究下 对这类表处理感兴趣,顶一下,没有明经币下不了 你到东东 支持中 不错的例子 请教了俄罗斯高手:ElpanovEvgeniy 后源程序大大简化,速度极快
(defun SumPartCounts (bom_lst / f)
(defun f (a bom_lst)
(if a
(* (atoi (caddr a)) (f (assoc (cadr a) bom_lst) bom_lst))
1
) ;_ 结束if
) ;_ 结束defun
(mapcar (function (lambda (a) (itoa (f a bom_lst))))
bom_lst
) ;_ 结束mapcar
) ;_ 结束defun(setq bomlst '(
("sub-assembly1-1" "assembly" "2")
("sub-assembly1-2" "assembly" "3")
("sub-assembly1-3" "assembly" "1")
("pat1-1" "assembly" "3")
("pat1-2" "assembly" "2")
("pat1-3" "assembly" "5")
("sub-assembly2-1" "sub-assembly1-1" "2")
("sub-assembly2-2" "sub-assembly1-1" "2")
("sub-assembly2-3" "sub-assembly1-1" "4")
("pat2-1" "sub-assembly1-1" "3")
("pat2-2" "sub-assembly1-2" "4")
("pat1-3" "sub-assembly1-1" "2")
("pat3-1" "sub-assembly1-3" "2")
("pat3-2" "sub-assembly1-3" "3")
("pat2-1" "sub-assembly1-2" "1")
("none" "sub-assembly2-2" "3")
("none" "sub-assembly2-1" "3")
)
) ;_ 结束setq
(SumPartCounts bomlst);=>("2" "3" "1" "3" "2" "5" "4" "4" "8" "6" "12" "4" "2" "3" "3" "12" "12")
收藏了,等有了明经币再下 最近忙了点
收藏了,
等有了空了再下
留个脚板印吧,还看不懂 留个言,以后再学习吧 学习了好好研究下