乐筑天下

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

[编程交流] 变量

[复制链接]

145

主题

590

帖子

446

银币

中流砥柱

Rank: 25

铜币
725
发表于 2022-7-6 14:15:51 | 显示全部楼层 |阅读模式
你好
我想设置一些变量,将文本与变量部分结合起来,生成一个新变量。
 
前任:
  1. (setq a 1500)
  2. (setq b "CCC_DR" + a)
  3. (setq c "CCC_Services" + a)

 
然后,我将使用b和c创建一个具有组合名称的层和alinetype。
 
谢谢
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 14:37:30 | 显示全部楼层
变量只能是一种类型,即字符串、整数、实数、列表等。
 
您可以使用“type”函数测试此类型(显然…)。。
 
因此,如果变量“a”是整数,则在将其与组合之前,需要将其转换为字符串
 
  1. "CCC_DR"

 
然后可以使用“strcat”连接字符串:
 
  1. (setq b (strcat "CCC_DR" (itoa a)))

 
希望这有帮助!
 
回复

使用道具 举报

145

主题

590

帖子

446

银币

中流砥柱

Rank: 25

铜币
725
发表于 2022-7-6 14:49:00 | 显示全部楼层
谢谢李,
 
太好了。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 14:55:35 | 显示全部楼层
没问题,如果你被卡住了,就大喊一声
回复

使用道具 举报

145

主题

590

帖子

446

银币

中流砥柱

Rank: 25

铜币
725
发表于 2022-7-6 15:14:54 | 显示全部楼层
李,
我确实有点卡住了。我正在尝试将其集成到我的代码中。当我运行这个时,我得到了一个错误:“错误的参数类型:fixnump:nil”。我在开始时将d设置为1500作为默认值,所以我不确定为什么会得到这个值。我认为COND设置正确,因为我根据大小在那里设置了d的值。
 
  1. (defun C:ESS02 () ;define function
  2. (setq dcl_id (load_dialog "ESS.dcl")) ;load dialog
  3. (setq d 1500)
  4. ;(setq b "CCC_SERVICES_EXISTING_Drainage_Storm_Sewer_1500")
  5. (if
  6.    (not (new_dialog "ESS" dcl_id) ;test for dialog
  7.    );not
  8.    (progn
  9.      (alert "Can not find your dcl file")
  10.      (exit) ;exit if no dialog
  11.    )
  12. );if
  13. (set_tile "1500" "1") ;Set radio_button T1 as default
  14. (setq hole "S1")   ;Set variable hole to S1 as default
  15. (action_tile "1500" "(setq hole "S1")") ;*store hole type
  16. (action_tile "1350" "(setq hole "S2")") ;*store hole type
  17. (action_tile "1200" "(setq hole "S3")") ;*store hole type
  18. (action_tile "1050" "(setq hole "S4")") ;*store hole type
  19. (action_tile "900" "(setq hole "S5")") ;*store hole type
  20. (action_tile "750" "(setq hole "S6")") ;*store hole type
  21. (action_tile "675" "(setq hole "S7")") ;*store hole type
  22. (action_tile "600" "(setq hole "S8")") ;*store hole type
  23. (action_tile "525" "(setq hole "S9")") ;*store hole type
  24. (action_tile "450" "(setq hole "S10")") ;*store hole type
  25. (action_tile "375" "(setq hole "S11")") ;*store hole type
  26. (action_tile "300" "(setq hole "S12")") ;*store hole type
  27. (action_tile "225" "(setq hole "S13")") ;*store hole type
  28. (action_tile "150" "(setq hole "S14")") ;*store hole type
  29. (action_tile "cancel" ;if cancel button pressed
  30.   "(done_dialog)(setq userclick nil)" ;close dialog, set flag
  31. );action_tile
  32. (action_tile "accept" ;if O.K. pressed
  33.   "(done_dialog)(setq userclick T))"
  34. );action tile
  35. (start_dialog) ;start dialog
  36. (unload_dialog dcl_id) ;unload
  37. (if userclick                        ;When OK button is selected
  38.    (cond                              ;And one of the following conditions apply
  39.      ((= hole "S1")(setq d 1500))       ;If S1 selected, d = 1500
  40.      ((= hole "S2")(setq d 1350))       ;If S2 selected, d = 1350
  41.      ((= hole "S3")(setq d 1200))       ;If S3 selected, d = 1200
  42.      ((= hole "S4")(setq d 1050))       ;If S4 selected, d = 1050
  43.      ((= hole "S5")(setq d 900))       ;If S4 selected, d = 900
  44.      ((= hole "S6")(setq d 750))       ;If S4 selected, d = 750
  45.      ((= hole "S7")(setq d 675))       ;If S4 selected, d = 675
  46.      ((= hole "S8")(setq d 600))       ;If S4 selected, d = 600
  47.      ((= hole "S9")(setq d 525))       ;If S4 selected, d = 525
  48.      ((= hole "S10")(setq d 450))      ;If S4 selected, d = 450
  49.      ((= hole "S11")(setq d 375))      ;If S4 selected, d = 375
  50.      ((= hole "S12")(setq d 300))      ;If S4 selected, d = 300
  51.      ((= hole "S13")(setq d 225))      ;If S4 selected, d = 225
  52.      ((= hole "S14")(setq d 150))      ;If S4 selected, d = 150
  53.     ;(t (princ "\nNothing changed.")) ;_ end of optional else condition
  54.    )                                  ;End cond
  55. )                                    ;End if
  56. (princ)                              ;Exit quietly
  57. )                                      ;End defun
  58. (princ "\nThis loaded fine")
  59. (setq a (strcat "CCC_DR_" (itoa d)))
  60. (setq b )strcat "CCC_SERVICES_EXISTING_Drainage_Storm_Sewer_" (itoa d)))
  61. (if (= (tblsearch "ltype" a) nil)  
  62.       (command "-linetype" "l" a "acadiso.lin" "")
  63.             (princ))
  64. (graphscr)
  65. (command "._-layer"   "N"   b   "M"   b   "L"   a  b   "C"   "84"   b   "LW"   "0.3"   b    "" )
  66. (command "pline" pause "width" "0.0" "0.0" pause "width" "0.0" "0.0")
  67. (princ)
  68. )
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:23:27 | 显示全部楼层
你的代码有很多错误——你的部分代码在函数定义之外,你的括号不对。
 
