woodman78 发表于 2022-7-6 14:15:51

变量

你好
我想设置一些变量,将文本与变量部分结合起来,生成一个新变量。
 
前任:

(setq a 1500)
(setq b "CCC_DR" + a)
(setq c "CCC_Services" + a)

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

Lee Mac 发表于 2022-7-6 14:37:30

变量只能是一种类型,即字符串、整数、实数、列表等。
 
您可以使用“type”函数测试此类型(显然…)。。
 
因此,如果变量“a”是整数,则在将其与组合之前,需要将其转换为字符串
 
"CCC_DR"
 
然后可以使用“strcat”连接字符串:
 

(setq b (strcat "CCC_DR" (itoa a)))

 
希望这有帮助!
 

woodman78 发表于 2022-7-6 14:49:00

谢谢李,
 
太好了。

Lee Mac 发表于 2022-7-6 14:55:35

没问题,如果你被卡住了,就大喊一声

woodman78 发表于 2022-7-6 15:14:54

李,
我确实有点卡住了。我正在尝试将其集成到我的代码中。当我运行这个时,我得到了一个错误:“错误的参数类型:fixnump:nil”。我在开始时将d设置为1500作为默认值,所以我不确定为什么会得到这个值。我认为COND设置正确,因为我根据大小在那里设置了d的值。
 

(defun C:ESS02 () ;define function
(setq dcl_id (load_dialog "ESS.dcl")) ;load dialog
(setq d 1500)
;(setq b "CCC_SERVICES_EXISTING_Drainage_Storm_Sewer_1500")
(if
   (not (new_dialog "ESS" dcl_id) ;test for dialog
   );not
   (progn
   (alert "Can not find your dcl file")
   (exit) ;exit if no dialog
   )
);if
(set_tile "1500" "1") ;Set radio_button T1 as default
(setq hole "S1")   ;Set variable hole to S1 as default
(action_tile "1500" "(setq hole \"S1\")") ;*store hole type
(action_tile "1350" "(setq hole \"S2\")") ;*store hole type
(action_tile "1200" "(setq hole \"S3\")") ;*store hole type
(action_tile "1050" "(setq hole \"S4\")") ;*store hole type
(action_tile "900" "(setq hole \"S5\")") ;*store hole type
(action_tile "750" "(setq hole \"S6\")") ;*store hole type
(action_tile "675" "(setq hole \"S7\")") ;*store hole type
(action_tile "600" "(setq hole \"S8\")") ;*store hole type
(action_tile "525" "(setq hole \"S9\")") ;*store hole type
(action_tile "450" "(setq hole \"S10\")") ;*store hole type
(action_tile "375" "(setq hole \"S11\")") ;*store hole type
(action_tile "300" "(setq hole \"S12\")") ;*store hole type
(action_tile "225" "(setq hole \"S13\")") ;*store hole type
(action_tile "150" "(setq hole \"S14\")") ;*store hole type
(action_tile "cancel" ;if cancel button pressed
"(done_dialog)(setq userclick nil)" ;close dialog, set flag
);action_tile
(action_tile "accept" ;if O.K. pressed
"(done_dialog)(setq userclick T))"
);action tile
(start_dialog) ;start dialog
(unload_dialog dcl_id) ;unload
(if userclick                        ;When OK button is selected
   (cond                              ;And one of the following conditions apply
   ((= hole "S1")(setq d 1500))       ;If S1 selected, d = 1500
   ((= hole "S2")(setq d 1350))       ;If S2 selected, d = 1350
   ((= hole "S3")(setq d 1200))       ;If S3 selected, d = 1200
   ((= hole "S4")(setq d 1050))       ;If S4 selected, d = 1050
   ((= hole "S5")(setq d 900))       ;If S4 selected, d = 900
   ((= hole "S6")(setq d 750))       ;If S4 selected, d = 750
   ((= hole "S7")(setq d 675))       ;If S4 selected, d = 675
   ((= hole "S8")(setq d 600))       ;If S4 selected, d = 600
   ((= hole "S9")(setq d 525))       ;If S4 selected, d = 525
   ((= hole "S10")(setq d 450))      ;If S4 selected, d = 450
   ((= hole "S11")(setq d 375))      ;If S4 selected, d = 375
   ((= hole "S12")(setq d 300))      ;If S4 selected, d = 300
   ((= hole "S13")(setq d 225))      ;If S4 selected, d = 225
   ((= hole "S14")(setq d 150))      ;If S4 selected, d = 150
    ;(t (princ "\nNothing changed.")) ;_ end of optional else condition
   )                                  ;End cond
)                                    ;End if
(princ)                              ;Exit quietly
)                                    ;End defun
(princ "\nThis loaded fine")
(setq a (strcat "CCC_DR_" (itoa d)))
(setq b )strcat "CCC_SERVICES_EXISTING_Drainage_Storm_Sewer_" (itoa d)))
(if (= (tblsearch "ltype" a) nil)
      (command "-linetype" "l" a "acadiso.lin" "")
            (princ))
