乐筑天下

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

[编程交流] DCL中的复选框

[复制链接]

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 16:57:37 | 显示全部楼层
我无法抗拒:
 
  1. (defun C:test ( / *error* dcl des dch dcf L r mann perc ChosenDiameters )
  2. (defun *error* ( msg )
  3.    (and (< 0 dch) (unload_dialog dch))
  4.    (and (eq 'FILE (type des)) (close des))
  5.    (and (eq 'STR (type dcl)) (findfile dcl) (vl-file-delete dcl))
  6.    (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\nError: " msg)) ))
  7.    (princ)
  8. ); defun *error*
  9. (if
  10.    (and ; write the dialog on the fly - temporary use
  11.      (setq dcl (vl-filename-mktemp nil nil ".dcl"))
  12.      (setq des (open dcl "w"))
  13.      (princ
  14.        (strcat
  15.          "samp8 : dialog"
  16.          "{ label = "Pipe Lines";"
  17.          "  : row"
  18.          "  { : boxed_column"
  19.          "    { label = "Pipe diameters used (mm)"; spacer;"
  20.          "      : list_box { key = "LB"; multiple_select = true; width = 10; height = 15; }"
  21.          "    }"
  22.          "    : boxed_column "
  23.          "    { label = "Variables";"
  24.          "      : edit_box { key = "eb1"; label = "Manning 'n'"; edit_width = 6 ; value = "0.013"; }"
  25.          "      : edit_box { key = "eb2"; label = "% part full"; edit_width = 6 ; value = "50"; }"
  26.          "    }"
  27.          "  }"
  28.          "  ok_cancel;"
  29.          "}"
  30.        ); strcat
  31.        des
  32.      ); princ
  33.      (not (setq des (close des)))
  34.      (setq dch (load_dialog dcl))
  35.      (new_dialog "samp8" dch)
  36.    ); and
  37.    (progn
  38.      ; Populate the list_box tile:
  39.      (start_list "LB")
  40.      (mapcar 'add_list (setq L '("150" "200" "225" "250" "300" "375" "450" "600")))
  41.      (end_list)
  42.      ; Set the first item as default value in the list box:
  43.      (set_tile "LB" "0")
  44.      ; Set default values - if ok is pressed without any input:
  45.      (setq r (get_tile "LB"))
  46.      (setq mann (get_tile "eb1"))
  47.      (setq perc (get_tile "eb2"))
  48.      ; Set default actions for the tiles:
  49.      (action_tile "LB" "(setq r $value)")
  50.      (action_tile "eb1" "(setq mann $value)")
  51.      (action_tile "eb2" "(setq perc $value)")
  52.      (action_tile "accept" "(done_dialog 1)")
  53.      ; Store the result - if user pressed OK, dcf will be 1, else 0
  54.      (setq dcf (start_dialog))
  55.    ); progn
  56. ); if
  57. (*error* nil) ; unload, and erase the temporary dcl file
  58. ; Check if user pressed OK
  59. (if (= 1 dcf)
  60.    (alert ; Display the results:
  61.      (strcat
  62.        "\nList of selected diameters: \n"
  63.        (vl-prin1-to-string (setq ChosenDiameters (mapcar '(lambda (x) (nth x L)) (read (strcat "(" r ")")))))
  64.        "\nManning: " mann
  65.        "\nPercentage: " perc
  66.      ); strcat
  67.    ); alert
  68. ); if
  69. (princ)
  70. ); defun

当然要归功于李·麦克(但基本上我写的每一个DCL代码,他都隐藏在那个里——就我所知)。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 17:01:43 | 显示全部楼层
了解你想要能够从列表中选择多个大小签出李mac listbox lsp允许多选择我也会签出它。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 17:03:42 | 显示全部楼层
  1. ; credit to lee-mac for original dcl list routine
  2. (defun C:samp8 ( )
  3. (setq lst (list "150" "200" "225" "250" "300" "375" "450" "600"))
  4. (setq rtn '())
  5. (setq dcl_id (load_dialog "c:\\acadtemp\\samp8.dcl")) ; change directory path to known location
  6. (if (not (new_dialog "samp8" dcl_id))
  7. (exit)
  8. )
  9. (set_tile "eb1" "0.013")
  10. (set_tile "eb2" "50")
  11. (start_list "list")
  12. (foreach itm lst (add_list itm))
  13. (end_list)
  14. (setq ans (set_tile "list" "0"))
  15. (action_tile "list" "(setq rtn (cons (atof (nth (atoi $value) lst)) rtn))")
  16. (action_tile "eb1" "(setq mann (atof $value))")
  17. (action_tile "eb2" "(setq perc (atof $value))")
  18. (start_dialog)
  19. (unload_dialog dcl_id)
  20. (alert "use !rtn !perc !mann to see answers") ; rub this line out later
  21. )
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 17:07:59 | 显示全部楼层
多选列表框的$value字符串可以包含多个整数(例如“5 1 3”)。你可以用这样的方法来处理它:
  1. (action_tile "list" "(setq rtn (mapcar '(lambda (idx) (nth idx lst)) (read (strcat "(" $value ")"))))")
回复

使用道具 举报

53

主题

302

帖子

249

银币

后起之秀

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

铜币
265
发表于 2022-7-5 17:11:52 | 显示全部楼层
谢谢BIGAL、Grrr和Roy,
我试图找到一个解决方案的目的是自动为特定流量选择最合适的直径和斜率,以及其他适用的条件,如值n和“满载百分比”。我能够在我的第1条帖子中成功地使用dcl,并在他的第4条帖子中很好地捕获Grrr给出的选择的方法,如下所示:
  1. (defun C:samp11 ()
  2. (setq dcl_id(load_dialog "samp11.dcl"))
  3. (if(not(new_dialog "samp11" dcl_id)
  4.     )
  5.    (exit)
  6. )
  7. (action_tile "tog1"
  8. (vl-prin1-to-string
  9.    '(cond
  10.       ( (= "0" $value) (setq t1 nil))
  11.       ( (= "1" $value) (setq t1 150)))))
  12. (action_tile "tog2"
  13. (vl-prin1-to-string
  14.    '(cond
  15.       ( (= "0" $value) (setq t2 nil))
  16.       ( (= "1" $value) (setq t2 200)))))
  17. (action_tile "tog3"
  18. (vl-prin1-to-string
  19.    '(cond
  20.       ( (= "0" $value) (setq t3 nil))
  21.       ( (= "1" $value) (setq t3 225)))))
  22. (action_tile "tog4"
  23. (vl-prin1-to-string
  24.    '(cond
  25.       ( (= "0" $value) (setq t4 nil))
  26.       ( (= "1" $value) (setq t4 250)))))
  27. (action_tile "tog5"
  28. (vl-prin1-to-string
  29.    '(cond
  30.       ( (= "0" $value) (setq t5 nil))
  31.       ( (= "1" $value) (setq t5 300)))))
  32. (action_tile "tog6"
  33. (vl-prin1-to-string
  34.    '(cond
  35.       ( (= "0" $value) (setq t6 nil))
  36.       ( (= "1" $value) (setq t6 375)))))
  37. (action_tile "tog7"
  38. (vl-prin1-to-string
  39.    '(cond
  40.       ( (= "0" $value) (setq t7 nil))
  41.       ( (= "1" $value) (setq t7 450)))))
  42. (action_tile "tog8"
  43. (vl-prin1-to-string
  44.    '(cond
  45.       ( (= "0" $value) (setq t8 nil))
  46.       ( (= "1" $value) (setq t8 600)))))
  47. (start_dialog)
  48. (unload_dialog dcl_id)
  49. )
  50. (defun pdandslope()
  51. (setq lst nil)
  52. (setq p150 '((150.0 120.0) (150.0 110.0) (150.0 100.0)))
  53. (setq p200 '((200.0 150.0) (200.0 140.0) (200.0 120.0)))
  54. (setq p225 '((225.0 180.0) (225.0 170.0) (225.0 160.0) (225.0 150.0)))
  55. (setq p250 '((250.0 200.0) (250.0 180.0) (225.0 170.0) (225.0 160.0)))
  56. (setq p300 '((300.0 300.0) (300.0 280.0) (300.0 260.0) (300.0 250.0) (300.0 240.0) (300.0 220.0)
  57.               (300.0 200.0) (300.0 180.0)))
  58. (setq p375 '((375.0 350.0) (375.0 320.0) (375.0 300.0) (375.0 280.0)))
  59. (setq p450 '((450.0 400.0) (450.0 370.0) (450.0 350.0) (450.0 320.0)))
  60. (setq p600 '((600.0 500.0) (600.0 450.0) (600.0 420.0) (600.0 400.0)))  
  61. (if (= t1 150)
  62. (setq lst(cons p150 lst))
  63. )
  64. (if (= t2 200)
  65. (setq lst(cons p200 lst))
  66. )
  67. (if (= t3 225)
  68. (setq lst(cons p225 lst))
  69. )
  70. (if (= t4 250)
  71. (setq lst(cons p250 lst))
  72. )
  73. (if (= t5 300)
  74. (setq lst(cons p300 lst))
  75. )
  76. (if (= t6 375)
  77. (setq lst(cons p375 lst))
  78. )
  79. (if (= t7 450)
  80. (setq lst(cons p450 lst))
  81. )
  82. (if (= t8 600)
  83. (setq lst(cons p600 lst))  
  84. )
  85. (setq lst(reverse lst))
  86. )  

 
列表“lst”已成功用于其他地方,以获得最终结果。谢谢你指导我。
芦荟
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:14:26 | 显示全部楼层
我建议如下:
  1. ([color=BLUE]defun[/color] c:samp12 ( [color=BLUE]/[/color] bit cnt dch lst rtn )
  2.    ([color=BLUE]setq[/color] lst
  3.       '(
  4.            ((150.0 120.0) (150.0 110.0) (150.0 100.0))
  5.            ((200.0 150.0) (200.0 140.0) (200.0 120.0))
  6.            ((225.0 180.0) (225.0 170.0) (225.0 160.0) (225.0 150.0))
  7.            ((250.0 200.0) (250.0 180.0) (225.0 170.0) (225.0 160.0))
  8.            ((300.0 300.0) (300.0 280.0) (300.0 260.0) (300.0 250.0) (300.0 240.0) (300.0 220.0) (300.0 200.0) (300.0 180.0))
  9.            ((375.0 350.0) (375.0 320.0) (375.0 300.0) (375.0 280.0))
  10.            ((450.0 400.0) (450.0 370.0) (450.0 350.0) (450.0 320.0))
  11.            ((600.0 500.0) (600.0 450.0) (600.0 420.0) (600.0 400.0))
  12.        )
  13.    )
  14.    ([color=BLUE]cond[/color]
  15.        (   ([color=BLUE]<=[/color] ([color=BLUE]setq[/color] dch ([color=BLUE]load_dialog[/color] [color=MAROON]"samp11.dcl"[/color])) 0)
  16.            ([color=BLUE]princ[/color] [color=MAROON]"\nsamp11.dcl not found or could not be loaded."[/color])
  17.        )
  18.        (   ([color=BLUE]not[/color] ([color=BLUE]new_dialog[/color] [color=MAROON]"samp11"[/color] dch))
  19.            ([color=BLUE]princ[/color] [color=MAROON]"\nError in samp11.dcl file."[/color])
  20.        )
  21.        (   ([color=BLUE]setq[/color] bit 1 cnt 1 rtn 0)
  22.            ([color=BLUE]repeat[/color] ([color=blue]length[/color] lst)
  23.                ([color=BLUE]action_tile[/color]
  24.                    ([color=BLUE]strcat[/color] [color=MAROON]"tog"[/color] ([color=BLUE]itoa[/color] cnt))
  25.                    ([color=BLUE]strcat[/color] [color=MAROON]"(setq rtn (boole (+ 4 (* 3 (atoi $value))) "[/color] ([color=BLUE]itoa[/color] bit) [color=MAROON]" rtn))"[/color])
  26.                )
  27.                ([color=BLUE]setq[/color] bit ([color=BLUE]lsh[/color] bit 1) cnt ([color=BLUE]1+[/color] cnt))
  28.            )
  29.            ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]start_dialog[/color]))
  30.                ([color=BLUE]setq[/color] bit 1
  31.                      lst
  32.                    ([color=BLUE]vl-remove-if[/color]
  33.                       '([color=BLUE]lambda[/color] ( x [color=BLUE]/[/color] flg ) ([color=BLUE]setq[/color] flg ([color=BLUE]zerop[/color] ([color=BLUE]logand[/color] bit rtn)) bit ([color=BLUE]lsh[/color] bit 1)) flg)
  34.                        lst
  35.                    )
  36.                )
  37.            )
  38.        )
  39.    )
  40.    ([color=BLUE]if[/color] ([color=BLUE]<[/color] 0 dch) ([color=BLUE]unload_dialog[/color] dch))
  41.    ([color=BLUE]princ[/color])
  42. )

 
此列表格式更好:
  1. (setq lst
  2. '(
  3.    ((150.0 120.0) (150.0 110.0) (150.0 100.0))
  4.    ((200.0 150.0) (200.0 140.0) (200.0 120.0))
  5.    ((225.0 180.0) (225.0 170.0) (225.0 160.0) (225.0 150.0))
  6.    ((250.0 200.0) (250.0 180.0) (225.0 170.0) (225.0 160.0))
  7.    ((300.0 300.0) (300.0 280.0) (300.0 260.0) (300.0 250.0) (300.0 240.0) (300.0 220.0) (300.0 200.0) (300.0 180.0))
  8.    ((375.0 350.0) (375.0 320.0) (375.0 300.0) (375.0 280.0))
  9.    ((450.0 400.0) (450.0 370.0) (450.0 350.0) (450.0 320.0))
  10.    ((600.0 500.0) (600.0 450.0) (600.0 420.0) (600.0 400.0))
  11. )
  12. )

 
