Cannibal Smurf 发表于 2022-7-6 14:43:29

布局之间的快速切换

您好,我正在绘制一个有75张布局图纸(全部编号)的图形,我想创建一个按钮,单击该按钮时,需要用户输入(即图纸编号),然后更改为该图纸。
 
提前感谢

Lee Mac 发表于 2022-7-6 14:53:22

快速一:
 

(defun c:lsw (/ lay)
(if (and (not (eq "" (setq lay (getstring t "\nSpecify Layout Name: "))))
          (member lay (layoutlist)))
   (setvar "CTAB" lay)
   (princ "\n<!> Layout not Found <!>"))
(princ))

 
区分大小写

Lee Mac 发表于 2022-7-6 15:01:26

我认为这不区分大小写:
 

(defun c:lsw (/ lay lst)
(vl-load-com)
(if (and (not (eq "" (setq lay (strcase (getstring t "\nSpecify Layout Name: ")))))
          (member lay (setq lst (mapcar 'strcase (layoutlist)))))
   (setvar "CTAB" (nth (vl-position lay lst) (layoutlist)))
   (princ "\n<!> Layout not Found <!>"))
(princ))

ronjonp 发表于 2022-7-6 15:02:30

还有一种方法:
 
(defun c:tabchange (/ $value choice dir file fn fno id laylst sel w)
(if (and (setq laylst (vl-sort (layoutlist) '<))
          (setq w (itoa (apply 'max (mapcar 'strlen laylst))))
          (setq fn (vl-filename-mktemp nil nil ".dcl"))
          (setq fno (open fn "w"))
   )
   (progn
   (write-line
       (strcat
         "batch : dialog { label = \"RJP-TabChanger\";
            :column {
         :boxed_column {
         label = \"< Select Tab >\";
         : list_box {
             key = \"laylist\";
             height = 30;
             width = "
         w
         ";
             multiple_select = false;
             }
          }
          }
         : row {
         : button {
             label = \"&Select...\";
             key = \"select\";
             }
         : button {
             label = \"&Cancel\";
             is_cancel = true;
             key = \"cancel\";
             }
            
         }
          }"
       )
       fno
   )
   (close fno)
   (setq id (load_dialog fn))
   (if (not (new_dialog "batch" id))
       (exit)
   )
   (start_list "laylist")
   (mapcar 'add_list laylst)
   (end_list)
   (action_tile "laylist" "(setq choice $value)")
   (action_tile "select" "(done_dialog)")
   (action_tile "cancel" "(setq choice nil)(done_dialog)(vl-file-delete fn)")
   (start_dialog)
   (unload_dialog id)
   (if (and choice (setq sel (nth (atoi choice) laylst)))
       (setvar 'ctab sel)
   )
   )
)
(princ)
)

Cannibal Smurf 发表于 2022-7-6 15:10:19

亲爱的,一切都很好。我认为我将使用rjp的例程,因为不需要输入,只需从下拉列表中选择。
我很好奇它们是如何工作的,试图在脑海中把最后两个分解开来,逐行理解它们。编辑:在这方面运气不太好,对如何学习lisp有什么建议吗?
非常感谢你们的帮助。

Lee Mac 发表于 2022-7-6 15:15:53

很高兴他们能满足你的要求
 
如果您对代码的工作方式有任何疑问,请提问
 

Cannibal Smurf 发表于 2022-7-6 15:24:52

干杯,李,
 
我本来打算下午你,但没有下午??你的代码比较短,所以如果你能帮我把它分解一下,也许是一个更好的开始。
第1行defun(定义函数)c:(命令?)lsw(命令触发器)(/lay lst)(?)
2号线(vl负载com)(?)
(if(and(not)(eq“”(setq lay(strcase(getstring t“\n指定布局名称:”))))
(成员层(setq lst(mapcar's strcase(layoutlist 107;)а)а)
(setvar“CTAB”(第n个(vl位置lay lst)(布局列表)))
(princ“\n Layout not Found”))错误消息,但不确定它是如何产生的。
(普林斯)

Cannibal Smurf 发表于 2022-7-6 15:30:56

罗恩·琼普,我能要求你也把代码分解一下吗?我想请你发邮件,但在论坛上可能会更好,这样其他人也可以从中学习。
你的程序很棒,ronjonp,我想到的一件事是添加一个打印按钮,这样它在更改布局后会自动打开打印对话框,你能帮我解决这个问题吗?
我猜它会像这样开始;
:行{
:按钮{
标签=\“&打印\”;
???????????????????

Lee Mac 发表于 2022-7-6 15:35:15

好的,这是我的代码分解。Ron的有点复杂,因为他创建了一个临时DCL文件,文件名由vl filename mktemp生成,然后将此DCL文件用作用户界面。
 
但希望这能有所帮助:
 

(defun ; Define the function
      c:; Defined function is invoked through Command line
      lsw ; Function Syntax (that will invoke the function)
(/ lay lst) ; Arguments and Localised Variables
(vl-load-com) ; Load the Visual LISP functions
(if ; If the following is true...
   (and ; Both these Conditions must be met in order to continue
   (not ; As it says on the tin
       (eq ; Returns T if the two expressions are identical
         ""; An empty String
         (setq lay ; Setting the following to a Variable "lay"
                (strcase; Capitalise the Following
                  (getstring t "\nSpecify Layout Name: ") ; Retrieve a String from the User
                  ) ; end strcase
               ) ; end setq
         ) ; end eq
       ) ; end not
          (member lay ; If lay is a member of the following
                  (setq lst ; Set the following to a variable "lst"
                         (mapcar 'strcase ; Applies the function "strcase" to every member of the following
                                 (layoutlist); Retrieves a List of Layouts
                                 ) ; end mapcar
                        ) ; end setq
                  ) ; setq member
   ) ; end and
   ; Upon the IF statement returning true:
   (setvar "CTAB" ; Set the ACAD variable "CTAB" to the following
         (nth ; Retrieve the member in the nth position of the list provided
             (vl-position lay lst) ; Find the position of the variable "lay" in the list "lst"
             (layoutlist) ; Retrieve the List of Layouts (this time not Capitalised).
             ) ; end nth
         ) ; ent setvar
   ; Upon the IF statement returning false:
   (princ "\n<!> Layout not Found <!>") ; Print this Message to the Command line
   ) ; end IF
(princ) ; Exit Cleanly
) ; End Defun

ronjonp 发表于 2022-7-6 15:43:23

 
让我知道Lisp程序的哪些方面让你困惑,我会尽力解释。至于绘图选项。。。。可以添加,但使用(命令“绘图”)(至少在我的计算机上)仅在命令行上显示绘图选项。你以前用过PUBLISH吗?
页: [1] 2
查看完整版本: 布局之间的快速切换