乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 26|回复: 13

[编程交流] 环虽然

[复制链接]

33

主题

96

帖子

65

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
170
发表于 2022-7-6 07:30:06 | 显示全部楼层 |阅读模式
我想我知道我需要“while”,但不知道该放在哪里,也不知道我错过了什么。我试了几个地方,但似乎什么都不对。我查看了所有其他帖子和网站。我理解它的功能,但我一定没有正确使用它。我希望它重复绘图并标记梁,直到我退出。
 
 
  1. ;Version 1.02
  2. (defun C:bd(/ width depth membr suffix suffixs prx tsz dpth wdth label label2 label1)
  3. (setq     lsttsz ' ("11x17" "24x36")
  4.          lstmembr '("Flush Beam" "Header/Drop Beam")
  5.          lstprx '("1 ply" "2 ply" "3 ply")
  6.          lstwidth '("1.5" "1.75" "3" "3.5" "4.5" "5.25" "7" "2.5")
  7.          lstdepth '("5.5" "6" "7.25" "8" "9.25" "9.5" "10" "11.25" "11.875" "12" "14" "16" "18" "24")
  8.          lstsuffix '("PSL" "LVL" "LSL")
  9.   lstsuffixs '("FRB" "UWA" "UCA" "nothing"));end setq
  10. (or tsz (setq tsz (car lsttsz)))
  11. (or membr (setq membr (car lstmembr)))
  12. (or prx (setq prx (car lstprx)))
  13. (or width (setq width (car lstWidth)))
  14. (or depth (setq depth (car lstDepth)))
  15. (or suffix (setq suffix (car lstsuffix)))
  16. (or suffixs (setq suffixs (car lstsuffixs)))
  17. (setq dcl_id (load_dialog "beam.dcl"))                     
  18. (if (not (new_dialog "beam" dcl_id)) (exit))                        
  19.    (progn
  20.        (set_tile tsz "1")
  21.        (set_tile membr "1")
  22.        (set_tile prx "1")
  23.        (set_tile width "1")
  24.        (set_tile depth "1")
  25.        (set_tile suffix "1")
  26.        (set_tile suffixs "1")
  27.      (action_tile "tsz" "(setq tsz $value)")
  28.      (action_tile "membr" "(setq membr $value)")
  29.      (action_tile "prx" "(setq prx $value)")
  30.      (action_tile "width" "(setq width $value)")
  31.      (action_tile "depth" "(setq depth $value)")
  32.      (action_tile "suffix" "(setq suffix $value)")
  33.      (action_tile "suffixs" "(setq suffixs $value)"));end progn
  34.        (start_dialog)
  35.        (unload_dialog dcl_id)
  36. ;;;----set variables -------------------------------------
  37. ;(setvar expert 1)
  38. (setq layerset (getvar "clayer")
  39. orthoset (getvar "orthomode")
  40. polyset  (getvar "plinewid")
  41. );setq
  42. ;------------What size text for border  -------------------
  43. (if(= tsz "11x17") (setq tsz1 "6"))
  44. (if(= tsz "24x36")(setq tsz1 "4.5"))
  45. ;------------Which layer it draws the beam on-------------------
  46. (if(= membr "Flush Beam") (setq layer_name "S-FRM-BEAM"))
  47. (if(= membr "Header/Drop Beam")(setq layer_name "S-FRM-HEADER"))
  48. (command "expert" "1" "")
  49. ;-------------Creat layers for beam-------------------------------  
  50. (command "_.layer" "M" layer_name "c" "12" layer_name "S" layer_name "")
  51. ;-----------------draw beams -------------------------  
  52. (command "pline" pause "w" width width pause "")
  53. ;----------change thickness of polyline----------------  
  54. (command "chprop" "l" "" "t" depth "")
  55. ;----------change text size and style-------------------  
  56.    (command "textsize" tsz1 "")
  57. (command "_.style" "romans" "romans" "0" "0.80" "" "" "" "")
  58. ;-------------Creat layers for text-------------------------------  
  59. (command "_.layer" "M" "S-ANNO-TEXT" "c" "1" "S-ANNO-TEXT" "S" "S-ANNO-TEXT" "")
  60. (and (setq ss (ssget "L" '((0 . "*polyline"))))
  61.        (while (setq en (ssname ss 0))
  62.            (setq ed (entget en))
  63.            (setq p10 (cdr (assoc 10 ed)))
  64.            (setq p9 (reverse ed))
  65.            (setq p11 (cdr (assoc 10 p9)))
  66.           (setq mpt (mapcar '(lambda (a b) (* (+ a b) 0.5)) p10 p11))
  67.            (setq ltype (cdr (cond
  68.     ((assoc 6 ed)))))
  69.            (setq dpth (cdr (cond
  70.     ((assoc 39 ed)))))
  71.            (setq wdth (cdr (cond
  72.     ((assoc 40 ed)))))
  73. ;---------How many plys the member has----------
  74. (cond
  75.     ((= prx "1 ply") (and (< width "1.75")(setq label2 "")))
  76.     ((= prx "2 ply")(setq label2 "2~"))
  77.     ((= prx "3 ply")(setq label2 "3~")));end cond
  78. ;----------Width of the member---------      
  79. (cond
  80.     ((= wdth 1.5)(setq label "2x"
  81.       suffix ""))
  82.     ((= wdth 1.75)(setq label "1.75x"))
  83.     ((= wdth 2.5)(setq label "I-JOIST/BEAM"
  84.                      label2 ""
  85.        dpth 0
  86.        suffix ""))
  87.     ((= wdth 3)(setq label "2x"
  88.      suffix "" ))      
  89.     ((= wdth 3.5)(setq label "3.5x"
  90.        label2 ""))
  91.     ((= wdth 4.5)(setq label "2x"
  92.        suffix ""))
  93.     ((= wdth 5.25)(setq label "5.25x"
  94.         label2 ""))
  95.     ((= wdth 7)(setq label "7x"
  96.      label2 "")));end cond
  97. ;----------Depth of the Member-------------      
  98. (cond
  99. ((= dpth 5.5)(setq label1 (rtos dpth 2 1)))
  100. ((= dpth 6)(setq label1 (rtos dpth 2 0)))
  101. ((= dpth 7.25)(setq label1 (rtos dpth 2 2)))
  102. ((= dpth 9.25)(setq label1 (rtos dpth 2 2)))
  103. ((= dpth 9.5)(setq label1 (rtos dpth 2 1)))
  104. ((= dpth (setq label1 (rtos dpth 2 0)))
  105. ((= dpth 10)(setq label1 (rtos dpth 2 0)))
  106. ((= dpth 11.25)(setq label1 (rtos dpth 2 2)))
  107. ((= dpth 12)(setq label1 (rtos dpth 2 0)))
  108. ((= dpth 11.875)(setq label1 (rtos dpth 2 3)))
  109. ((= dpth 14)(setq label1 (rtos dpth 2 0)))
  110. ((= dpth 16)(setq label1 (rtos dpth 2 0)))
  111. ((= dpth 18)(setq label1 (rtos dpth 2 0)))
  112. ((= dpth 24)(setq label1 (rtos dpth 2 0)))      
  113. ((= dpth 0)(setq label1 "")));end cond
  114. (defun radians->degrees (r)(cvunit r "radian" "degree"))
  115. ;-------TEXT JUSTIFICATION----------------------------------------     
  116. (setq lan (angle p10 p11))
  117.       (setq ad (radians->degrees lan))
  118.       (if (and (> ad 90.1) (<= ad 270.1))
  119.         (progn
  120.           (setq ptemp p10
  121.                 p10 p11
  122.                 p11 ptemp
  123.                 lan (angle p10 p11)  
  124.                 ad (radians->degrees lan))))
  125.       (setq dir (if (< (* pi 0.5) lan (* pi 1.5)) - +))
  126.                   (setq r3(entmake (list (cons 0 "TEXT")
  127.                           (cons 8 (getvar "CLAYER"))
  128.                           (cons 7 (getvar "TEXTSTYLE"))
  129.                           (cons 40 (getvar "TEXTSIZE"))
  130.                           (cons 41 0.80)
  131.      (cons 72 4)
  132.             (setq fg(cons 10 ' (0.0 0.0)));(setq r1(polar mpt (dir lan (+ 1))
  133.                                    ;(getvar "TEXTSIZE")))))
  134.                           (setq hg(cons 11 (setq r2(polar mpt (dir lan (* 0.5 pi));(+ 1))
  135.                                   (+ (* 0.5 (atof width)) (* 0.8 (getvar "TEXTSIZE")))))))
  136.                           (setq gg(cons 50 lan))
  137.                          (setq rg(cons 1 (strcat label2 label label1 suffix suffixs))))))
  138.                   (ssdel en ss)))
  139. ;---------------------reset vars-----------
  140. (setvar "clayer" layerset)
  141. (setvar "orthomode" orthoset)  
  142. (setvar "plinewid"  polyset)
  143. (command "expert" "0" "")
  144. (princ)
  145. )

 
  1. beam : dialog {
  2. label = "Pick a Member";
  3.      : row {
  4.        : boxed_radio_row {key = "tsz";
  5.          label = "Text Size";
  6.          : radio_button {
  7.            label = "11x17";
  8.            key = "11x17";
  9.          }
  10.          : radio_button {
  11.            label = "24x36";
  12.            key = "24x36";
  13.            }}}
  14.      : row {
  15.        : boxed_radio_row {key = "membr";
  16.          label = "Member";
  17.          : radio_button {
  18.            label = "Flush Beam";
  19.            key = "Flush Beam";
  20.          }
  21.          : radio_button {
  22.            label = "Header/Drop Beam";
  23.            key = "Header/Drop Beam";
  24.            }}}
  25.             : row {
  26.        : boxed_radio_row {key = "prx";
  27.          label = "Preffix";
  28.          : radio_button {
  29.            label = "1 Ply";
  30.            key = "1 ply";
  31.          }
  32.          : radio_button {
  33.            label = "2 Ply";
  34.            key = "2 ply";
  35.          }
  36.          : radio_button {
  37.            label = "3 Ply";
  38.            key = "3 ply";
  39.          }}}
  40.      : row {
  41.        : boxed_radio_row {key = "width";
  42.          label = "Width";
  43.           : radio_button {
  44.            label = "1.5 (SGL 2x)";
  45.            key = "1.5";
  46.          }
  47.          : radio_button {
  48.            label = "1.75";
  49.            key = "1.75";
  50.          }
  51.            : radio_button {
  52.            label = "3 (DBL 2x)";
  53.            key = "3";
  54.          }
  55.          : radio_button {
  56.            label = "3.5";
  57.            key = "3.5";
  58.          }
  59.           : radio_button {
  60.            label = "4.5 (TPL 2x)";
  61.            key = "4.5";
  62.          }
  63.          : radio_button {
  64.            label = "5.25";
  65.            key = "5.25";
  66.          }
  67.          : radio_button {
  68.            label = "7";
  69.            key = "7";
  70.          }
  71.          : radio_button {
  72.            label = "I-JOIST/BEAM";
  73.            key = "2.5";
  74.          }}}
  75.       : row {
  76.        : boxed_radio_row {key = "depth";
  77.          label = "Depth";
  78.          : radio_button {
  79.            label = "5.5";
  80.            key = "5.5";
  81.          }
  82.           : radio_button {
  83.            label = "2x6";
  84.            key = "6";
  85.          }
  86.          : radio_button {
  87.            label = "7.25";
  88.            key = "7.25";
  89.          }
  90.           : radio_button {
  91.            label = "2x8";
  92.            key = "8";
  93.          }
  94.          : radio_button {
  95.            label = "9.25";
  96.            key = "9.25";
  97.          }
  98.           : radio_button {
  99.            label = "9.5";
  100.            key = "9.5";
  101.          }
  102.           : radio_button {
  103.            label = "2x10";
  104.            key = "10";
  105.          }
  106.          : radio_button {
  107.            label = "11.25";
  108.            key = "11.25";
  109.          }
  110.          : radio_button {
  111.            label = "11.875";
  112.            key = "11.875";
  113.          }
  114.           : radio_button {
  115.            label = "2x12";
  116.            key = "12";
  117.          }         
  118.          : radio_button {
  119.            label = "14";
  120.            key = "14";
  121.          }
  122.          : radio_button {
  123.            label = "16";
  124.            key = "16";
  125.          }
  126.          : radio_button {
  127.            label = "18";
  128.            key = "18";
  129.          }
  130.           : radio_button {
  131.            label = "24";
  132.            key = "24";
  133.          }}}
  134.     : row {
  135.        : boxed_radio_row {key = "suffix";
  136.          label = "Suffix";
  137.          : radio_button {
  138.            label = "PSL";
  139.            key = " PSL";
  140.          }
  141.          : radio_button {
  142.            label = "LVL";
  143.            key = " LVL";
  144.          }
  145.          : radio_button {
  146.            label = "LSL";
  147.            key = " LSL";
  148.          }
  149.          }}
  150.   : row {
  151.        : boxed_radio_row {key = "suffixs";
  152.          label = "Suffixs";
  153.          : radio_button {
  154.            label = "FRB";
  155.            key = " FRB";
  156.          }
  157.            : radio_button {
  158.            label = "UWA";
  159.            key = " UWA";
  160.          }
  161.          : radio_button {
  162.            label = "UCA";
  163.            key = " UCA";
  164.          }
  165.          : radio_button {
  166.            label = "NOTHING";
  167.            key = "";
  168.          }
  169.          }}
  170.      : row {
  171.        : button {
  172.          label = "&OK";
  173.          key = "accept";      
  174.          fixed_width = true;
  175.          is_default = true;
  176.          alignment = centered;
  177.        }  
  178.        : button {
  179.          label = "&Cancel";
  180.          key = "cancel";        
  181.          fixed_width = true;
  182.          is_cancel = true;
  183.          alignment = centered;
  184.        }}
  185.      : paragraph {
  186.       :text_part {
  187.       label = "PTS Inc.";
  188.       alignment = centered;      
  189.       }
  190.        :text_part {
  191.       label = "Version 1.02";
  192.       alignment = centered;      
  193.       }}
  194. }
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-6 07:35:39 | 显示全部楼层
我对此不太确定。while基本上具有这样的结构:
  1. (while condition
  2. operation1
  3. operation2
  4. ...
  5. operationN
  6. )
如果条件返回除nil以外的任何值,则所有操作都将运行。只有当条件=nil时,循环才会停止。
 
在你的例子中,我认为条件永远不会返回nil,因此循环永远不会结束。我认为问题是你总是从选择集中提取第一个项目。您应该使用一个计数器变量来提取next,然后提取next,等等,直到没有更多,并且ssname-->nil-->停止while。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:39:54 | 显示全部楼层
在底部,他/她有:
然而,这是一种在选择集上迭代的非常低效的方法,因为必须为处理的每个实体更新所有剩余实体的索引。
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-6 07:44:59 | 显示全部楼层
哦凹痕让我有点不舒服。我没有数一数所有的括号来计算循环的开始和停止位置,所以当我没有看到它在我预期的位置时,我认为这就是问题所在。
 
无论如何,更清楚一点OP想要什么:你想每次打开对话框直到你点击取消按钮吗?然后,您可能需要从start\u对话框调用中获取返回值,并检查是否为1-可能会将其添加到while循环的条件部分(将unload\u对话框移到末尾右侧的外侧),然后围绕其他所有内容继续while循环,直到重置变量之前。
 
顺便说一句,您可能需要研究错误处理,因为您正在设置一些sysvars。尤其是当你要按Esc键来“停止”这个程序时。
回复

使用道具 举报

33

主题

96

帖子

65

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
170
发表于 2022-7-6 07:49:05 | 显示全部楼层
Irnbe,
我希望盒子不要再出现。只需继续绘制和标记梁。
 
李,
我在这方面是新手,所以我从这个论坛的其他人那里获得了一部分代码。我请求帮助对一条线的长度进行多重标记。所以有没有办法做到这一点,并改变这一部分。你有没有办法向我解释一下,这样我就可以自己动手学习了,还是打字太多了?我希望有一天我能来这里帮助别人,而不是寻求帮助。在我来寻求帮助之前,我试着自己做了几天。我正在尽我所能寻找新的阅读和学习材料。像你的网站,这个论坛帖子,其他论坛,其他人的网站和书籍。
 
谢谢你们的信息,我会继续寻找另一种方式。
 
我也是一个他。英雄联盟
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:56:02 | 显示全部楼层
 
有几种方法可以迭代选择集中的所有对象,一些方法更直观,其他方法更有效。
 
下面我将提供一些示例来演示各种不同的方法,并尽我所能简要解释每种方法的工作原理及其操作效率。
 
因此,我提出:
 
选择集处理简介。。。
作者:Lee Mac
 
在以下所有示例中,将提示用户选择对象,示例程序将迭代选择集,打印每个实体的实体类型(或在Visual LISP示例中为VLA对象的对象名称)。
 
为了简单易读,许多示例已扩展为使用多个变量,随后可以通过嵌套表达式缩短,但这不是本教程的目的。
 
方法1:while
 
以下函数使用while循环在选择集上迭代。计数器变量i初始化为0,限制变量n设置为选择集的大小。
 
如果计数器小于集合中的项数,则while循环的测试条件将评估为T。
 
然后,计数器变量在while循环中顺序递增,确保在处理完所有实体后循环终止。
 
注意,所有选择集都有一个从零开始的索引,因此选择中的第一个实体位于索引0,最后一个实体位于索引sslength-1
 
  1. ([color=BLUE]defun[/color] c:test1 ( [color=BLUE]/[/color] e i n s x )
  2.    ([color=BLUE]if[/color] ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color]))
  3.        ([color=BLUE]progn[/color]
  4.            ([color=BLUE]setq[/color] i 0
  5.                  n ([color=BLUE]sslength[/color] s)
  6.            )
  7.            ([color=BLUE]while[/color] ([color=BLUE]<[/color] i n)
  8.                ([color=BLUE]setq[/color] e ([color=BLUE]ssname[/color] s i)
  9.                      x ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] e)))
  10.                      i ([color=BLUE]1+[/color] i)
  11.                )
  12.                ([color=BLUE]print[/color] x)
  13.            )
  14.        )
  15.    )
  16.    ([color=BLUE]princ[/color])
  17. )

 
 
 
  1. 5
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-6 07:59:46 | 显示全部楼层
看了这个,你知道怎么用我的Lisp程序吗?我一直在尝试不同的事情,但没有成功。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 08:05:28 | 显示全部楼层
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 08:07:26 | 显示全部楼层
Great explanations indeed ,
 
I wish I had seen explanations like this before , before I had to push my self so hard to know how things are running
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 08:11:54 | 显示全部楼层
Thanks Tharwat, glad it helps!
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 04:43 , Processed in 0.830432 second(s), 83 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表