[Er...] Posted January 14, 2021 Share Posted January 14, 2021 No fun problems have poped up here in like for ever, so how about another educational challange? Think your man or woman (Yes Laura, you are also welcome) enough? Now this sould not be super easy, atleast to get decent points. Unless I overlooked something? Task: Execute external files containing pcm. Challange: You don't know the full path to them or how many they are. Or more exactly. It may be a different amount every time. Even the path may change. Description: Let's say you know the files are located in your C:\ drive. And they are all located in, and in a sub-folders inside a folder called challange. And you don't know how many there is. All files you need to execute are named same as your drawing no. And have the file extension ".para". Point system: You start at 15, and for every line less then 15 lines of code. You will subtract 1. Closest to zero wins. Attached are a folder system that you can use. It looks like this: *C:\.. ...you_dont_know_this_folder\ not_this_one_either\ bunch of files (DONT EXECUTE THESE) also_unknown_part_of_the_path\ *challange\ bunch of files Random1\ bunch of files Random2\ bunch of files Random3\ bunch of files Where "random" and "challange" contains the files you need to execute. The ones marked with a *, are the only thing you know. (Except that the files are named as your drawing no and have the .para extension) Rules: 1) You can do systemCall("mySuperScript.ps") to some executable. But for every call to an external file. You get 30 points as a punishment. (Since it contains lines..) 2) You can assign 2 variables at the beginning. That don't count as lines. For the ease of testing. 3) The file-structure shall be able to be placed anywhere on the specified drive. Even change, and your code must work anyway. Here is some stuff to explain: //--You can use this for testing purpouse, it don't count as lines. //--And works well with the pre-created folder structure you can download. dwgNo="123" setRecordHead("drawingno",dwgNo.shuffle) //--END //--Your 2 free variables var1="They don't need to be named var" something="C:\" //--END //--From now on, you are hunting for zero lines. ... //--How many lines? Have a look at the attached file structure, and it might clarify further. If we get 5 working tries, I'll share what I think is the shortest way to do it. Looking forward to see how people think. Don't be shy! Happy hunting!you_dont_know_this_folder.7z Link to comment Share on other sites More sharing options...
[Me...] Posted January 14, 2021 Share Posted January 14, 2021 Challenge Accepted ...……. 😎 Link to comment Share on other sites More sharing options...
[Er...] Posted January 15, 2021 Author Share Posted January 15, 2021 Thats the spirit! Link to comment Share on other sites More sharing options...
[Ch...] Posted January 15, 2021 Share Posted January 15, 2021 I love this. We need more of this stuff. Link to comment Share on other sites More sharing options...
[He...] Posted January 15, 2021 Share Posted January 15, 2021 Just to be clear. I know that the folder is called "Challange" (miss spelled and all) and in it and its subfolders it will be an unknown number of para-files named according to the drawing number. My goal is to execute all off them but none of the txt-files? Will there be any other folders called "Challange" on the drive that also contains correctly named para-files? And also. You have waaaaaaay to much time on your hands. Now I don't have to feel guilty bugging you with weird PCM questions. Link to comment Share on other sites More sharing options...
[Mi...] Posted January 15, 2021 Share Posted January 15, 2021 This is beyond me at this point, but eagerly following. Link to comment Share on other sites More sharing options...
[Er...] Posted January 15, 2021 Author Share Posted January 15, 2021 Please sign in to view this quote. Haha, yeah I suck. 🤣 Yes, only the .para, that is sub to challange. And have the correct name, based on drawing no. And the folder structure is just an example, it should be able to work with anything. As long as you know the drive and a folder. (Just to keep it down a notch.) I had not considered duplicate "challange" folder on the drive. Its up to you, but as faar as I consider it, not a reqirement. Yeah, the days after the hollidays have been unusually calm. But I guess hell is around the corner.. Link to comment Share on other sites More sharing options...
[Is...] Posted January 16, 2021 Share Posted January 16, 2021 ... Link to comment Share on other sites More sharing options...
[He...] Posted January 16, 2021 Share Posted January 16, 2021 Please sign in to view this quote. When you are at the top everyone must do whatever they can to bring you down. Another question. Should we PM it to you or just post it in this thread? Israel Soto Rodriguez: Thanks for your solution. The best thing with thing like this is that we get to see secret commands like .trimExteriorBlanks and .trimExteriorDoubleQuotes Another thing that goes to us all. This thread will probably contain solutions that have be shrunk in vertically and expanded horisontally to get so fewer lines but making it almost impossible to see the method of finding the random locations. Please also provide a more expanded solution. A simple example is this: Five lines: path_old = "C:\temp\new folder\test.txt" path_new = "s:\results\new folder\test.txt" deleteFile(path_new) copyFile(path_old,path_new) deleteFile(path_old) Three lines. deleteFile("s:\results\new folder\test.txt") copyFile("C:\temp\new folder\test.txt","s:\results\new folder\test.txt") deleteFile("C:\temp\new folder\test.txt") They do the same but the three lines are harder to read. When doing complex stuff the lines can get ridiculously long. Link to comment Share on other sites More sharing options...
[Me...] Posted January 16, 2021 Share Posted January 16, 2021 Here’s my submission, and yes it’s a complete disaster that Eric probably will shoot holes in... 😃 Couple of things worth noting, It’s looking for the misspelled folder name “challange”. If there are multiple folders it might break. I could have tested for that condition, but it wasn’t part of the rules. Also, depending on how deep you bury the main folder, it could take a bit to find everything so be patient while it’s executing. This can be pulled off with one line of ridiculous code, but I opted to censor a few things. If Eric does not mind, I’ll share my “one-liner” before he shows us his elegant solution. // Execute all .para files in folder named "challange" & any subsequent sub-folders. var1= "c:\" var2= "123" executeCode("dir:= '"+var1+"'. t1:= '*\'. t2:='challange'. [t3:= dir asFilename filesMatching: t2. (t3 size >0) ifFalse:[t2:= t1,t2] ifTrue:[t4:= OrderedCollection new. t3 first asFilename completeDirectoryContentsAsFilenames collect:[:file | (file tail= '"+var2+".para') ifTrue:[t4 add: file].].^t4]] repeat.") for i = 1 to executeCode("t4").size runPCMFile(getParameterNamed(executeCode("t4"),i).asString) next i Link to comment Share on other sites More sharing options...
[He...] Posted January 16, 2021 Share Posted January 16, 2021 My solution use cmd-script to first find the "challenge"-folder and then list all para-files in there and in subfolder 4 lines //--You can use this for testing purpouse, it don't count as lines. //--And works well with the pre-created folder structure you can download. dwgNo="123" setRecordHead("drawingno",dwgNo.shuffle) //--END //--Your 2 free variables //Free variables are for sycophants and products of incest. //--END //--From now on, you are hunting for zero lines. file_list = executeCode("WinProcess shOneOEM: 'cmd.exe /c dir " +qm() +executeCode("WinProcess shOneOEM: 'cmd.exe /c dir c:\*challange* /a:d /b /s' .").asArrayOfLines.first +"\*" +getRecordHead("drawingno") +".para" +qm() +" /b /s' .").asArrayOfLines for i = 1 to file_list.size runPCMFile(getParameterNamed(file_list,i)) next i The same thing but in 6 lines for clarity. //--You can use this for testing purpouse, it don't count as lines. //--And works well with the pre-created folder structure you can download. dwgNo="123" setRecordHead("drawingno",dwgNo.shuffle) //--END //--Your 2 free variables //Free variables are for sycophants and products of incest. //--END //--From now on, you are hunting for zero lines. Path_Folder = executeCode("WinProcess shOneOEM: 'cmd.exe /c dir c:\*challange* /a:d /b /s' .") Path_Folder_fixed = Path_Folder.asArrayOfLines.first +"\*" +getRecordHead("drawingno") +".para" file_list = executeCode("WinProcess shOneOEM: 'cmd.exe /c dir " +qm() +Path_Folder_fixed +qm() +" /b /s' .").asArrayOfLines for i = 1 to file_list.size runPCMFile(getParameterNamed(file_list,i)) next i It can also be reduced to 3 lines but it will take a lot longer to calculate. //--You can use this for testing purpouse, it don't count as lines. //--And works well with the pre-created folder structure you can download. dwgNo="123" setRecordHead("drawingno",dwgNo.shuffle) //--END //--Your 2 free variables //Free variables are for sycophants and products of incest. //--END //--From now on, you are hunting for zero lines. for i = 1 to executeCode("WinProcess shOneOEM: 'cmd.exe /c dir " +qm() +executeCode("WinProcess shOneOEM: 'cmd.exe /c dir c:\*challange* /a:d /b /s' .").asArrayOfLines.first +"\*" +getRecordHead("drawingno") +".para" +qm() +" /b /s' .").asArrayOfLines.size runPCMFile(getParameterNamed(executeCode("WinProcess shOneOEM: 'cmd.exe /c dir " +qm() +executeCode("WinProcess shOneOEM: 'cmd.exe /c dir c:\*challange* /a:d /b /s' .").asArrayOfLines.first +"\*" +getRecordHead("drawingno") +".para" +qm() +" /b /s' .").asArrayOfLines,i)) next i Link to comment Share on other sites More sharing options...
[Er...] Posted January 16, 2021 Author Share Posted January 16, 2021 We all think pretty much the same. 🙂 And that is in some ways dissapointing.. (Keep reading, I found one thing retaredly smart) I also had a one liner with nested block closures, for backup if I where to loose. But as Phillip said, not sure its wise. I also opted for a cmd.exe solution in the end, similar to Henriks, since I dont really like to show objects. Not sure what the copyright holders feel about that. I'll post my 3 lines tomorrow as Im on my phone hiding in my kids room, from wify... 🤣 Good job everyone btw! ....later that night. Here is my take (long version). Scary similar to Henriks... Did you peek in to my window or? for i = 1 to executeCode("WinProcess shOneOEM: 'dir "+qm()+executeCode("WinProcess shOneOEM: 'dir "+root+"\*"+folder+"* /A:D /B /S'").killTrailingBlanks+"\*"+getRecordHead("drawingno")+".para"+qm()+" /B /S'").asArrayOfLines.size runPCMFile(getParameterNamed(executeCode("WinProcess shOneOEM: 'dir "+qm()+executeCode("WinProcess shOneOEM: 'dir "+root+"\*"+folder+"* /A:D /B /S'").killTrailingBlanks+"\*"+getRecordHead("drawingno")+".para"+qm()+" /B /S'").asArrayOfLines,i)) next i I had to edit my oneliner a bit, since you Phillip solved one of my issues way better then I did. (I did my own string splitting instead of using tail.) I could shave mine 23 characters! I just 'dir':ed the shit of the the drive. May I ask how you came up with recusivly adding \* to the path by repeat? It's smart. And I was like: noooooooo he didnt, he did? OMG! I have never seen anything that stupid 😃 But in this contex, brilliant. Very in-effective though. Im laughing with you on this one. Not at you. 🤣 (I like to see short stuff. That really brings out the brutal savage in everyone. And stuff like the *\ is exactly what I like to see. Things that I would not think of in a million years.) I'll PM my "new" oneliner, I think that is the most wise thing to do. Here is one version that don't execute it, it only shows the content of the file. (So this thread has some educational value for others. It also handles Henriks multiple challange folders scenario.) executeCode("(WinProcess shOneOEM: 'dir c:\*challange /A:D /B /S') asArrayOfLines collect: [:x | (x asFilename completeDirectoryContentsAsFilenames) asCollection collect: [:y | (y tail = '123.para') ifTrue: [ICCDialog message: y contentsOfEntireFile]]]") And as a contest. I'll say we all did it in 3 lines. The one you shared Phillip can be turned in to 3 as well, in the same stupid fashion I and Henrik did. Henrik: 3 Phillip: 3 Eric: 3 Israel: sqrt(9) (You created the file, so I'll get away with it.) Thank you for playing! ...next time I'll get bored. We'll do ray tracing with the acis kernel, or somthing else ridicoulus 😃 Link to comment Share on other sites More sharing options...
[Me...] Posted January 18, 2021 Share Posted January 18, 2021 Please sign in to view this quote. Believe it or not, I just happen to stumble on it while jacking around. Once I saw that it worked, I figured what the heck, let’s roll with it and see if I get chastised for doing something ignorant. 😃 Please sign in to view this quote. You have more than just Henrik peeking in your window.... 🤣 Link to comment Share on other sites More sharing options...
[Mi...] Posted January 22, 2021 Share Posted January 22, 2021 So this post was well above my level of knowledge, but from it I was able to learn how to create something I've wanted to do for a while that helps us simplify our as-idiot-proof-as-possible loading instructions. Saved in inspection_start_pcm.txt in the measurement plan folder: systemCallWithWait("C:\Program Files\IrfanView\i_view64.exe " +chr(34)+ getActualInspectionDir() + "\Loading.jpg"+chr(34)) Thank you Eric for the game! Helps us learners even if it's just fun for you guys. Link to comment Share on other sites More sharing options...
[Cl...] Posted January 22, 2021 Share Posted January 22, 2021 Please sign in to view this quote. So what does this do? Does it prompt the operator to view a pic on how to load the part before the program starts? Thank you Eric for the game! Helps us learners even if it's just fun for you guys. [/quote] Link to comment Share on other sites More sharing options...
[Mi...] Posted January 22, 2021 Share Posted January 22, 2021 It uses an external photo viewer/editor, irfanview, to automatically display a full screen photo that is a collage of 3-4 pictures of the part loaded correctly, and a section of text with text based instructions. Before, we similar code in the presettings of every single program ( 30ish CMMs, many hundreds of programs) systemCallWithWait("C:\Program Files\IrfanView\i_view64.exe C:\data\cmm\userinfo\xxxxx.jpg") We used a custom path because we have everything from version 4 to 6.8 in this building and calypso file directories have changed, which would break the code. But we still had a lot to maintain when it came to moving programs from one machine to the other. And, any changes mean every program needs to be edited. Now, with this, when you put inspection_start_pcm.txt in your designated program directory it executes every time any program on that machine runs, in this case it then goes to the directory for the open measurment plan and opens the instruction photo saved there. Any changes are done externally, this will save many many hours. Link to comment Share on other sites More sharing options...
[Cl...] Posted January 22, 2021 Share Posted January 22, 2021 So that line is inserted in the presettings? Link to comment Share on other sites More sharing options...
[Mi...] Posted January 22, 2021 Share Posted January 22, 2021 Not anymore. Now its in an external PCM file. Nothing is in the presettings that's why its great. Link to comment Share on other sites More sharing options...
[Cl...] Posted January 22, 2021 Share Posted January 22, 2021 Ok, got it. Link to comment Share on other sites More sharing options...
[Mi...] Posted January 22, 2021 Share Posted January 22, 2021 Old, saved in the presettings: systemCallWithWait("C:\Program Files\IrfanView\i_view64.exe C:\data\cmm\userinfo\xxxxx.jpg") In every single program. If something changed, every program needed to be edited, or if we moved a program we had to maintain the photo library. New, thanks to this post. in "inspection_start_pcm.txt" saved in the measurement plan folder saving here makes it execute automatically every single time an inspection is started. systemCallWithWait("C:\Program Files\IrfanView\i_view64.exe " +chr(34)+ getActualInspectionDir() + "\Loading.jpg"+chr(34)) the instruction photos now get saved in the inspection directory for each program with the name Loading.jpg, and that external pcm code will find and open it every time. So now it's zero maintenance, and if we change the code, like use a different program to display it, we edit one text file per machine, not hundreds of programs. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in