我已经重新编写了你的代码并发表了一些评论,这没有经过测试,但请注意我修改它的方式。
 
  1. (defun C:ESS02  (/ dcl_id d hole userclick a b)
  2. ;; Make sure that you localise your variables!
  3. (cond
  4.    ((minusp (setq dcl_id (load_dialog "ESS.dcl")))
  5.     (princ "\n<< DCL File not Found >>"))
  6.    ((not (new_dialog "ESS" dcl_id))
  7.     (princ "\n<< Dialog could not be Loaded >>"))
  8.    (t
  9.      (setq d 1500 hole "S1")
  10.      (set_tile "1500" "1")  ;Set radio_button T1 as default
  11.      (action_tile "1500" "(setq hole "S1")")
  12.      (action_tile "1350" "(setq hole "S2")")
  13.      (action_tile "1200" "(setq hole "S3")")
  14.      (action_tile "1050" "(setq hole "S4")")
  15.      (action_tile "900"  "(setq hole "S5")")
  16.      (action_tile "750"  "(setq hole "S6")")
  17.      (action_tile "675"  "(setq hole "S7")")
  18.      (action_tile "600"  "(setq hole "S8")")
  19.      (action_tile "525"  "(setq hole "S9")")
  20.      (action_tile "450"  "(setq hole "S10")")
  21.      (action_tile "375"  "(setq hole "S11")")
  22.      (action_tile "300"  "(setq hole "S12")")
  23.      (action_tile "225"  "(setq hole "S13")")
  24.      (action_tile "150"  "(setq hole "S14")")
  25.      (action_tile "cancel" "(done_dialog)") ; Userclick will be nil anyway
  26.      (action_tile "accept" "(done_dialog)(setq userclick T))")
  27.     (start_dialog) ;start dialog
  28.     (unload_dialog dcl_id) ;unload
  29.     (if userclick ;When OK button is selected
  30.       (progn
  31.         (setq d
  32.           (cond ;And one of the following conditions apply
  33.             ((= hole "S1") 1500)
  34.             ((= hole "S2") 1350)
  35.             ((= hole "S3") 1200)
  36.             ((= hole "S4") 1050)
  37.             ((= hole "S5")  900)
  38.             ((= hole "S6")  750)
  39.             ((= hole "S7")  675)
  40.             ((= hole "S8")  600)
  41.             ((= hole "S9")  525)
  42.             ((= hole "S10") 450)
  43.             ((= hole "S11") 375)
  44.             ((= hole "S12") 300)
  45.             ((= hole "S13") 225)
  46.             ((= hole "S14") 150)))
  47.         (setq a (strcat "CCC_DR_" (itoa d))
  48.               b (strcat "CCC_SERVICES_EXISTING_Drainage_Storm_Sewer_" (itoa d)))
  49.         (if (not (tblsearch "LTYPE" a))
  50.           (command "_.-linetype" "_l" a "acadiso.lin" ""))
  51.         (command "._-layer"   "_N"   b   "_M"   b   "_L"   a  b   "_C"   "84"   b   "_LW"   "0.3"   b    "" )
  52.         (command "pline" pause "width" "0.0" "0.0" pause "width" "0.0" "0.0")))))
  53. (princ))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-5 03:20 , Processed in 1.924373 second(s), 64 queries .

© 2020-2025 乐筑天下

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