Earlzii Posted September 30, 2016 Share Posted September 30, 2016 Hi, I have created a lisp routine that plots PDF's and saves them into a certain folder depending on the client. As an extension of this I wanted to create a folder for each job that is worked on for that client which is pulled from a block. I have managed to create a folder using this information but then there are 2 different types of PDF that will be required and I wanted to split these up again into 2 different folders. The part that I am having trouble with is creating these 2 subfolders. The folder structure should be "C:\\Users\\" UName "\\Documents\\PDF's\\Client A\\" JobName then in this folder there will be another 2 folders one called Issue and the other called Check Print. I have tried to create these 2 sub-folders but with no luck but the program runs fine without any errors. I am guessing because at the time of the plot the lisp creates the folder with the JobName it can't then verify that it exists to then create the subfolders within the JobName folder. I am probably wrong but after some searching the only help I can find online is to just create one folder or something that asks for a users input. The idea behind the lisp is to ask the user some minimal questions as to sheet size and colour or mono plot etc and automate the rest so i don't really want to go down the route of adding another dialog box for the user to input where to save the PDF because this will just defeat the point. (defun ClientProjectFolder ( / UName SJobDesc1 SJobDesc2 SJobDesc3 SPN ClientProjectFolderName ClientProjectFolderNameCP ClientProjectFolderNameIssue) (setq UName (getenv "UserName")) (setq SJobDesc1 (showattvalue "PW_TITLE" "JOB_DESC")) (setq SJobDesc2 (showattvalue "PW_TITLE" "JOB_DESC2")) (setq SJobDesc3 (showattvalue "PW_TITLE" "JOB_DESC3")) (setq SPN (strcat SJobDesc1 " " SJobDesc2 " " SJobDesc3)) (setq ClientProjectFolderName (strcat "C:\\Users\\" UName "\\Documents\\PDF's\\ClientA\\" SPN)) (vl-mkdir ClientProjectFolderName) T (setq ClientProjectFolderNameCP (strcat "C:\\Users\\" UName "\\Documents\\PDF's\\ClientA\\" SPN "\\Check Print\\")) (vl-mkdir ClientProjectFolderNameCP) T (setq ClientProjectFolderNameIssue (strcat "C:\\Users\\" UName "\\Documents\\PDF's\\ClientA\\" SPN "\\Issue\\")) (vl-mkdir ClientProjectFolderNameIssue) T ) Forgive me if some of the variables I have created don't match I have just quickly changed the names as they were client names. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 30, 2016 Share Posted September 30, 2016 This function should perform as you require: Create Directory Quote Link to comment Share on other sites More sharing options...
Earlzii Posted September 30, 2016 Author Share Posted September 30, 2016 Hi Lee, I have tried this a few different ways and can't get it to work. Will it not take user defined variables within the call i.e. (LM:createdirectory "C:\\Users\\" UName "\\Documents\\PDF's\\ClientA\\" SPN "\\Check Print") I need to be able to create the directory in the users documents which is not a constant as well as the project name which will always be different. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 30, 2016 Share Posted September 30, 2016 You need to read about strcat function Quote Link to comment Share on other sites More sharing options...
Earlzii Posted September 30, 2016 Author Share Posted September 30, 2016 I used strcat and it didn't work but I have figured out the issue. The drawing that I was testing it on the attributes "JOB_DESC2" and "JOB_DESC3" are blank which is causing the creation of anything past the SPN variable to stop. These attributes are not always filled in, they are completely blank in the example I tested on is there a way to get it to work if these variables are blank because I don't really want to ignore them as it is 50/50 whether they have any information in them or not. Quote Link to comment Share on other sites More sharing options...
Earlzii Posted September 30, 2016 Author Share Posted September 30, 2016 OK so it appears that because the attributes are blank and I am using " " to space out the attributes this is causing the problem. Is there an alternative to using " " but that will still put a space in between the attributes. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted October 1, 2016 Share Posted October 1, 2016 Check for blanks and use something else like - or _ Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted October 1, 2016 Share Posted October 1, 2016 Not sure what the OP means by 'blanks'. But most likely the missing (showattvalue) function can return nil. (setq SPN (vl-string-trim " " (strcat (if SJobDesc1 SJobDesc1 "") ; Assumption: SJobDesc1 is either nil or a string. " " (if SJobDesc2 SJobDesc2 "") " " (if SJobDesc3 SJobDesc3 "") ) ) ) (if (/= "" SPN) (setq SPN (strcat SPN "\\")) ) ... (strcat "C:\\Users\\" UName "\\Documents\\PDF's\\ClientA\\" SPN "Check Print\\") ... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 1, 2016 Share Posted October 1, 2016 I would suggest perhaps: (setq SPN (substr (strcat (if (member SJobDesc1 '(nil "")) "" (strcat " " SJobDesc1)) (if (member SJobDesc2 '(nil "")) "" (strcat " " SJobDesc2)) (if (member SJobDesc3 '(nil "")) "" (strcat " " SJobDesc3)) ) 2 ) ) In order to avoid a possible double-space. Quote Link to comment Share on other sites More sharing options...
Earlzii Posted October 5, 2016 Author Share Posted October 5, 2016 Guys, I've just got round to trying out your suggestions and it works perfectly now. Thanks for all your help!!! Quote Link to comment Share on other sites More sharing options...
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.