找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2597|回复: 27

[每日一码] 国标三螺母

[复制链接]
发表于 2015-2-9 16:02:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
捕获luomu.JPG
(defun c:luomu6170(/ data_list aa bz d d1 dd2 dist e1 e10 e2 e3 e4 e5 e6 e7 e8 e9 eL1 en en1 en2 h1 HH1 LL1 LL3 LL4 M m1 p1 p10 p2 p3 p7 p8 p9 pdm1 pdm2 pdm3 pdm4 pds1 pds2 pds3 pds4 pds5 pe pe1 pm1 pm2 ps ps1 rr s1 txt1 vm wt xobj)
  (setvar "cmdecho" 0)
  (setvar "blipmode" 0)
  (setvar "delobj" 1)
  (vl-load-com)
  (initget
  "1.6 2 2.5 3 3.5 4 5 6 8 10 12 14 16 18 20 22 24 27 30 33 36 39 42 45 48 52 56 60 64 72 80 90 100 110"
  )
  (setq    MMM (getkword
     "\n请输入国标(GB/T6170-2000)六角螺母规格(括号内为非优选的规格,首次运行必输入一个数值!!!)\nM:[1.622.533.54 5681012(14)16(18)20(22)24(27)30(33)36(39)42(45)48(52)56(60)64728090100110] <默认>:"
  )
  )
(if
      (= MMM nil)     ;;;;此处必须用nil不能用""
      (setq MM MM);;;;MM不能设为局部变量!!!
      (setq MM MMM)
    )
    (setq M MM)
    (setq M (atof M))
    (cond
     ((= M 1.6) (setq data_list '(1.6 3.41 0.2528 0.1459 1.3 3.2 0.14 0.15)))
     ((= M 2) (setq data_list '(2 4.32 0.3202 0.1849 1.6 4 0.18 0.19)))
     ((= M 2.5) (setq data_list '(2.5 5.45 0.404 0.2332 2 5 0.22 0.23)))
     ((= M 3) (setq data_list '(3 6.01 0.4455 0.2572 2.4 5.5 0.26 0.28)))
     ((= M 3.5) (setq data_list '(3.5 6.58 0.4877 0.2816 2.8 6 0.31 0.33)))
     ((= M 4) (setq data_list '(4 7.66 0.5678 0.3278 3.2 7 0.35 0.38)))
     ((= M 5) (setq data_list '(5 8.79 0.6515 0.3762 4.7 8 0.44 0.47)))
     ((= M 6) (setq data_list '(6 11.05 0.819 0.4729 5.2 10 0.53 0.56)))
     ((= M 8) (setq data_list '(8 15.0111 1.1127 0.6424 6.8 13 0.7 0.75)))
     ((= M 10) (setq data_list '(10 18.4752 1.2379 0.7147 8.4 16 0.99 1)))
     ((= M 12) (setq data_list '(12 20.7846 2.9506 1.7035 10.8 18 1.48 1.5)))
     ((= M 14) (setq data_list '(14 24.2487 3.4423 2.2999 12.8 21 1.48 1.5)))
     ((= M 16) (setq data_list '(16 27.7128 3.9341 2.6285 14.8 24 1.48 1.5)))
     ((= M 18) (setq data_list '(18 31.1769 4.4258 2.957 15.8 27 1.48 1.5)))
     ((= M 20) (setq data_list '(20 34.641 4.9176 3.2856 18 30 1.48 1.5)))
     ((= M 22) (setq data_list '(22 39.2598 5.5733 3.7237 19.4 34 1.48 1.5)))
     ((= M 24) (setq data_list '(24 41.5692 5.9011 3.9427 21.5 36 1.98 2)))
     ((= M 27) (setq data_list '(27 47.3427 6.7207 4.4903 23.8 41 1.98 2)))
     ((= M 30) (setq data_list '(30 53.1162 7.5403 5.0379 25.6 46 1.98 2)))
     ((= M 33) (setq data_list '(33 57.735 8.196 5.476 28.7 50 1.98 2)))
     ((= M 36) (setq data_list '(36 63.5085 9.0156 6.0236 31 55 2.97 3)))
     ((= M 39) (setq data_list '(39 69.282 9.8352 6.5712 33.4 60 2.97 3)))
     ((= M 42) (setq data_list '(42 75.0555 10.6548 7.1188 34 65 2.97 3)))
     ((= M 45) (setq data_list '(45 80.829 11.4744 7.6664 36 70 2.97 3)))
     ((= M 48) (setq data_list '(48 86.6025 12.294 8.214 38 75 2.97 3)))
     ((= M 52) (setq data_list '(52 92.376 13.1136 8.7616 42 80 3.96 4)))
     ((= M 56) (setq data_list '(56 98.1495 13.9332 9.3092 45 85 3.96 4)))
     ((= M 60) (setq data_list '(60 103.923 14.7528 9.8568 48 90 3.96 4)))
     ((= M 64) (setq data_list '(64 109.6966 15.5724 10.4044 51 95 3.96 4)))
      ;;;;以下数据为参考“发电厂汽水管道支架设计手册(D-ZD2010)”中的数据
     ((= M 72) (setq data_list '(72 121.2436 8.9868 5.1885 58 105 4.4 4.79)))
     ((= M 80) (setq data_list '(80 132.7906 9.8427 5.6827 64 115 4.93 5.32)))
     ((= M 90) (setq data_list '(90 150.1111 11.1265 6.4239 72 130 5.54 5.99)))
     ((= M 100) (setq data_list '(100 167.4316 12.4104 7.1651 80 145 6.16 6.65)))
     ((= M 110) (setq data_list '(110 178.9786 13.2662 7.6593 88 155 6.78 7.32)))
  )
(setq d1 (nth 0 data_list))
(setq eL1 (nth 1 data_list))
(setq HH1 (nth 2 data_list))
(setq LL1 (nth 3 data_list))
(setq m1 (nth 4 data_list))
(setq s1 (nth 5 data_list))
(setq LL3 (nth 6 data_list))
(setq h1 (nth 7 data_list));;螺旋线的螺距
(setq ps (getpoint "\n起点:"))
(setvar "osmode" 0)  ;很关键,否则画线时容易出错
(setq rr (/ s1 2.0))
(setq pe (polar ps 0 m1))
(setq p1 (polar ps (/ PI 2) (/ s1 2.0)))
(setq p2 (polar p1 (/ PI 2) HH1))
(setq p3 (polar p2 0 LL1))
(setq pm1 (polar ps 0 (/ m1 2.0)))
(setq pm2 (polar pm1 (/ PI 2) (/ eL1 2.0)))
(command "polygon" 6 ps "c" rr)
(setq e1 (entlast))
(command "rotate" e1 "" ps 90)
(command "rotate3d" e1 "" "y" ps 90)
(command "extrude" e1 "" m1)
(setq e1 (entlast))
(command "pline" p1 p2 p3 "c")
(setq e2 (entlast))
(command "revolve" e2 "" ps pe 360 )
(setq e2 (entlast))
(command "mirror" e2 "" pm1 pm2 "n" )
(setq e3 (entlast))
(command "union" e2 e3 "")
(command "subtract" e1 "" e2 "")
(command "line" ps pe "")
(setq e2 (entlast))
(command "circle" ps "d" d1)
(setq e3 (entlast))
(command "sweep" e3 "" e2)
(setq e4 (entlast))
(command "subtract" e1 "" e4 "")
(command "erase" e2 "")
;;;  绘制螺纹
(setq p7 (polar pe (/ PI 2) (/ d1 2.0)))
(setq p8 (polar p7 PI (/ LL3 2)))
(setq p9 (polar p8 0 LL3))
(setq p10 (polar p8 (/ (* 300 PI) 180) LL3))
(setq ps1 (polar ps PI LL3))
(setq pe1 (polar pe 0 LL3))
(setq dist (distance ps1 pe1))
(setq aa (/ (* 30 PI) 180))
(setq LL4 (/ (* 0.5 LL3 (cos aa)) (sin aa)))
(setq dd2 (+ d1 LL4 LL4))
(setvar "cecolor" "2")
(command "line" ps1 pe1 "")
(setq e5 (entlast))
(command "circle" ps "d" dd2)
(setq e6 (entlast))
(command "sweep" e6 "" e5)
(setq e7 (entlast))
(command "erase" e5 "")
(command "pline" p8 p9 p10 "c")
(setq e8 (entlast))
(command "rotate3d" e8 "" "x" p7 90)
(command "helix" pe1 (/ dd2 2.0) (/ dd2 2.0) "H" h1 "T" (/ dist h1))
(setq e9 (entlast))
(command "rotate3d" e9 "" "y" pe1 270)
(command "sweep" e8 "" "B" p7 "A" "N" e9)
(setq e10 (entlast))
(command "subtract" e7 "" e10 "")
(command "subtract" e1 "" e7 "")
(command "erase" e9 "")
;;;标尺寸
  (setq pds1 (polar ps (/ (* 3 PI) 2) (/ s1 2.0)))
  (setq pds2 (polar ps (/ (* 3 PI) 2) (/ eL1 2.0)))
  (setq pds3 (polar ps (/ PI 2) (/ eL1 2.0)))
  (setq pds4 (polar pe (/ PI 2) (/ d1 2.0)))
  (setq pds5 (polar pe (/ (* 3 PI) 2) (/ d1 2.0)))
  (setq pdm1 (polar ps PI (/ m1 2)));;;标尺寸用
  (setq pdm2 (polar ps PI m1));;;标尺寸用
  (setq pdm3 (polar pe 0 (/ m1 2)));;;标尺寸用
  (setq pdm4 (polar pm1 (/ (* 3 PI) 2) (* 0.8 s1)));;;标尺寸用
  (setq pdm5 (polar pdm4 (/ (* 3 PI) 2) (* 0.5 d1)));;;写文本
  (setvar "cecolor" "1")
(command "dim" "ver" p1 pds1 pdm1 "" "e")
(command "dim" "ver" pds2 pds3 pdm2 "" "e")
(command "dim" "ver" pds4 pds5 pdm3 "" "e")
(command "dim" "hor" ps pe pdm4 "" "e")
  ;;;求重量
  (setq bz 7.85);;;;钢的比重
  (setq en (entget e1))
  (setq en1 (car en))
  (setq en2 (cdr en1))
  (setq xobj (vlax-ename->vla-object en2)) ;转换enamevla对象
  (setq vm (vla-get-volume xobj))   ;  直接取得对象体积mm3
  (setq vm (/ vm 1000000.0));;;;转换成立方分米:dm3
  (setq wt (* bz vm))
  (setq txt1 (strcat "M" (rtos M) " 重量:" (rtos wt 2 3) "kg"))
  (command "text" "J" "BC" pdm5 (* 0.08 eL1) 0 txt1 )
  (setvar "osmode" 527)
   (setvar "cecolor" "bylayer")
  (prompt "\n已绘制一个螺母")
  (prin1)
)
(prompt "绘制螺母程序,命令行输入luomu6170")
(prin1)
本程序加载后直接在命令运行luomu6170,按提示输入所需数值即可生成所需尺寸规格的螺母。

评分

参与人数 2D豆 +10 收起 理由
yularna + 5 很给力!经验;技术要点;资料分享奖!
lucas3 + 5 很给力!经验;技术要点;资料分享奖!

查看全部评分

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 2026个

财富等级: 金玉满堂

发表于 2015-2-9 17:27:27 | 显示全部楼层
谢谢提供源码程序,下载学习。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 924个

财富等级: 财运亨通

发表于 2015-2-9 18:18:25 | 显示全部楼层
谢谢楼主分享码源。学习学习!!!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 3198个

财富等级: 富可敌国

发表于 2015-2-9 18:22:13 | 显示全部楼层
楼主随便来一个绘制螺杆的吧

点评

(defun c:luosuan(/ clay aa ang1 ang2 ang3 ang4 b1 b2 b3 bz clt d1 dd1 dd2 ddh e1 e2 e3 e4 e5 eeL1 eeL2 eL1 eL2 eLL1 en en1 en2 ep file1 h1 HH1 LL1 LL2 LL3 LL4 M m1 m2 ML1 ML2 MM2 osm p1 p10 p11 p12  详情 回复 发表于 2015-2-9 20:57
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-2-9 20:57:09 | 显示全部楼层
lucas3 发表于 2015-2-9 18:22
楼主随便来一个绘制螺杆的吧


(defun c:luosuan(/ clay aa ang1 ang2 ang3 ang4 b1 b2 b3 bz clt d1 dd1 dd2 ddh e1 e2 e3 e4 e5 eeL1 eeL2 eL1 eL2 eLL1 en en1 en2 ep file1 h1 HH1 LL1 LL2 LL3 LL4 M m1 m2 ML1 ML2 MM2 osm p1 p10 p11 p12 p13 p2 p3 p4 p7 p8 p9 pe ph1 pL1 pL2 pr ps ps1 pse rr s1 tbl1 tbl2 txt1 txt2 txt3 vm wt1 wt2 wt3 xobj);;;;此表已经excel处理过
  (setvar "cmdecho" 0)
  (setvar "blipmode" 0)
  (setvar "delobj" 1)
  (setq clay (getvar "clayer"))
  (setq clt (getvar "CELTYPE"))
  (setq osm (getvar "osmode"))
  (vl-load-com)
   
  (setq tbl1 (tblsearch "ltype" "center"))
  (if(= tbl1 nil) (command "linetype" "L" "center" "acadiso" ""))
  (setq tbl2 (tblsearch "layer" "cen_lay"))
  (if(= tbl2 nil) (command "layer" "N" "cen_lay" "L" "center" "cen_lay" "C" 1 "cen_lay" ""))

  (initget
    "3 4 5 6 8 10 12 14 16 18 20 22 24 27 30 33 36 39 42 45 48 52 56 60 64"
  )
  (setq M (getkword
      "\n请输入国标(GB/T6170-2000)六角螺母规格(括号内为非优选的规格)\nM:[3 4 5 6 8、10、12、(14)、16、(18)、20、(22)、24、(27)、30、(33)、36、(39)、42、(45)、48、(52)、56、(60)、64] <默认>:"
    )
  )
    (if
      (= M nil)     ;;;;此处必须用nil不能用""
      (setq MM1 MM1);;;;MM1不能设为局部变量!!!
      (setq MM1 M)
    )
    (setq MM2 MM1)
    (setq MM2 (atof MM2))
    (setq ps (getpoint "\n起点:"))
    (setq pse (getpoint ps "\n紧固段长度:"))
    (setq LL2 (distance ps pse))
        (if (<= MM2 6)
     (progn
               (cond
                  ((= MM2 3) (setq data_list '(3 6.3509 0.4 0.4707 0.2718 0.3700 0.1875 2 0.2115 5.5 12 0 0 3.2 7 0.5 2.4 1.8)))   
                  ((= MM2 4) (setq data_list '(4 8.0829 0.5 0.5991 0.3459 0.4948 0.25 2.8 0.2692 7 14 0 0 4.3 9 0.8 3.2 2.2)))
                  ((= MM2 5) (setq data_list '(5 9.2376 0.63 0.6847 0.3953 0.6184 0.3125 3.5 0.3077 8 16 0 0 5.3 10 1 4.7 2.7)))
                  ((= MM2 6) (setq data_list '(6 11.547 0.75 0.8559 0.4941 0.7400 0.375 4 0.3846 10 18 0 0 6.4 12 1.6 5.2 3.2)))   
               )
   
         (setq d1 (nth 0 data_list))
                (setq eL1 (nth 1 data_list))
                (setq h1 (nth 2 data_list))
                (setq HH1 (nth 3 data_list))
                (setq LL1 (nth 4 data_list))
                (setq LL3 (nth 5 data_list))
                (setq LL4 (nth 6 data_list))
                (setq m1 (nth 7 data_list))
                (setq m2 (nth 8 data_list))
                (setq s1 (nth 9 data_list))
                (setq b1 (nth 10 data_list))
                (setq b2 (nth 11 data_list))
                (setq b3 (nth 12 data_list))
                (setq dd1 (nth 13 data_list))
                (setq dd2 (nth 14 data_list))
;;;                (setq ddh (nth 15 data_list))
                (setq ML1 (nth 16 data_list))
                (setq ML2 (nth 17 data_list))
      
                (while  (<= LL2 0)
                   (progn
         (alert "紧固段长度必须大于0,重新输入紧固段长度:")
         (setq pse (getpoint ps "\n紧固段长度:"))
                       (setq LL2 (distance ps pse))
     )
   )
      
          (while  (> (+ LL2 b1) 125)
                   (progn
         (alert "螺栓总长度应小于125mm,重新输入紧固段长度:")
         (setq pse (getpoint ps "\n紧固段长度:"))
                       (setq LL2 (distance ps pse))
     )
   )
     )
        )
;;;----------------------------------------------------------------------------------------------------------
  (if (and (>= MM2 8) (<= MM2 39))
     (progn
               (cond
                    ((= MM2 8) (setq data_list '(8 15.0111 1 1.1127 0.6424 0.9895 0.5 5.3 0.5 13 22 28 41 8.4 16 1.6 6.8 4)))
                    ((= MM2 10) (setq data_list '(10 18.4752 1 1.3694 0.7906 0.99 0.625 6.4 0.5 16 26 32 45 10.5 20 2 8.4 5)))
                    ((= MM2 12) (setq data_list '(12 20.7846 1.5 1.5406 0.8895 1.48 0.75 7.5 0.5341 18 30 36 49 13 24 2.5 10.8 6)))
                    ((= MM2 14) (setq data_list '(14 24.2487 1.5 1.7974 1.0377 1.48 0.875 8.8 0.6231 21 34 40 57 15 28 2.5 12.8 7)))
                    ((= MM2 16) (setq data_list '(16 27.7128 1.5 2.0541 1.186 1.45 1 10 0.6039 24 38 44 57 17 30 3 14.8 8)))           
                    ((= MM2 18) (setq data_list '(18 31.1769 1.5 2.3109 1.3342 1.48 1.125 11.5 0.6794 27 42 48 61 19 34 3 15.8 9)))
                    ((= MM2 20) (setq data_list '(20 34.641 1.5 2.5677 1.4824 1.48 1.25 12.5 0.7549 30 46 52 65 21 37 3 18 10)))               
                    ((= MM2 22) (setq data_list '(22 39.2598 1.5 2.91 1.6801 1.48 1.4167 14 0.8555 34 50 56 69 23 39 3 19.4 11)))     
                    ((= MM2 24) (setq data_list '(24 41.5692 2 3.0812 1.7789 1.98 1.5 15 0.9058 36 54 60 73 25 44 4 21.5 12)))                 
                    ((= MM2 27) (setq data_list '(27 47.3427 2 3.5091 2.026 1.98 1.7083 17 1.0316 41 60 66 79 28 50 4 23.8 13.5)))  ;;; MM227               
                    ((= MM2 30) (setq data_list '(30 53.1162 2 3.9371 2.2731 1.98 1.9167 18.7 1.1575 46 66 72 85 31 56 4 25.6 15)))
                    ((= MM2 33) (setq data_list '(33 57.735 2 4.2794 2.4707 1.98 2.0833 21 1.2581 50 72 78 91 34 60 5 28.7 16.5)))
                    ((= MM2 36) (setq data_list '(36 63.5085 3 4.7074 2.7178 2.97 2.2917 22.5 1.23 55 78 84 97 37 66 5 33 18)))              
                    ((= MM2 39) (setq data_list '(39 69.282 3 5.1353 2.9649 2.97 2.5 25 1.3418 60 84 90 103 42 72 6 33.4 19.5)))
               )
         (setq d1 (nth 0 data_list))
                (setq eL1 (nth 1 data_list))
                (setq h1 (nth 2 data_list))
                (setq HH1 (nth 3 data_list))
                (setq LL1 (nth 4 data_list))
                (setq LL3 (nth 5 data_list))
                (setq LL4 (nth 6 data_list))
                (setq m1 (nth 7 data_list))
                (setq m2 (nth 8 data_list))
                (setq s1 (nth 9 data_list))
                (setq b1 (nth 10 data_list))
                (setq b2 (nth 11 data_list))
                (setq b3 (nth 12 data_list))
                (setq dd1 (nth 13 data_list))
                (setq dd2 (nth 14 data_list))
;;;                (setq ddh (nth 15 data_list))
                (setq ML1 (nth 16 data_list))
                (setq ML2 (nth 17 data_list))
         (while  (<= LL2 0)
                   (progn
         (alert "紧固段长度必须大于0,重新输入紧固段长度:")
         (setq pse (getpoint ps "\n紧固段长度:"))
                       (setq LL2 (distance ps pse))
     )
   )

          (if (<= (+ LL2 b1) 125) (setq b1 b1)
                   (progn
                       (if (and (> (+ LL2 b1) 125) (<= (+ LL2 b1 ) 200)) (setq b1 b2))
         (if (> (+ LL2 b1 ) 200) (setq b1 b3))
     )
   )
     )
        )
;;;  -----------------------------------------------------------------------------------------------------------
    (if (and (>= MM2 42) (<= MM2 64))
     (progn
               (cond
                    ((= MM2 42) (setq data_list '(42 75.0555 3 5.5633 3.212 2.97 2.7083 26 1.4536 65 0 96 109 45 78 8 34 21)))
                    ((= MM2 45) (setq data_list '(45 80.829 3 5.9912 3.459 2.97 2.9167 28 1.5654 70 0 102 115 48 85 8 36 22.5)))
                    ((= MM2 48) (setq data_list '(48 86.6025 3 6.4192 3.7061 2.97 3.125 30 1.6772 75 0 108 121 52 92 8 38 24)))
                    ((= MM2 52) (setq data_list '(52 92.376 4 6.8471 3.9532 3.96 3.3333 33 1.7891 80 0 116 129 56 98 8 42 26)))
                    ((= MM2 56) (setq data_list '(56 98.1495 4 7.275 4.2002 3.96 3.5417 35 1.9009 85 0 124 137 62 105 10 45 28)))
                    ((= MM2 60) (setq data_list '(60 103.923 4 7.703 4.4473 3.96 3.75 38 2.0127 90 0 132 145 66 110 10 48 30)))
                    ((= MM2 64) (setq data_list '(64 109.6966 4 8.1309 4.6944 3.94 3.9583 40 2.1245 95 0 140 153 70 115 10 51 32)))
               )

         (setq d1 (nth 0 data_list))
                (setq eL1 (nth 1 data_list))
                (setq h1 (nth 2 data_list))
                (setq HH1 (nth 3 data_list))
                (setq LL1 (nth 4 data_list))
                (setq LL3 (nth 5 data_list))
                (setq LL4 (nth 6 data_list))
                (setq m1 (nth 7 data_list))
                (setq m2 (nth 8 data_list))
                (setq s1 (nth 9 data_list))
                (setq b1 (nth 10 data_list))
                (setq b2 (nth 11 data_list))
                (setq b3 (nth 12 data_list))
         (setq dd1 (nth 13 data_list))
                (setq dd2 (nth 14 data_list))
;;;                (setq ddh (nth 15 data_list))
         (setq ML1 (nth 16 data_list))
                (setq ML2 (nth 17 data_list))

                (setq b1 b2)
                (while  (<= LL2 0)
                   (progn
         (alert "紧固段长度必须大于0,重新输入紧固段长度:")
         (setq pse (getpoint ps "\n紧固段长度:"))
                       (setq LL2 (distance ps pse))
     )
   )
                (while  (<= (+ LL2 b1) 125)
                   (progn
         (alert "螺栓长度应大于125mm,重新输入紧固段长度:")
         (setq pse (getpoint ps "\n紧固段长度:"))
                       (setq LL2 (distance ps pse))
     )
   )
       (if (and (> (+ LL2 b1 ) 125) (<= (+ LL2 b1) 200)) (setq b1 b2))
              (if (> (+ LL2 b1) 200) (setq b1 b3))
  
            )
      
     )
;;;  -----------------------------------------------------------------------------------------------------------
         (setq ang1 0)
       (setq ang2 (/ PI 2))
       (setq ang3 PI)
       (setq ang4 (/ (* 3 PI) 2))
              (setq aa (angle ps pse))
;;;+++++++++++++++++++++++++++++++++++++
     (if (= aa ang1)
     (progn
              (setvar "osmode" 0)      ;很关键,否则画线时容易出错
              (setq rr (/ s1 2.0))
              (setq ps1 (polar ps (+ aa PI) m1))
              (setq p1 (polar ps1 (+ aa (/ PI 2)) (/ s1 2.0)))
              (setq p2 (polar p1 (+ aa (/ PI 2)) HH1))
              (setq p3 (polar p2 aa LL1))
              (setq p4 (polar ps1 aa (- m1 m2)))
  
              (setq pe (polar pse aa b1))
              (setq p7 (polar pe (+ aa (/ PI 2)) (/ d1 2.0)))
              (setq p8 (polar p7 (+ aa PI) (/ LL3 2)))
              (setq p9 (polar p8 (+ aa 0) LL3))
              (setq p10 (polar p8 (/ (* (+ aa 300) PI) 180) LL3))
              (setq p11 (polar pe (- aa (/ PI 2)) (/ d1 2.0)))
              (setq p12 (polar p11 (+ aa (/ PI 2)) LL4))
              (setq p13 (polar p11 (+ aa pi) LL4))
              (setq pr (polar ps1 aa rr))
              (setq pL1 (polar pse aa ML1))
              (setq pL2 (polar pL1 aa ML2))
              (command "polygon" 6 ps1 "c" pr)
              (setq e1 (entlast))
              (command "rotate3d" e1 "" "Y" ps1 90)
        (command "copy" e1 "" ps1 ps1)
              (setq eLL1 (entlast))
        (command "copy" e1 "" ps1 ps1)
              (setq eeL1 (entlast))
              (command "extrude" e1 "" (- m1 m2))
              (setq e1 (entlast))
              (command "pline" p1 p2 p3 "c")
              (setq e2 (entlast))
              (command "revolve" e2 "" ps1 pe 360)
              (setq e2 (entlast))
              (command "subtract" e1 "" e2 "")
              (command "circle" p4 "d" s1)
              (setq e3 (entlast))
              (command "rotate3d" e3 "" "Y" p4 90)
              (command "extrude" e3 "" m2)
              (setq e4 (entlast))
              (command "union" e1 e4 "")
              (command "line" p4 pe "")
              (setq e2 (entlast))
              (command "circle" p4 "d" d1)
              (setq e3 (entlast))
              (command "sweep" e3 "" e2)
              (setq e5 (entlast))
              (command "erase" e2 "")
              (command "union" e1 e5 "")
              (command "pline" p11 p12 p13 "c")
              (setq e2 (entlast))
              (command "revolve" e2 "" ps pe 360)
              (setq e2 (entlast))
              (command "subtract" e1 "" e2 "")
       (command "copy" e1 "" ps ps)
              (setq ep (entlast))
      
  ;;;  画螺纹
       (command "pline" p10 p9 p8 "c")
              (setq e2 (entlast))
              (setq ph1 (polar pse (+ aa ang2) (/ d1 2.0)))
              (command "helix" pse ph1 (/ d1 2.0) "H" h1 "T" (/ b1 h1));;;;(/ d1 2.0)必须除以2.0否则画不出螺纹
              (setq e3 (entlast))
              (command "rotate3d" e3 "" "y" pse 90)
         (command "move" e2 "" p7 ph1)
              (command "sweep" e2 "" "b" ph1 "A" "N" e3)
              (setq e4 (entlast))
;;;       (command "move" e4 "" pse (polar pse aa 0.01));;;此句为解决边面关系不一致而设
              (command "subtract" e1 "" e4 "")
              (command "erase" e3 "")
      
              (setvar "clayer" "cen_lay")
              (command "line" ps1 pe "")
              (setq e2 (entlast))

;;;绘制螺母
              (setvar "clayer" "0")
              (setvar "cecolor" "221")

              (command "move" eLL1 "" ps1 pse)
              (command "extrude" eLL1 "" (/ ML1 2.0))
              (setq eLL1 (entlast))
              (command "pline" p1 p2 p3 "c")
              (setq eL2 (entlast))
              (command "move" eL2 "" ps1 pse)
              (command "revolve" eL2 "" ps1 pe 360)
              (setq eL2 (entlast))
              (command "subtract" eLL1 "" eL2 "")
              (command "mirror3d" eLL1 "" "Y" (polar pse aa (/ ML1 2.0)) "N")
              (setq eL2 (entlast))
              (command "union" eLL1 eL2 "")
;;;绘制溥螺母
  
              (command "move" eeL1"" ps1 pL1)
              (command "extrude" eeL1 "" (/ mL2 2.0))
              (setq eeL1 (entlast))
              (command "pline" p1 p2 p3 "c")
              (setq eeL2 (entlast))
              (command "move" eeL2 "" ps1 pL1)
              (command "revolve" eeL2 "" ps1 pe 360)
              (setq eeL2 (entlast))
              (command "subtract" eeL1 "" eeL2 "")
              (command "mirror3d" eeL1 "" "Y" (polar pL1 aa (/ ML2 2.0)) "N")
              (setq eeL2 (entlast))
              (command "union" eeL1 eeL2 "")
   
            );end progn
      
     );end if
;;;+++++++++++++++++++++++++++++++++++++
  
;;;+++++++++++++++++++++++++++++++++++++
     (if (= aa ang2)
     (progn
       (setvar "osmode" 0)      ;很关键,否则画线时容易出错
              (setq rr (/ s1 2.0))
              (setq ps1 (polar ps (+ aa PI) m1))
              (setq p1 (polar ps1 (+ aa (/ PI 2)) (/ s1 2.0)))
              (setq p2 (polar p1 (+ aa (/ PI 2)) HH1))
              (setq p3 (polar p2 aa LL1))
              (setq p4 (polar ps1 aa (- m1 m2)))
  
              (setq pe (polar pse aa b1))
              (setq p7 (polar pe ang3 (/ d1 2.0)))
              (setq p8 (polar p7 (- 0 aa) (/ LL3 2)))
              (setq p9 (polar p8 aa LL3))
              (setq p10 (polar p8 (/ (* 30 PI) 180) LL3))
              (setq p11 (polar pe (- aa (/ PI 2)) (/ d1 2.0)))
              (setq p12 (polar p11 (+ aa (/ PI 2)) LL4))
              (setq p13 (polar p11 (+ aa pi) LL4))
              (setq pr (polar ps1 aa rr))
              (setq pL1 (polar pse aa ML1))
              (setq pL2 (polar pL1 aa ML2))
              (command "polygon" 6 ps1 "c" pr)
              (setq e1 (entlast))
              (command "rotate3d" e1 "" "x" ps1 -90)
        (command "copy" e1 "" ps1 ps1)
              (setq eLL1 (entlast))
        (command "copy" e1 "" ps1 ps1)
              (setq eeL1 (entlast))
              (command "extrude" e1 "" (- m1 m2))
              (setq e1 (entlast))
              (command "pline" p1 p2 p3 "c")
              (setq e2 (entlast))
              (command "revolve" e2 "" ps1 pe 360)
              (setq e2 (entlast))
              (command "subtract" e1 "" e2 "")
              (command "circle" p4 "d" s1)
              (setq e3 (entlast))
              (command "rotate3d" e3 "" "x" p4 -90)
              (command "extrude" e3 "" m2)
              (setq e4 (entlast))
              (command "union" e1 e4 "")
              (command "line" p4 pe "")
              (setq e2 (entlast))
              (command "circle" p4 "d" d1)
              (setq e3 (entlast))
              (command "sweep" e3 "" e2)
              (setq e5 (entlast))
              (command "erase" e2 "")
              (command "union" e1 e5 "")
              (command "pline" p11 p12 p13 "c")
              (setq e2 (entlast))
              (command "revolve" e2 "" ps pe 360)
              (setq e2 (entlast))
              (command "subtract" e1 "" e2 "")
       (command "copy" e1 "" ps ps)
              (setq ep (entlast))

  ;;;  画螺纹
              (command "pline" p10 p9 p8 "c")
              (setq e2 (entlast))
              (setq ph1 (polar pse (+ aa ang2) (/ d1 2.0)))
              (command "helix" pse ph1 (/ d1 2.0) "H" h1 "T" (/ b1 h1));;;;(/ d1 2.0)必须除以2.0否则画不出螺纹
              (setq e3 (entlast))
              (command "rotate3d" e3 "" "x" pse 270)
         (command "move" e3 "" pse (polar pse ang2 0.01))
         (command "move" e2 "" p7 ph1)
              (command "sweep" e2 "" "A" "N" e3)
              (setq e4 (entlast))
              (command "subtract" e1 "" e4 "")
              (command "erase" e3 "")
              (setvar "clayer" "cen_lay")
              (command "line" ps1 pe "")
              (setq e2 (entlast))
;;;绘制螺母
              (setvar "clayer" "0")
              (setvar "cecolor" "221")
              (command "move" eLL1 "" ps1 pse)
              (command "extrude" eLL1 "" (/ ML1 2.0))
              (setq eLL1 (entlast))
              (command "pline" p1 p2 p3 "c")
              (setq eL2 (entlast))
              (command "move" eL2 "" ps1 pse)
              (command "revolve" eL2 "" ps1 pe 360)
              (setq eL2 (entlast))
              (command "subtract" eLL1 "" eL2 "")
              (setq ppL (polar pse aa (/ ML1 2.0)))
              (command "mirror3d" eLL1 "" "zx" ppL "N")
              (setq eL2 (entlast))
              (command "union" eLL1 eL2 "")
;;;绘制溥螺母
  
              (command "move" eeL1"" ps1 pL1)
              (command "extrude" eeL1 "" (/ mL2 2.0))
              (setq eeL1 (entlast))
              (command "pline" p1 p2 p3 "c")
              (setq eeL2 (entlast))
              (command "move" eeL2 "" ps1 pL1)
              (command "revolve" eeL2 "" ps1 pe 360)
              (setq eeL2 (entlast))
              (command "subtract" eeL1 "" eeL2 "")
              (command "mirror3d" eeL1 "" "zx" (polar pL1 aa (/ ML2 2.0)) "N")
              (setq eeL2 (entlast))
              (command "union" eeL1 eeL2 "")
   
            );end progn
      
     );end if
;;;+++++++++++++++++++++++++++++++++++++
      (if (= aa ang3)
     (progn  
              (setvar "osmode" 0)      ;很关键,否则画线时容易出错
              (setq rr (/ s1 2.0))
              (setq ps1 (polar ps (+ aa PI) m1))
              (setq p1 (polar ps1 (+ aa (/ PI 2)) (/ s1 2.0)))
              (setq p2 (polar p1 (+ aa (/ PI 2)) HH1))
              (setq p3 (polar p2 aa LL1))
              (setq p4 (polar ps1 aa (- m1 m2)))
  
              (setq pe (polar pse aa b1))
              (setq p7 (polar pe ang4 (/ d1 2.0)))
              (setq p8 (polar p7 0 (/ LL3 2)))
              (setq p9 (polar p8 aa LL3))
              (setq p10 (polar p8 (/ (* 120 PI) 180) LL3))
              (setq p11 (polar pe (- aa (/ PI 2)) (/ d1 2.0)))
              (setq p12 (polar p11 (+ aa (/ PI 2)) LL4))
              (setq p13 (polar p11 (+ aa pi) LL4))
              (setq pr (polar ps1 aa rr))
              (setq pL1 (polar pse aa ML1))
              (setq pL2 (polar pL1 aa ML2))
              (command "polygon" 6 ps1 "c" pr)
              (setq e1 (entlast))
              (command "rotate3d" e1 "" "y" ps1 -90)
        (command "copy" e1 "" ps1 ps1)
              (setq eLL1 (entlast))
        (command "copy" e1 "" ps1 ps1)
              (setq eeL1 (entlast))
              (command "extrude" e1 "" (- m1 m2))
              (setq e1 (entlast))
              (command "pline" p1 p2 p3 "c")
              (setq e2 (entlast))
              (command "revolve" e2 "" ps1 pe 360)
              (setq e2 (entlast))
              (command "subtract" e1 "" e2 "")
              (command "circle" p4 "d" s1)
              (setq e3 (entlast))
              (command "rotate3d" e3 "" "y" p4 -90)
              (command "extrude" e3 "" m2)
              (setq e4 (entlast))
              (command "union" e1 e4 "")
              (command "line" p4 pe "")
              (setq e2 (entlast))
              (command "circle" p4 "d" d1)
              (setq e3 (entlast))
              (command "sweep" e3 "" e2)
              (setq e5 (entlast))
              (command "erase" e2 "")
              (command "union" e1 e5 "")
              (command "pline" p11 p12 p13 "c")
              (setq e2 (entlast))
              (command "revolve" e2 "" ps pe 360)
              (setq e2 (entlast))
              (command "subtract" e1 "" e2 "")
      
       (command "copy" e1 "" ps ps)
              (setq ep (entlast))
  ;;;  画螺纹
              (command "pline" p10 p9 p8 "c")
              (setq e2 (entlast))
              (setq ph1 (polar pse (+ aa ang3) (/ d1 2.0)))
              (command "helix" pse ph1 (/ d1 2.0) "H" h1 "T" (/ b1 h1));;;;(/ d1 2.0)必须除以2.0否则画不出螺纹
              (setq e3 (entlast))
         (command "move" e2 "" p7 ph1)
         (command "rotate3d" e2 "" "Y" ph1 90)
         (command "rotate3d" e2 "" "z" ph1 90)
              (command "rotate3d" e2 e3 "" "y" pse -90)

              (command "sweep" e2 "" "A" "N" e3)
              (setq e4 (entlast))
              (command "subtract" e1 "" e4 "")
              (command "erase" e3 "")
              (setvar "clayer" "cen_lay")
              (command "line" ps1 pe "")
              (setq e2 (entlast))
              (setvar "cecolor" "221")
;;;绘制螺母
              (setvar "clayer" "0")
              (setvar "cecolor" "221")
              (command "move" eLL1 "" ps1 pse)
              (command "extrude" eLL1 "" (/ ML1 2.0))
              (setq eLL1 (entlast))
              (command "pline" p1 p2 p3 "c")
              (setq eL2 (entlast))
              (command "move" eL2 "" ps1 pse)
              (command "revolve" eL2 "" ps1 pe 360)
              (setq eL2 (entlast))
              (command "subtract" eLL1 "" eL2 "")
              (setq ppL (polar pse aa (/ ML1 2.0)))
              (command "mirror3d" eLL1 "" "yz" ppL "N")
              (setq eL2 (entlast))
              (command "union" eLL1 eL2 "")
;;;绘制溥螺母
  
              (command "move" eeL1"" ps1 pL1)
              (command "extrude" eeL1 "" (/ mL2 2.0))
              (setq eeL1 (entlast))
              (command "pline" p1 p2 p3 "c")
              (setq eeL2 (entlast))
              (command "move" eeL2 "" ps1 pL1)
              (command "revolve" eeL2 "" ps1 pe 360)
              (setq eeL2 (entlast))
              (command "subtract" eeL1 "" eeL2 "")
              (command "mirror3d" eeL1 "" "yz" (polar pL1 aa (/ ML2 2.0)) "N")
              (setq eeL2 (entlast))
              (command "union" eeL1 eeL2 "")
          );end progn
      
     );end if

;;;+++++++++++++++++++++++++++++++++++++  
  
      (if (= aa ang4)
     (progn  
              (setvar "osmode" 0)      ;很关键,否则画线时容易出错
              (setq rr (/ s1 2.0))
              (setq ps1 (polar ps (+ aa PI) m1))
              (setq p1 (polar ps1 (+ aa (/ PI 2)) (/ s1 2.0)))
              (setq p2 (polar p1 (+ aa (/ PI 2)) HH1))
              (setq p3 (polar p2 aa LL1))
              (setq p4 (polar ps1 aa (- m1 m2)))
  
              (setq pe (polar pse aa b1))
              (setq p7 (polar pe ang1 (/ d1 2.0)))
              (setq p8 (polar p7 ang2 (/ LL3 2)))
              (setq p9 (polar p8 aa LL3))
              (setq p10 (polar p8 (/ (* 210 PI) 180) LL3))
              (setq p11 (polar pe (- aa (/ PI 2)) (/ d1 2.0)))
              (setq p12 (polar p11 (+ aa (/ PI 2)) LL4))
              (setq p13 (polar p11 (+ aa pi) LL4))
              (setq pr (polar ps1 aa rr))
              (setq pL1 (polar pse aa ML1))
              (setq pL2 (polar pL1 aa ML2))
              (command "polygon" 6 ps1 "c" pr)
              (setq e1 (entlast))
              (command "rotate3d" e1 "" "x" ps1 90)
        (command "copy" e1 "" ps1 ps1)
              (setq eLL1 (entlast))
        (command "copy" e1 "" ps1 ps1)
              (setq eeL1 (entlast))
              (command "extrude" e1 "" (- m1 m2))
              (setq e1 (entlast))
              (command "pline" p1 p2 p3 "c")
              (setq e2 (entlast))
              (command "revolve" e2 "" ps1 pe 360)
              (setq e2 (entlast))
              (command "subtract" e1 "" e2 "")
              (command "circle" p4 "d" s1)
              (setq e3 (entlast))
              (command "rotate3d" e3 "" "x" p4 90)
              (command "extrude" e3 "" m2)
              (setq e4 (entlast))
              (command "union" e1 e4 "")
              (command "line" p4 pe "")
              (setq e2 (entlast))
              (command "circle" p4 "d" d1)
              (setq e3 (entlast))
              (command "sweep" e3 "" e2)
              (setq e5 (entlast))
              (command "erase" e2 "")
              (command "union" e1 e5 "")
              (command "pline" p11 p12 p13 "c")
              (setq e2 (entlast))
              (command "revolve" e2 "" ps pe 360)
              (setq e2 (entlast))
              (command "subtract" e1 "" e2 "")
      
       (command "copy" e1 "" ps ps)
              (setq ep (entlast))
      
  ;;;  画螺纹
              (command "pline" p10 p9 p8 "c")
              (setq e2 (entlast))
              (setq ph1 (polar pse 0 (/ d1 2.0)))
              (command "helix" pse ph1 (/ d1 2.0) "H" h1 "T" (/ b1 h1));;;;(/ d1 2.0)必须除以2.0否则画不出螺纹
              (setq e3 (entlast))
         (command "move" e2 "" p7 ph1)
         (command "rotate3d" e2 "" "x" ph1 -90)
              (command "rotate3d" e2 e3 "" "x" pse 90)
               (command "sweep" e2 "" "b" ph1 "A" "N" e3)
              (setq e4 (entlast))
              (command "subtract" e1 "" e4 "")
              (command "erase" e3 "")
              (setvar "clayer" "cen_lay")
              (command "line" ps1 pe "")
              (setq e2 (entlast))
;;;绘制螺母
              (setvar "clayer" "0")
              (setvar "cecolor" "221")
              (command "move" eLL1 "" ps1 pse)
              (command "extrude" eLL1 "" (/ ML1 2.0))
              (setq eLL1 (entlast))
              (command "pline" p1 p2 p3 "c")
              (setq eL2 (entlast))
              (command "move" eL2 "" ps1 pse)
              (command "revolve" eL2 "" ps1 pe 360)
              (setq eL2 (entlast))
              (command "subtract" eLL1 "" eL2 "")
              (setq ppL (polar pse aa (/ ML1 2.0)))
              (command "mirror3d" eLL1 "" "zx" ppL "N")
              (setq eL2 (entlast))
              (command "union" eLL1 eL2 "")
;;;;;;绘制溥螺母
              (command "move" eeL1"" ps1 pL1)
              (command "extrude" eeL1 "" (/ mL2 2.0))
              (setq eeL1 (entlast))
              (command "pline" p1 p2 p3 "c")
              (setq eeL2 (entlast))
              (command "move" eeL2 "" ps1 pL1)
              (command "revolve" eeL2 "" ps1 pe 360)
              (setq eeL2 (entlast))
              (command "subtract" eeL1 "" eeL2 "")
              (command "mirror3d" eeL1 "" "zx" (polar pL1 aa (/ ML2 2.0)) "N")
              (setq eeL2 (entlast))
              (command "union" eeL1 eeL2 "")
    );end progn
      
     );end if
;;;  
;;;;;;求重量
    (setq file1 (open "e:/LSP/data/螺栓.txt" "a"))
    (setq bz 7.85)
    (setq en (entget ep));;;螺栓重量
    (setq en1 (car en))
    (setq en2 (cdr en1))
    (setq xobj (vlax-ename->vla-object en2)) ;转换ename为vla对象
    (setq vm (vla-get-volume xobj)) ;  直接取得对象体积mm3
    (setq vm (/ vm 1000000.0));;;;转换成dm3
    (setq wt1 (* bz vm ))
    (command "erase" ep "")
  
    (setq en (entget eLL1));;;螺母重量
    (setq en1 (car en))
    (setq en2 (cdr en1))
    (setq xobj (vlax-ename->vla-object en2)) ;转换ename为vla对象
    (setq vm (vla-get-volume xobj)) ;  直接取得对象体积mm3
    (setq vm (/ vm 1000000.0));;;;转换成dm3
    (setq wt2 (* bz vm ))
    (setq en (entget eeL1));;;溥螺母重量
    (setq en1 (car en))
    (setq en2 (cdr en1))
    (setq xobj (vlax-ename->vla-object en2)) ;转换ename为vla对象
    (setq vm (vla-get-volume xobj)) ;  直接取得对象体积mm3
    (setq vm (/ vm 1000000.0));;;;转换成dm3
    (setq wt3 (* bz vm ))

    (setq txt1 (strcat "螺栓: M" (rtos MM2) "  重量=" (rtos wt1 2 6)"kg" " 长度L=" (rtos (+ LL2 b1) 2 0) "mm"))
    (setq txt1_1 (strcat "螺栓: M" (rtos MM2) "长度L=" (rtos (+ LL2 b1) 2 2) "mm 个" " 1 单重:" (rtos wt1 2 6) " 总重: "  (rtos (* 1 wt1) 2 6) " 35号钢" " 国标(GB/T5782-2000)"))
  (write-line txt1_1 file1)
    (setq txt2 (strcat "螺母: M" (rtos MM2) "  重量=" (rtos wt2 2 6)"kg"))
    (setq txt2_1 (strcat "螺母: M" (rtos MM2)  " 个" " 1 单重:" (rtos wt2 2 6) " 总重: "  (rtos (* 1 wt2) 2 6) " Q235-A" " 国标(GB/T6170-2000)"))
   (write-line txt2_1 file1)
    (setq txt3 (strcat "溥螺母: M" (rtos MM2) "  重量=" (rtos wt3 2 6)"kg"))
    (setq txt3_1 (strcat "溥螺母: M" (rtos MM2) " 个" " 2 单重:" (rtos wt3 2 6) " 总重: "  (rtos (* 2 wt3) 2 6) " Q235-A" " 国标(GB/T6172.1-2000)"))
  (write-line txt3_1 file1)
    (close file1)
  
    (princ txt1)
    (princ "\n")
    (princ txt2)
    (princ "\n")
    (princ txt3)
  
              (setvar "cecolor" "bylayer")
              (setvar "clayer" clay)
              (setvar "CELTYPE" clt)
              (setvar "osmode" osm)
              (prin1)
  
)

抛砖玉,供参考

点评

体力活  发表于 2015-2-11 08:39
本程在屏幕上指定两点(紧固段长度)即可绘制带双螺的螺栓。  详情 回复 发表于 2015-2-9 20:59
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-2-9 20:59:06 | 显示全部楼层
heyongw@163.com 发表于 2015-2-9 20:57
(defun c:luosuan(/ clay aa ang1 ang2 ang3 ang4 b1 b2 b3 bz clt d1 dd1 dd2 ddh e1 e2 e3 e4 e5 eeL ...

本程在屏幕上指定两点(紧固段长度)即可绘制带双螺的螺栓。

点评

感谢楼主分享,可是运行时报错: 错误: 参数类型错误: lentityp nil 中断在:(entget ep) 不知是不是缺少那个txt文件? (open "e:/LSP/data/螺栓.txt" "a")  详情 回复 发表于 2015-2-9 21:54
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 3198个

财富等级: 富可敌国

发表于 2015-2-9 21:54:56 | 显示全部楼层
heyongw@163.com 发表于 2015-2-9 20:59
本程在屏幕上指定两点(紧固段长度)即可绘制带双螺的螺栓。

感谢楼主分享,可是运行时报错: 错误: 参数类型错误: lentityp nil

中断在:(entget ep)
  1. ;;;  
  2. ;;;;;;求重量
  3.     (setq file1 (open "e:/LSP/data/螺栓.txt" "a"))
  4.     (setq bz 7.85)
  5.     (setq en (entget ep));;;螺栓重量
  6.     (setq en1 (car en))
  7.     (setq en2 (cdr en1))
  8.     (setq xobj (vlax-ename->vla-object en2)) ;转换ename为vla对象
  9.     (setq vm (vla-get-volume xobj)) ;  直接取得对象体积mm3
  10.     (setq vm (/ vm 1000000.0));;;;转换成dm3
  11.     (setq wt1 (* bz vm ))
  12.     (command "erase" ep "")


不知是不是缺少那个txt文件? (open "e:/LSP/data/螺栓.txt" "a")

点评

本程序运后会将有关技术参数写入e:/LSP/data/螺栓.txt",若你电脑上有 e:\LSP\data\目录就不会提示错误。也可将"e:/LSP/data/"删除,运行时只在当前目录下生成文本文件。且不会有错误提示。  详情 回复 发表于 2015-2-10 15:17
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 2026个

财富等级: 金玉满堂

发表于 2015-2-10 09:06:00 | 显示全部楼层
本帖最后由 yxianfo 于 2015-2-10 14:35 编辑

将程序中下面的一行修改一下可解决楼上的问题:
  ;  (setq file1 (open "e:/LSP/data/螺栓.txt" "a"))
     (setq file1 (open "E:/螺栓.txt" "a"))

但是觉得螺纹的末端(即螺纹的起始位置)应比“紧固段长度”稍短才符合实际使用状态,应在程序中修改一下该参数。



点评

本程序是参照国标提供的尺寸设计的,螺栓是没有问题的,主要是螺母的位置易给人产生错觉。  详情 回复 发表于 2015-2-10 15:21
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-2-10 15:17:07 | 显示全部楼层
lucas3 发表于 2015-2-9 21:54
感谢楼主分享,可是运行时报错: 错误: 参数类型错误: lentityp nil

中断在:(entget ep)

本程序运后会将有关技术参数写入e:/LSP/data/螺栓.txt",若你电脑上有 e:\LSP\data\目录就不会提示错误。也可将"e:/LSP/data/"删除,运行时只在当前目录下生成文本文件。且不会有错误提示。

点评

以下是国标尺寸: [attachimg]13080[/attachimg] [attachimg]13081[/attachimg]  详情 回复 发表于 2015-2-10 15:26
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-2-10 15:21:33 | 显示全部楼层
yxianfo 发表于 2015-2-10 09:06
将程序中下面的一行修改一下可解决楼上的问题:
  ;  (setq file1 (open "e:/LSP/data/螺栓.txt" "a"))
...

本程序是参照国标提供的尺寸设计的,螺栓是没有问题的,主要是螺母的位置易给人产生错觉。

点评

改成(setq file1 (open "E:/螺栓.txt" "a")) ,或者删除掉E:/螺栓.txt,结果都是一样,参数类型错误: lentityp nil  详情 回复 发表于 2015-2-10 19:09
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-2-10 15:26:25 | 显示全部楼层
heyongw@163.com 发表于 2015-2-10 15:17
本程序运后会将有关技术参数写入e:/LSP/data/螺栓.txt",若你电脑上有 e:\LSP\data\目录就不会提示错误。 ...

以下是国标尺寸:
gb1.JPG
gb2.JPG
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 3198个

财富等级: 富可敌国

发表于 2015-2-10 19:09:50 | 显示全部楼层
本帖最后由 lucas3 于 2015-2-10 19:12 编辑
heyongw@163.com 发表于 2015-2-10 15:21
本程序是参照国标提供的尺寸设计的,螺栓是没有问题的,主要是螺母的位置易给人产生错觉。

改成(setq file1 (open "E:/螺栓.txt" "a")) ,或者删除掉E:/螺栓.txt,结果都是一样,参数类型错误: lentityp nil

改成(setq file1 (open "E:/螺栓.txt" "a")) 后, 会在E盘建立一个 螺栓.txt 文件

点评

你没看清我的回复,我说的删除"e:/LSP/data/",注意是双引中的部分,即跟8楼说的一样  详情 回复 发表于 2015-2-11 16:45
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-2-11 16:45:32 | 显示全部楼层
lucas3 发表于 2015-2-10 19:09
改成(setq file1 (open "E:/螺栓.txt" "a")) ,或者删除掉E:/螺栓.txt,结果都是一样,参数类型错误: len ...

你没看清我的回复,我说的删除"e:/LSP/data/",注意是双引中的部分,即跟8楼说的一样

点评

换了几台电脑,几个CAD版本,终于发现,选择10,12的螺栓,怎么都是参数错误, 但是选择M5,M3的,都可以绘制出  详情 回复 发表于 2015-3-10 14:40
奇怪,之前的回复不见了,重回下: 我是删除的双引号中的部分, 仍然显示参数类型错误: lentityp nil 如果连双引号一起删除,就会显示 缺少参数  详情 回复 发表于 2015-2-15 11:52
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 3198个

财富等级: 富可敌国

发表于 2015-2-15 11:52:32 | 显示全部楼层
heyongw@163.com 发表于 2015-2-11 16:45
你没看清我的回复,我说的删除"e:/LSP/data/",注意是双引中的部分,即跟8楼说的一样

奇怪,之前的回复不见了,重回下:

我是删除的双引号中的部分, 仍然显示参数类型错误: lentityp nil
如果连双引号一起删除,就会显示 缺少参数
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 67个

财富等级: 招财进宝

发表于 2015-3-3 12:29:54 | 显示全部楼层
谢谢楼主分享提供源码程序,下载学习。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-24 09:40 , Processed in 0.507686 second(s), 73 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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