mwade93 Posted November 21, 2016 Posted November 21, 2016 (edited) I have a plot setup to plot all the layout tabs in a drawing. I have provided the users the options to select the paper size, plot style, and orientation. These are stored as user variables (PDFPS, PST, and PLO). I have the setup working great, but I am trying to set it up where if the user hasn't selected one of the variables, the command will be cancelled. I have tried an if statement, but I wanted to evaluate all three variables at once. I'm thinking it should be doable, just have been able to figure it out. Any help is appreciated. The code below is the code that plots all the layouts and places them in the PDF folder for each project. ^C^C^C(foreach LL (layoutlist)(setvar "ctab" LL)(command (setq DL (substr (getvar "dwgprefix") 1 (- (strlen (getvar "dwgprefix")) 13))) (setq DN (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4))) (strcat DL DN);(setq FS (strcat DL "52 PDFs" (chr 92) DN "-" (getvar "CTAB") ".pdf")) "plot" "yes" "" "AutoCAD PDF (General Documentation)" PDFPS "Inches" PLO "No" "Extents" "1:1" "Center" "Yes" PST "Yes" "No" "No" "No" FS "Yes" "Yes" "Yes"));(alert "If all settings were selected, PDFs have been made of all layout sheets and saved in the PDFs folder for this project. They were saved as Project Name-Layout Name"); For reference, I have a code that evaluates each variable and displays a message. (if (= nil PDFPS) (alert "No paper size was selected. Please cancel command and select paper size.") (strcat PDFPS)) Edited November 21, 2016 by mwade93 Quote
Grrr Posted November 21, 2016 Posted November 21, 2016 This is your code, indented: ^C^C^C (foreach LL (layoutlist) (setvar "ctab" LL) (command (setq DL (substr (getvar "dwgprefix") 1 (- (strlen (getvar "dwgprefix")) 13))) (setq DN (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4))) (strcat DL DN); (setq FS (strcat DL "52 PDFs" (chr 92) DN "-" (getvar "CTAB") ".pdf")) "plot" "yes" "" "AutoCAD PDF (General Documentation)" PDFPS "Inches" PLO "No" "Extents" "1:1" "Center" "Yes" PST "Yes" "No" "No" "No" FS "Yes" "Yes" "Yes" ) ) (alert "If all settings were selected, PDFs have been made of all layout sheets and saved in the PDFs folder for this project. They were saved as Project Name-Layout Name" ) Example for a proper structure would be something like this (corrections in red color): [color="red"](defun C:PlotMyLayouts ( / DL DN FS PDFPS PLO PST ) [color="darkgreen"]; Localise your variables (everything that is used with [i]setq [/i]function)[/color] (if (and (setq DL ...) (setq DN ...) (setq FS ...) (setq PDFPS ...) (setq PLO ...) (setq PST ...) ) (progn[/color] (foreach LL (layoutlist) (setvar "ctab" LL) (command [color="red"]DL[/color] [color="red"]DN[/color] (strcat DL DN); [color="red"]FS[/color] "plot" "yes" "" "AutoCAD PDF (General Documentation)" PDFPS "Inches" PLO "No" "Extents" "1:1" "Center" "Yes" PST "Yes" "No" "No" "No" FS "Yes" "Yes" "Yes" ); command ); foreach (alert "If all settings were selected, PDFs have been made of all layout sheets and saved in the PDFs folder for this project. They were saved as Project Name-Layout Name" ) [color="red"] ); progn ); if (princ) ); defun[/color] And btw note that you could use: (setq DN (cadr (fnsplitl (getvar 'dwgname)))) Quote
mwade93 Posted November 21, 2016 Author Posted November 21, 2016 Thank you for the reply. I am trying to do everything on the command line without the use of an external LSP file. The variables that I am evaluating are entered using buttons that I have created to set the variables separately. Then the user can create the setup using the buttons. What does the second code do? Quote
Grrr Posted November 21, 2016 Posted November 21, 2016 What does the second code do? It does... nothing. Actually thats an example how to input / fill all the variables before the command call is evaluated, in short: the code checks if everything you've entered is OK and then proceeds with the plotting, otherwise you simply crash the command ( and the code exits with error ). Even simplier example: (if (and (setq pdfSaveDirectory ...) (setq pdfName ...) (setq PaperSize ...) ) (command "_.PLOT" ... ) ) Quote
mwade93 Posted November 21, 2016 Author Posted November 21, 2016 (edited) (if (and (setq pdfSaveDirectory ...) (setq pdfName ...) (setq PaperSize ...) ) (command "_.PLOT" ... ) ) I don't want to set the variables with this code though, I am just looking to verify that they do not have a value of nil. The setq here means that they will be set to what I enter in the code? The code crashing is exactly what I am looking for it to do though. Here is the image of the setup: Edited November 21, 2016 by mwade93 Quote
Grrr Posted November 21, 2016 Posted November 21, 2016 I don't want to set the variables with this code though, I am just looking to verify that they do not have a value of nil. The setq here means that they will be set to what I enter in the code? The code crashing is exactly what I am looking for it to do though. Whats the reason not to set the variables as long as they are localised? However try this (I don't know how to set it to a macro): (if (and PDFPS PLO PST) (progn (foreach LL (layoutlist) (setvar "ctab" LL) (command (setq DL (substr (getvar "dwgprefix") 1 (- (strlen (getvar "dwgprefix")) 13))) (setq DN (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4))) (strcat DL DN); (setq FS (strcat DL "52 PDFs" (chr 92) DN "-" (getvar "CTAB") ".pdf")) "plot" "yes" "" "AutoCAD PDF (General Documentation)" PDFPS "Inches" PLO "No" "Extents" "1:1" "Center" "Yes" PST "Yes" "No" "No" "No" FS "Yes" "Yes" "Yes" ) ) (alert "If all settings were selected, PDFs have been made of all layout sheets and saved in the PDFs folder for this project. They were saved as Project Name-Layout Name" ) ) (cond ((not PDFPS) (alert "\n\"PDFPS\" was nil!")) ((not PLO) (alert "\n\"PLO\" was nil!")) ((not PST) (alert "\n\"PST\" was nil!")) ) ) And BTW the images you've uploaded are not loading. Quote
BIGAL Posted November 22, 2016 Posted November 22, 2016 A couple of suggestions If you running this a a macro then make it ^c^c^c(load "plotroutine") so it loads a lisp. Have a look at a prefilled dialouge you can put the current value into the boxes and check for any that have not been filled in and ask the question continue or exit completey, the continue will open the dialouge again the exit is just that use (exit) it will end the lisp. Re dialouge you can have say 3 lists so the user can choose the correct option. Me I just have multiple options in a menu so users picks what they want. Quote
mwade93 Posted November 22, 2016 Author Posted November 22, 2016 (edited) Whats the reason not to set the variables as long as they are localised?And BTW the images you've uploaded are not loading. The reason for that is that way I have everything set up. I have a panel on the ribbon to select paper size, plot styles, and orientations. They set the variables that I use in this code. It just makes it easier to use in my opinion. I will try the code that you posted out. EDIT: This works perfectly, thank you very much for your help! Here is the code I ended up using: ^C^C^C(if (and PDFPS PLO PST) (progn (foreach LL (layoutlist) (setvar "ctab" LL) (command (setq DL (substr (getvar "dwgprefix") 1 (- (strlen (getvar "dwgprefix")) 13))) (setq DN (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4))) (strcat DL DN); (setq FS (strcat DL "52 PDFs" (chr 92) DN "-" (getvar "CTAB") ".pdf")) "plot" "yes" "" "DWG to PDF" PDFPS "Inches" PLO "No" "Extents" "1:1" "Center" "Yes" PST "Yes" "No" "No" "No" FS "Yes" "Yes" "Yes")) (alert "PDFs have been made of all layout sheets and saved in the PDFs folder for this project. They were saved as Project Name-Layout Name")) (cond ((not PDFPS) (alert "No paper size was selected. Please select paper size and restart command.")) ((not PLO) (alert "No orientation was selected. Please select orientation and restart command.")) ((not PST) (alert "No plot style was selected. Please select plot style and restart command.")))); Edited November 22, 2016 by mwade93 Quote
BIGAL Posted November 23, 2016 Posted November 23, 2016 Again I suggest your code is ^c^c^c(load "a lisp file to be run") Another suggestion http://www.lee-mac.com/listbox.html this is a great little program for allowing selection form dialouge lists, you could add it easy to your existing routine asking for input for PDFPS PLO PST. This way only 1 program. Quote
Recommended Posts
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.