如果每个项目的第一个子项目相同。
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 17:17:25 | 显示全部楼层
我想知道你在做什么,可能有更好的方法,如果你看一个管道的流量公式,它包括坡度作为其计算的一部分,给定一个流量,从150开始,你会得到一个坡度答案,如果这是垂直的,然后转到下一个直径,直到它开始给出一个合理的坡度答案,然后你可以说做+或-并锁定管道直径。这是许多民用排水设计软件采用的一种方法,从种子流开始,增加直径。在我们的例子中,是一个带有上下箭头的拨号箱。
 
我将其用于即时流,只需使用pline绘制管道真实尺寸的圆或通道的形状,并可以水平修剪以计算出明渠尺寸。
  1. (setq lst
  2. '(
  3.    (150.0 (120.0 110.0 100.0))
  4.    (200.0 (150.0 140.0 120.0))
  5.    (225.0 (180.0 170.0 160.0 150.0))
  6.    (250.0 (200.0 180.0))
  7.    (300.0 (300.0 280.0 260.0 250.0 240.0 220.0 200.0 180.0))
  8.    (375.0 (320.0 300.0 280.0))
  9.    (450.0 (400.0 370.0 350.0 320.0))
  10.    (600.0 (500.0 450.0 420.0 400.0))
  11. )
  12. )

 
q=AR2/3*(sqrt斜率)/n
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 17:19:26 | 显示全部楼层
 
令人印象深刻,我什么都不懂!
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 17:24:48 | 显示全部楼层
整洁又漂亮。它通过使lst全球化而起作用。
非常感谢李。
回复

使用道具 举报

53

主题

302

帖子

249

银币

后起之秀

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

铜币
265
发表于 2022-7-5 17:25:55 | 显示全部楼层
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-8-20 22:05 , Processed in 1.660380 second(s), 72 queries .

© 2020-2025 乐筑天下

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