(graphscr)
(command "._-layer"   "N"   b   "M"   b   "L"   ab   "C"   "84"   b   "LW"   "0.3"   b    "" )
(command "pline" pause "width" "0.0" "0.0" pause "width" "0.0" "0.0")
(princ)
)

Lee Mac 发表于 2022-7-6 15:23:27

你的代码有很多错误——你的部分代码在函数定义之外,你的括号不对。
 
我已经重新编写了你的代码并发表了一些评论,这没有经过测试,但请注意我修改它的方式。
 

(defun C:ESS02(/ dcl_id d hole userclick a b)
;; Make sure that you localise your variables!

(cond
   ((minusp (setq dcl_id (load_dialog "ESS.dcl")))
    (princ "\n<< DCL File not Found >>"))
   ((not (new_dialog "ESS" dcl_id))
    (princ "\n<< Dialog could not be Loaded >>"))
   (t
   (setq d 1500 hole "S1")
   (set_tile "1500" "1");Set radio_button T1 as default
   (action_tile "1500" "(setq hole \"S1\")")
   (action_tile "1350" "(setq hole \"S2\")")
   (action_tile "1200" "(setq hole \"S3\")")
   (action_tile "1050" "(setq hole \"S4\")")
   (action_tile "900""(setq hole \"S5\")")
   (action_tile "750""(setq hole \"S6\")")
   (action_tile "675""(setq hole \"S7\")")
   (action_tile "600""(setq hole \"S8\")")
   (action_tile "525""(setq hole \"S9\")")
   (action_tile "450""(setq hole \"S10\")")
   (action_tile "375""(setq hole \"S11\")")
   (action_tile "300""(setq hole \"S12\")")
   (action_tile "225""(setq hole \"S13\")")
   (action_tile "150""(setq hole \"S14\")")
   (action_tile "cancel" "(done_dialog)") ; Userclick will be nil anyway
   (action_tile "accept" "(done_dialog)(setq userclick T))")

    (start_dialog) ;start dialog
    (unload_dialog dcl_id) ;unload

    (if userclick ;When OK button is selected
      (progn
      (setq d
          (cond ;And one of the following conditions apply
            ((= hole "S1") 1500)
            ((= hole "S2") 1350)
            ((= hole "S3") 1200)
            ((= hole "S4") 1050)
            ((= hole "S5")900)
            ((= hole "S6")750)
            ((= hole "S7")675)
            ((= hole "S8")600)
            ((= hole "S9")525)
            ((= hole "S10") 450)
            ((= hole "S11") 375)
            ((= hole "S12") 300)
            ((= hole "S13") 225)
            ((= hole "S14") 150)))

      (setq a (strcat "CCC_DR_" (itoa d))
            b (strcat "CCC_SERVICES_EXISTING_Drainage_Storm_Sewer_" (itoa d)))
      (if (not (tblsearch "LTYPE" a))
          (command "_.-linetype" "_l" a "acadiso.lin" ""))
      (command "._-layer"   "_N"   b   "_M"   b   "_L"   ab   "_C"   "84"   b   "_LW"   "0.3"   b    "" )
      (command "pline" pause "width" "0.0" "0.0" pause "width" "0.0" "0.0")))))
(princ))
页: [1]
查看完整版本: 变量