明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 15530|回复: 47

[基础] 分享,属性块图框编辑,再次更新,加一键生成BOM

    [复制链接]
发表于 2013-6-21 22:32 | 显示全部楼层 |阅读模式
本帖最后由 邹锋 于 2013-6-24 12:39 编辑

最近看别人搞LSP反编译挺火的,呵呵,所以哪,自己有好程序也不敢 藏着 捏着,所以发布源码了,这个星期写了个图框属性块,呵呵,很基础的,以前根本没接触过块这方面的,这些代码都是论坛找的,我只是凑在一起,附件是我公司的图框,常用字符,等等,适合搞模具的吧,强大的软件,我不会,只能做些小东西了,这程序还可以进一步完善的,怎么优化它有,高手们有空,优化下,你要是币多,给个吧难得放源码

(defun c:BTL()
  (getatt)
  (setvar "cmdecho" 0)
  (setlist)
  (dcl_bomdcl)
  (prin1)
)


(defun getatt ()
  (setq en (car (entsel "选择块")))
  (setq xobj2 (vlax-ename->vla-object en))
  (vlax-get-property xobj2 'hasAttributes)
  (setq xvar (vla-GetAttributes xobj2))
  (setq svar (vlax-variant-value xvar))
  (setq att_obj_list (vlax-safearray->list svar))
  (setq attobj1 (nth 0 att_obj_list))
  (setq tag1 (vla-get-tagstring attobj1))
  (setq text1 (vla-get-textstring attobj1))
  
  (setq attobj2 (nth 1 att_obj_list))
  (setq tag2 (vla-get-tagstring attobj2))
  (setq text2 (vla-get-textstring attobj2))
  
  (setq attobj3 (nth 2 att_obj_list))
  (setq tag3 (vla-get-tagstring attobj3))
  (setq text3 (vla-get-textstring attobj3))
  
  (setq attobj4 (nth 3 att_obj_list))
  (setq tag4 (vla-get-tagstring attobj4))
  (setq text4 (vla-get-textstring attobj4))
  
  (setq attobj5 (nth 4 att_obj_list))
  (setq tag5 (vla-get-tagstring attobj5))
  (setq text5 (vla-get-textstring attobj5))
  
  (setq attobj6 (nth 5 att_obj_list))
  (setq tag6 (vla-get-tagstring attobj6))
  (setq text6 (vla-get-textstring attobj6))
  
  (setq attobj7 (nth 6 att_obj_list))
  (setq tag7 (vla-get-tagstring attobj7))
  (setq text7 (vla-get-textstring attobj7))
  
  (setq attobj8 (nth 7 att_obj_list))
  (setq tag8 (vla-get-tagstring attobj8))
  (setq text8 (vla-get-textstring attobj8))
  
  (setq attobj9 (nth 8 att_obj_list))
  (setq tag9 (vla-get-tagstring attobj9))
  (setq text9 (vla-get-textstring attobj9))
  
  (setq attobj10 (nth 9 att_obj_list))
  (setq tag10 (vla-get-tagstring attobj10))
  (setq text10 (vla-get-textstring attobj10))
  
  (setq attobj11 (nth 10 att_obj_list))
  (setq tag11 (vla-get-tagstring attobj11))
  (setq text11 (vla-get-textstring attobj11))
  
  (setq attobj12 (nth 11 att_obj_list))
  (setq tag12 (vla-get-tagstring attobj12))
  (setq text12 (vla-get-textstring attobj12))
  
  (setq attobj13 (nth 12 att_obj_list))
  (setq tag13 (vla-get-tagstring attobj13))
  (setq text13 (vla-get-textstring attobj13))
  
  (setq attobj14 (nth 13 att_obj_list))
  (setq tag14 (vla-get-tagstring attobj14))
  (setq text14 (vla-get-textstring attobj14))
  
  (setq attobj15 (nth 14 att_obj_list))
  (setq tag15 (vla-get-tagstring attobj15))
  (setq text15 (vla-get-textstring attobj15))
  
  (setq attobj16 (nth 15 att_obj_list))
  (setq tag16 (vla-get-tagstring attobj16))
  (setq text16 (vla-get-textstring attobj16))
)
(defun dcl_bomdcl()
  (setq dcl_id (load_dialog "bomdcl"))
  (new_dialog "bomdcl" dcl_id)
  (show_list "pop1" pop1_list)
  (show_list "pop2" pop2_list)
  (show_list "pop3" pop3_list)
  (show_list "pop4" pop4_list)
  (show_list "pop5" pop5_list)
  (show_list "pop6" pop6_list)
  (show_list "pop7" pop7_list)
  (show_list "pop8" pop8_list)
  (show_list "pop9" pop9_list)
  (set_tile "txt1" text1)
  (set_tile "txt2" text2)
  (set_tile "txt3" text3)
  (set_tile "txt4" text5)
  (set_tile "txt5" (nth 0 pop5_list))
  (set_tile "txt6" text8)
  (set_tile "txt7" text9)
  (set_tile "txt8" (nth 0 pop8_list))
  (set_tile "txt9" (nth 0 pop9_list))
  (action_tile "pop1" "(sub_pop1 $value)")
  (action_tile "pop2" "(sub_pop2 $value)")
  (action_tile "pop3" "(sub_pop3 $value)")
  (action_tile "pop4" "(sub_pop4 $value)")
  (action_tile "pop5" "(sub_pop5 $value)")
  (action_tile "pop6" "(sub_pop6 $value)")
  (action_tile "pop7" "(sub_pop7 $value)")
  (action_tile "pop8" "(sub_pop8 $value)")
  (action_tile "pop9" "(sub_pop9 $value)")
  (action_tile "accept" "(ok_bomdcl)(done_dialog 1)")
  (setq dd(start_dialog))
  (if (= dd 1)
    (puttext)
    )
)
(defun show_list (key newlist)
  (start_list key)
  (mapcar 'add_list newlist)
  (end_list)
)
(defun sub_pop1 (vvs)
  (set_tile "txt1" (nth (atoi vvs) pop1_list))
)
(defun sub_pop2 (vvs)
  (set_tile "txt2" (nth (atoi vvs) pop2_list))
)
(defun sub_pop3 (vvs)
  (set_tile "txt3" (nth (atoi vvs) pop3_list))
)
(defun sub_pop4 (vvs)
  (set_tile "txt4" (nth (atoi vvs) pop4_list))
)
(defun sub_pop5 (vvs)
  (set_tile "txt5" (nth (atoi vvs) pop5_list))
)
(defun sub_pop6 (vvs)
  (set_tile "txt6" (nth (atoi vvs) pop6_list))
)
(defun sub_pop7 (vvs)
  (set_tile "txt7" (nth (atoi vvs) pop7_list))
)
(defun sub_pop8 (vvs)
  (set_tile "txt8" (nth (atoi vvs) pop8_list))
)
(defun sub_pop9 (vvs)
  (set_tile "txt9" (nth (atoi vvs) pop9_list))
)

(defun ok_bomdcl ()
  (setq txt1 (get_tile "txt1"))
  (setq txt2 (get_tile "txt2"))
  (setq txt3 (get_tile "txt3"))
  (setq txt5 (get_tile "txt4"))
  (setq txt6 (get_tile "txt5"))
  (setq txt8 (get_tile "txt6"))
  (setq txt9 (get_tile "txt7"))
  (setq txt14 (get_tile "txt8"))
  (setq txt15 (get_tile "txt9"))
)


(defun puttext ()
  (do_fname_andtime)
  (vla-put-textstring attobj1 txt1)
  (vla-put-textstring attobj2 txt2)
  (vla-put-textstring attobj3 txt3)
  (vla-put-textstring attobj5 txt5)
  (vla-put-textstring attobj6 txt6)
  (vla-put-textstring attobj7 txt1)
  (vla-put-textstring attobj8 txt8)
  (vla-put-textstring attobj9 txt9)
  (vla-put-textstring attobj10 moldno)
  (vla-put-textstring attobj11 fname)
  (vla-put-textstring attobj12 newdate)
  (vla-put-textstring attobj13 newdate)
  (vla-put-textstring attobj14 txt14)
  (vla-put-textstring attobj15 txt15)
  (vla-put-textstring attobj16 txt2)
  )
;;;BY 风之影
(defun do_fname_andtime()
  (setq moldno (vl-string-subst "" "M.dwg" (getvar "dwgname")))
  (setq fname (vl-string-subst "" ".dwg" (getvar "dwgname")))
  (setq cdate (rtos (getvar "cdate") 2 0))
  (setq newdate (strcat (substr cdate 1 4) "." (substr cdate 5 2) "." (substr cdate 7 2)))
)

(defun readtxt(lujin /)
  (setq data_list '())
  (setq ff (open lujin  "r"))
  (setq data (read-line ff))
  (while data
    (setq data_list (cons data data_list))
    (setq data(read-line ff))
    )
  (end_list)  
  (close ff)
  (setq data_list (reverse data_list))
  )
(defun setlist( /)
  (setq lu1 "D:/t1.txt")
  (setq pop1_list (readtxt lu1))
  (setq lu2 "D:/t2.txt")
  (setq pop2_list (readtxt lu2))
  (setq lu3 "D:/t3.txt")
  (setq pop3_list (readtxt lu3))
  (setq lu4 "D:/t4.txt")
  (setq pop4_list (readtxt lu4))
  (setq lu5 "D:/t5.txt")
  (setq pop5_list (readtxt lu5))
  (setq lu6 "D:/t6.txt")
  (setq pop6_list (readtxt lu6))
  (setq lu7 "D:/t7.txt")
  (setq pop7_list (readtxt lu7))
  (setq lu8 "D:/t8.txt")
  (setq pop8_list (readtxt lu8))
  (setq lu9 "D:/t9.txt")
  (setq pop9_list (readtxt lu9))
  )


/*★★★★★ListDCL @ fsxm.mjtd.com★★★★★*/
bomdcl:dialog {
    label = "TONY-BOM" ;
    :row {
        :edit_box {
            edit_width = 15 ;
            key = "txt1" ;
            label = "序号" ;
        }
        :popup_list {
            key = "pop1" ;
            edit_width = 15 ;
        }
    }
    :row {
        :edit_box {
            label = "名称" ;
            key = "txt2" ;
            edit_width = 15 ;
        }
        :popup_list {
            key = "pop2" ;
            edit_width = 15 ;
        }
    }
    :row {
        :edit_box {
            label = "材质" ;
            key = "txt3" ;
            edit_width = 15 ;
        }
        :popup_list {
            key = "pop3" ;
            edit_width = 15 ;
        }
    }
    :row {
        :edit_box {
            label = "数量" ;
            key = "txt4" ;
            edit_width = 15 ;
        }
        :popup_list {
            key = "pop4" ;
            edit_width = 15 ;
        }
    }
    :row {
        :edit_box {
            label = "备注" ;
            key = "txt5" ;
            edit_width = 15 ;
        }
        :popup_list {
            key = "pop5" ;
            edit_width = 15 ;
        }
    }
    :row {
        :edit_box {
            label = "胶料" ;
            key = "txt6" ;
            edit_width = 15 ;
        }
        :popup_list {
            key = "pop6" ;
            edit_width = 15 ;
        }
    }
    :row {
        :edit_box {
            label = "缩水" ;
            key = "txt7" ;
            edit_width = 15 ;
        }
        :popup_list {
            key = "pop7" ;
            edit_width = 15 ;
        }
    }
    :row {
        :edit_box {
            label = "名字" ;
            key = "txt8" ;
            edit_width = 15 ;
        }
        :popup_list {
            key = "pop8" ;
            edit_width = 15 ;
        }
    }
    :row {
        :edit_box {
            label = "主管" ;
            key = "txt9" ;
            edit_width = 15 ;
        }
        :popup_list {
            key = "pop9" ;
            edit_width = 15 ;
        }
    }
    spacer_1;
    ok_cancel;
}




文本要放D盘根目录,哈哈,我的程序很乱吧

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

点评

源程序应该用findfile定义txt文件  发表于 2015-9-29 12:37

评分

参与人数 1明经币 +1 收起 理由
zctao1966 + 1 赞一个!

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下

本帖被以下淘专辑推荐:

发表于 2022-11-18 11:44 | 显示全部楼层
感謝分享,給源碼的就更不用說了,學習了
发表于 2018-7-10 21:26 | 显示全部楼层
来晚了,,,学习一下,多谢楼主的源码
发表于 2013-6-21 23:02 | 显示全部楼层
发表于 2013-6-22 09:16 | 显示全部楼层
最近明经的书是否暂停了?一年多了
发表于 2013-6-22 09:34 | 显示全部楼层
好思路好想法,支持支持
发表于 2013-6-22 11:13 | 显示全部楼层
好思路好想法,支持支持
 楼主| 发表于 2013-6-24 12:42 | 显示全部楼层
44444444444444

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2013-6-26 14:28 | 显示全部楼层
可惜不能指定的属性值!!!

点评

随便你改,源码都在这了  发表于 2013-6-26 23:35
发表于 2013-6-26 18:16 | 显示全部楼层
嘿嘿,学习学习!
发表于 2013-7-2 11:33 | 显示全部楼层
图框 利器啊
发表于 2013-8-6 07:07 | 显示全部楼层
文件都放在D根目录,程序运行错误: 参数类型错误: VLA-OBJECT nil
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-3-29 08:27 , Processed in 0.322229 second(s), 36 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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