OMEGA-ThundeR Posted May 2, 2014 Posted May 2, 2014 Hi, We store our projects by discipline , we have a main code for every discipline . 55.1234 - where 55 is the discipline and 1234 the increasing project number per project. I've written a list where i can go enter a command and the windows file explorer opens to a certain discipline . C1 goes to the main 51.xxx folder and C7 goes to the main 57.xxx folder. I would like to make a lisp where i can enter the project number and go straight to that project folder. Is that possible? I'm no expert in LISP, the most stuff i do is simple like; (defun c:c5 () (startapp "explorer" (strcat "/n,/e," "g:\\c5")) (princ) ) (Defun C:excel () (startapp "C:\\Program Files (x86)\\Microsoft Office\\Office12\\EXCEL.EXE") (princ) ) The projectnumber of the folder starts the same always. 55.12.34 - Name of project I would like to be able to perform a command like 'openfolder' and enter a projectcode '551234' and then it opens that folder in the windows explorer, something like the 'C5' command in the above lisp. I have no idea how to start at that, at least not in LISP ways. Since the projectfolder always starts in the same way i would think it wouldn't be that hard, but how to open a folder like 'open 55.12.34*' would not be so simple. Any ideas how to do this? If it is even possible? Quote
MSasu Posted May 2, 2014 Posted May 2, 2014 You may adjust the example below for your case; it expects a 6 digits number as project ID, inputted without dots. ;;; Open Project Folder (02-V-2014) (defun c:OPF( / pathProjects noProject nameProject ) (setq pathProjects [color=magenta][color=black]"[/color]C:\\MyProjects\\[/color][color=black]"[/color]) (if (setq noProject (getstring "\nNumber of project: ")) (if (or (/= (strlen noProject) 6) (wcmatch noProject "*`.*")) (alert "Wrong project number!") (if (vl-some '(lambda(x) (wcmatch (setq nameProject x) (strcat (substr noProject 1 2) "." (substr noProject 3 2) "." (substr noProject 5 2) "*"))) (vl-directory-files pathProjects nil -1)) (startapp "EXPLORER" (strcat pathProjects nameProject)) (alert "Project not available!") ) ) ) (princ) ) Quote
OMEGA-ThundeR Posted May 2, 2014 Author Posted May 2, 2014 (edited) Wow, nice.. it does right what i want it to do . Seeing the code it's easy to understand.. however it needs another function in my case. There needs to be a check on the first 2 numbers. If the code starts with 51,52,53,54,55,56 or 57 the 'pathProjects' needs to be changed to a specific discipline. Free translated it needs to be something like : IF First2Numbers equals; 51 then Discipline = 'C1\\' 52 then Discipline = 'C2\\' 53 then Discipline = 'C3\\' 54 then Discipline = 'C4\\' 55 then Discipline = 'C5\\' 56 then Discipline = 'C6\\' 57 then Discipline = 'C7\\' With in the end would make the executable something like: (startapp "EXPLORER" (strcat pathProjects Discipline nameProject)) I ask; How? Edit: Argh!!! :@ We are working with 2 people on this code for hours (no knowledge, just some other coding languages).. We are stuck at the (if (vl-some '(lambda(x) (wcmatch (setq nameProject x) (strcat (substr noProject 1 2) "." (substr noProject 3 2) "." (substr noProject 5 2) "*"))) (vl-directory-files pathProjects nil -1)) (startapp "EXPLORER" (strcat pathProjects nameProject)) (alert "Project not available!") part of the code (i copied from second post, naming is different in my code, and checked). What i got is this: (defun c:project ( / Beginpunt ProNummer DisCheck Discipline nameProject ) (setq Beginpunt "G:\\") (setq ProNummer (getstring "\nWat is het projectnummer: ")) (setq DisCheck (substr ProNummer 1 2)) (prompt DisCheck) ;Debug (cond ((= DisCheck "51") (setq Discipline "C1\\")) ((= DisCheck "52") (setq Discipline "C2\\")) ((= DisCheck "53") (setq Discipline "C3\\")) ((= DisCheck "54") (setq Discipline "C4\\")) ((= DisCheck "55") (setq Discipline "C5\\")) ((= DisCheck "56") (setq Discipline "C6\\")) ((= DisCheck "57") (setq Discipline "C7\\")) ) ;Doe een IF ELSE statement (prompt Discipline) ;Debug (prompt (strcat Beginpunt Discipline)) ;Debug - Insert code here - (prompt nameProject) ;Debug (startapp "EXPLORER" (strcat Beginpunt Discipline)) (princ) ) It goes wrong on the part where the dots are added in the projectnumber. How do i get it there without some syntax error? Edited May 2, 2014 by OMEGA-ThundeR Quote
Snownut Posted May 2, 2014 Posted May 2, 2014 MSasu, wasted his time giving you what your where looking for, then you go and move the goal posts. Due to your lack of being entirely upfront about what you where looking for, in the future you need to be completely upfront with just what it is you need. Quote
OMEGA-ThundeR Posted May 3, 2014 Author Posted May 3, 2014 I'm sorry then that i failed to mention our folder structure. It's like this X:\Discipline\12.34.56 - Projectname And in real it's something like : G:\C2\52.43.33 - Projectname G:\C3\53.44.53 - Projectname G:\C3\53.44.32 - Projectname G:\C7\57.45.44 - Projectname To check in which folder i need to be i think i need to use something like this: (defun c:project ( / Root ProNumber DisCheck Discipline nameProject ) (setq Root "G:\\") (setq ProNumber (getstring "\nProjectnumber? ")) (setq DisCheck (substr ProNumber 1 2)) ; Read the first 2 digits from $ProNumber (cond ((= DisCheck "51") (setq Discipline "C1\\")) ((= DisCheck "52") (setq Discipline "C2\\")) ((= DisCheck "53") (setq Discipline "C3\\")) ((= DisCheck "54") (setq Discipline "C4\\")) ((= DisCheck "55") (setq Discipline "C5\\")) ((= DisCheck "56") (setq Discipline "C6\\")) ((= DisCheck "57") (setq Discipline "C7\\")) ) ;Set $Discipline for right folder to open ( i know it has no fail check, yet) (setq nameProject (strcat (substr ProNumber 1 2) "." (substr ProNumber 3 2) "." (substr ProNumber 5 2) "*")) (startapp "EXPLORER" (strcat Root Discipline nameProject)) (prompt (strcat Root Discipline nameProject)) (princ) ) This would prompt (when entered '551234') - G:\G5\55.12.34* - and it would open the explorer on the 'my documents' (standard) folder instead of the project folder. I guess that has something to do with the Visual Lisp style code, but if i try to edit the original code supplied by MSasu i only get errors or prompts the 'last' foldername in the root directory. Any tips on how to get it working that it does open the project folder? On the bright sight.. i learned a lot from this, i wasn't able to perfom IF statements or set Variables before this question. I can use that knowledge in the future Quote
marko_ribar Posted May 4, 2014 Posted May 4, 2014 (defun c:project ( / Root ProNumber DisCheck Discipline nameProject fn f ) (setq Root "G:\\") (setq ProNumber (getstring "\nProjectnumber? ")) (setq DisCheck (substr ProNumber 1 2)) ; Read the first 2 digits from $ProNumber (cond ((= DisCheck "51") (setq Discipline "C1\\")) ((= DisCheck "52") (setq Discipline "C2\\")) ((= DisCheck "53") (setq Discipline "C3\\")) ((= DisCheck "54") (setq Discipline "C4\\")) ((= DisCheck "55") (setq Discipline "C5\\")) ((= DisCheck "56") (setq Discipline "C6\\")) ((= DisCheck "57") (setq Discipline "C7\\")) ) ;Set $Discipline for right folder to open ( i know it has no fail check, yet) (setq nameProject (strcat (substr ProNumber 1 2) "." (substr ProNumber 3 2) "." (substr ProNumber 5 2) "*")) (setq fn (vl-filename-mktemp "explorer.bat")) (setq f (open fn "w")) (write-line (strcat "cd " Root Discipline nameProject) f) (write-line "EXPLORER ." f) (close f) (startapp fn) (princ) ) Quote
OMEGA-ThundeR Posted May 5, 2014 Author Posted May 5, 2014 (edited) Code... 'Command: ; error: bad argument type: numberp: nil' On load... --------- Aaaand the code works thanks to some elbow grease from my colleague.. (defun c:pj () ; Shorten 'project' command (c:project) (princ) ) (defun c:project( / Root RootDis ProNummer nameProject DisCheck Discipline ) ; ROOT FOLDER (setq Root "G:\\") ; INPUT PROJECTNUMBER (if (setq ProNummer (getstring "\nEnter Projectnumber: ")) ; CHECK VALID (if (or (/= (strlen ProNummer) 6) (wcmatch ProNummer "*`.*")) ; IF - FALSE (alert "Invalid number (only 6 numbers)!") ; IF - TRUE (progn ; SET DISCIPLINE (setq DisCheck (substr Pronummer 1 2)) (cond ((= DisCheck "51") (setq Discipline "C1\\")) ((= DisCheck "52") (setq Discipline "C2\\")) ((= DisCheck "53") (setq Discipline "C3\\")) ((= DisCheck "54") (setq Discipline "C4\\")) ((= DisCheck "55") (setq Discipline "C5\\")) ((= DisCheck "56") (setq Discipline "C6\\")) ((= DisCheck "57") (setq Discipline "C7\\")) ) (setq RootDis (strcat Root Discipline)) ;(prompt RootDis) ; DEBUG ; OPEN PROJECTFOLDER (if (vl-some '(lambda(x) (wcmatch (setq nameProject x) (strcat (substr ProNummer 1 2) "." (substr ProNummer 3 2) "." (substr ProNummer 5 2) "*"))) (vl-directory-files RootDis nil -1)) (startapp "EXPLORER" (strcat RootDis nameProject)) (alert "Projectfolder not found or does not exist.") ) ) ) ) (princ) ) ;;; END Edited May 5, 2014 by OMEGA-ThundeR problem solved! 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.