Jump to content

Quick change between layout sheets


Cannibal Smurf

Recommended Posts

Hi, I'm working on a drawing that has 75 layout sheets (all numbered)and I want to create a button that, when clicked, requires input from the user (ie. sheet number) then changes to that sheet.

 

Thanks in advance

Link to comment
Share on other sites

Quick one:

 

(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))

 

Case-sensitive

Link to comment
Share on other sites

I believe this is not case-sensitive:

 

(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))

Link to comment
Share on other sites

Here is another way:

 

(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)
)

Link to comment
Share on other sites

Sweet, all work very well. Thinking I'll go with rjp's routine as no typing req'd, just select from dropdown.

I'm curious as to how they work, trying to break the last 2 down in my head and understand them line by line. edit: not having much luck with that, any suggestions on how to learn lisp?

Thank you both very much for your help.

Link to comment
Share on other sites

Cheers Lee,

 

I was going to PM you, but no PM?? Your code is shorter so may be a better place to start if could break it down for me.

Line 1 defun (define function) c:(command?) lsw (command trigger) (/ lay lst) (?)

Line 2 (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 ")) error message, not sure how it is induced though.

(princ))

Link to comment
Share on other sites

ronjonp, can i request a breakdown of your code too? Was going to ask you to email it, but it might be better in the forum so that others can also learn from it.

Your routine is great ronjonp, 1 thing I have thought of is adding a Print button so it automatially opens the print dialog after changing layouts, can you help me out with that too?

Im guessing it would start something like;

: row {

: button {

label = \"&Print\";

???????????????????

Link to comment
Share on other sites

Ok, here is a breakdown of my code. Ron's is a bit more complicated in that he creates a temporary DCL file with a filename generated by vl-filename-mktemp, then uses this DCL file as the user interface.

 

But hopefully this will help:

 

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

Link to comment
Share on other sites

ronjonp, can i request a breakdown of your code too? Was going to ask you to email it, but it might be better in the forum so that others can also learn from it.

Your routine is great ronjonp, 1 thing I have thought of is adding a Print button so it automatially opens the print dialog after changing layouts, can you help me out with that too?

Im guessing it would start something like;

: row {

: button {

label = \"&Print\";

???????????????????

 

Let me know what areas of the lisp confuse you and I'll try to explain. As far as the plot option....it can be added but using (command "plot") (at least on my computer) is only showing the plot options on the command line. Have you used PUBLISH before?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...