MarkMc Posted December 30, 2018 Share Posted December 30, 2018 I can read a file using- File.read ("D:/Mark/Documents/_ Current Kit/ _Price/test_1.csv") works once backslashes are changed to forward -requires parenthesis and quote So I copy and paste a path statemtent into an OIP filed (using supplier) and then use a macro to change the slashes and add parenthesis and quotes that works fine using- #first reads the file from the Supplier field in the cabinet DBX, then it changes the back slashes to forward slashes so Ruby can use it myFile= owner.supplier.gsub(/\\/,'/') # next need to parenthesis and quotes for the file to be found -looks like ("C:/some file...") path= ('("')+myFile+('")') I've tried a few variations on that which also work then I'm trying to read that file. question is once I have that result how can I get Ruby to read the file? Also if someone on a Mac can open the program and let me know if you get the same results as the posted image please? macro test.plan Link to comment Share on other sites More sharing options...
glennw Posted December 31, 2018 Share Posted December 31, 2018 Mark, I get this on a mac. Link to comment Share on other sites More sharing options...
MarkMc Posted December 31, 2018 Author Share Posted December 31, 2018 Thanks Glen, was afraid that would happen. Guess I either have to add some code or write a version specific to a Mac. That latter is easier for me but I'm going to be giving this away and may be confusing for others, and I guess it's better if it worked either way. Guess I have to check to see if Ruby in Chief can understand what OS it's on. Link to comment Share on other sites More sharing options...
glennw Posted December 31, 2018 Share Posted December 31, 2018 Let me know if you want me to try things on a mac. Link to comment Share on other sites More sharing options...
MarkMc Posted December 31, 2018 Author Share Posted December 31, 2018 29 minutes ago, solver said: Not sure what you are asking, but this opens and reads the file into a. Eric- I can read a file with a path as in For that I changed the backslashes to forward before placing in the macro-that is a nogo in the long run. What I can't get to read is when I generate the altered path within the macro. Tried more than a few variations. If what you post will work I don't understand how to use it and utilize the altered path in the result shown. Link to comment Share on other sites More sharing options...
MarkMc Posted December 31, 2018 Author Share Posted December 31, 2018 48 minutes ago, glennw said: Mark, I get this on a mac. Glen I just realized that I didn't include the file so naturally you get an error for the read macro. I think to find out if this works on both I first have to get the longer macro to read on windows. Then will try posting something again, thanks. Link to comment Share on other sites More sharing options...
MarkMc Posted December 31, 2018 Author Share Posted December 31, 2018 7 minutes ago, solver said: f="d:\\rb.txt" <---- the value of f is d:\rb.txt -- you don't need to add the quotes or parenthesis. fh=open f a=fh.read fh.close a I still don't see how to make that work even if I don't use the macro- tried this after making a new text file, copying the path and pasting get error- f=C:\\Users\mark\Documents\A_Current\test new.txt fh=open f a=fh.read fh.close a are you saying to add this file as an rb to the scripts folder? prefer not to go there for this. Link to comment Share on other sites More sharing options...
MarkMc Posted December 31, 2018 Author Share Posted December 31, 2018 3 minutes ago, solver said: f="C:\\Users\\mark\\Documents\\A_Current\\test new.txt" Ruby, and other languages use the \ character with a string to allow the insertion of special characters. If you want the \ character, then it must be doubled. The quotes delimit a string value. Ok so I got that to work so long as I add the extra slashes and quotes manually. Note that above I list a statement with File.read ("C:/somewhere/doc.text") that also reads when I do it manually. So I have two ways to MANUALLY alter a path and get it to read. However if I go and write something to automatically add the extra slashes and the quotes I'm pretty sure I'm going to end up with the same problem. How do I use the result to read? I want to have it so someone can paste a path into the Supplier field and have it read properly without user needing to adjust the path statement. Link to comment Share on other sites More sharing options...
MarkMc Posted December 31, 2018 Author Share Posted December 31, 2018 7 minutes ago, solver said: The supplier field is C:\Users\mark\Documents\A_Current\test new.txt This line gets that value and changes either \ or / into \\ Don't know if you need to test for both. If not change [/|\] to \ f=owner.supplier.gsub("[/|\]","\\") Thanks Eric but I'm not getting anywhere and been at this all day- Did you open the file I posted? already had gsub written. I'll pick this up again tomorrow, fried, thanks again Link to comment Share on other sites More sharing options...
GerryT Posted December 31, 2018 Share Posted December 31, 2018 From reading your posts, I haven't the slightest idea of what your trying to accomplish. Trying to understand why you don't just put the file in your scripts directory and let Chief handle the path automatically for the MAC or PC. File.read ($LOAD_PATH[0] +"test_1.txt") Eliminates need for any path. Note that macs do not use letter drives 1 Link to comment Share on other sites More sharing options...
Chopsaw Posted December 31, 2018 Share Posted December 31, 2018 28 minutes ago, GerryT said: File.read ($LOAD_PATH[0] +"test_1.txt") Eliminates need for any path. Thanks Gerry, I am working on a slightly different project but this looks like a nice solution for me and I think it will work for Mark if I am following along correctly. Any idea why X10 would be referencing my X8 scripts folder when the file path in Preferences is clearly marked as X10 ? Also wondering if there is a way to deal with the extra " "" that the text file generates around a measurement in feet and inches ie. ( 6' 8" ) seems to automatically come out as ( " 6' 8""" ) in the text file originally sourced from excel. Can ruby handle this within Chief and find and remove the three extra " 's ? Link to comment Share on other sites More sharing options...
GerryT Posted December 31, 2018 Share Posted December 31, 2018 18 minutes ago, Chopsaw said: Any idea why X10 would be referencing my X8 scripts folder when the file path in Preferences is clearly marked as X10 ? Most likely it was copied from a previous upgrade. Change the path in preferences/general/ruby from x8 to x10 Link to comment Share on other sites More sharing options...
Chopsaw Posted December 31, 2018 Share Posted December 31, 2018 27 minutes ago, GerryT said: Change the path in preferences/general/ruby from x8 to x10 Thanks, that worked. 32 minutes ago, solver said: Yes. You just need to write the code. Would that search the entire imported text file and fix all instances ? If so that would be great. Could you help with that ? Ruby is something I hope to learn in the future but have not begun to grasp it quite yet. Link to comment Share on other sites More sharing options...
MarkMc Posted December 31, 2018 Author Share Posted December 31, 2018 3 minutes ago, solver said: Post a representative example of the data and I'll have a look. I'm trying not to. Link to comment Share on other sites More sharing options...
MarkMc Posted December 31, 2018 Author Share Posted December 31, 2018 Quote Trying to understand why you don't just put the file in your scripts directory and let Chief handle the path automatically for the MAC or PC. File.read ($LOAD_PATH[0] +"test_1.txt") Eliminates need for any path. Note that macs do not use letter drives I wanted to avoid the scripts directory if possible to keep it simpler for end user. Re: File.read ($LOAD_PATH[0] +"test_1.txt") That makes the path problem easier and likely simplifies the cross platform issues AND it works within the macro. HOWEVER IF I place the file location or name into an OIP field and try to get that data into a macro that reads the file it has the same problems I ran into already. The problem is that while the OIP field output looks correct -be it a correctly formatted path OR any variation I can come up of ($LOAD_PATH[0] +"test_1.txt") I don't know how to include the output from the field or another macro into a "File.read" statement. Since the text file can change on a regular basis AND I don't want end users changing code I want to be able to place the text file in an OIP field. 11 hours ago, GerryT said: From reading your posts, I haven't the slightest idea of what your trying to accomplish. Here's what I'm trying to do- The short answer This is for the cabinet pricng system I started last summer. I looked for ways to simplify it for the end user (I don’t need it myself but promised it to some folks). The purpose is to generate quick ball park pricing. Data goes to schedule which is copied to spreadhseet template. Final pricing can be done with some manipulation of the spreadsheet or copying from the sheet to an on line ordering system. How-user places files somewhere on system (there will be multiple files), defines file in OIP field, macro looks up pricing for cabinet, output to schedule, copy schedule info to a spreadsheet template. Limit what a user needs to do or not No altering code Generate text files and place somewhere they understand Enter data in OIP fields in cabinet DBX or defaults Occasionally add price into an OIP filed for a cabinet not included in files (but can be in library) Process-temporarily remove columns from schedule, copy, paste into spreadsheet template, undo to restore shedule fields (be nice if two schedules could have user defined numbering in sync..) For brands that use style/species pricing instead of columns enter those prices in sheet (could be in the spreadsheet template) Considerations The typical end user is used to other software for cabinet pricing where you install a catalog, select price category from a drop down list, click report, done. At the same time I have to deal with my limitations with Ruby and avoid as many pitfalls for end user as I can. OTOH I’m not interested in this being everything possible A typical kitchen dealer will carry between 3 and 6 brands, some of those could have 2 to 4 lines with different pricing. More than half of the cabinet brands out there use groups for pricing (A,B,C,D…) The pricing changes annually. All that can make for either large complicated files (and macro) or a lot of files. To that end- Text files will include only the most common cabinet styles and prices. Text files will be limited to a single price group and only the most sold groups included (ROI for included something that is sold once a year or less is lousy) For rarely sold categories get out your pencil. (hey, I’ve been getting prices out of CA for 5 years without it and could have done twice all those cabinet orders in the less time than spent on this ) Link to comment Share on other sites More sharing options...
MarkMc Posted December 31, 2018 Author Share Posted December 31, 2018 19 minutes ago, solver said: The contents of the file are displayed in the schedule in both the Label and custom field. I'm guessing that the macro should read the file, compare the cabinet identifier with data in the file, on finding a match it gets the price and returns that instead of the contents of the entire file as I've done. Yabadabadoo- Thanks that works fine. Thanks so much. I have no idea why it didn't work for me last night, tried it six ways to Sunday when after you posted-must have been pilot/syntax error or such, was at it for 10 hours by then and had written at least 3 dozen versions prior to posting-on a good day I struggle with this. Your guess is correct-I now have to define where to find what to match and the lookup then formatting that result with extra determiners for output so columns sort properly in spreadsheet. Baby steps... WOW- I was just about to ask to see if this would work on a Mac so copied the macro and eliminated gsub. It still works on Windows without the substitution!! I don't know why I could not get the originals to read without changing the slashes and I'd seen several complaints about folks having to do that on stackoverflow (where I understand very little). This is great. I'm guessing it's because you have the file open in there instead of just read? Link to comment Share on other sites More sharing options...
BrownTiger Posted December 31, 2018 Share Posted December 31, 2018 Depending on what are you trying to accomplish, below will give you a location of CA/csv/myL 17 hours ago, GerryT said: From reading your posts, I haven't the slightest idea of what your trying to accomplish. Trying to understand why you don't just put the file in your scripts directory and let Chief handle the path automatically for the MAC or PC. File.read ($LOAD_PATH[0] +"test_1.txt") Eliminates need for any path. Note that macs do not use letter drives NOTE: THIS IS NOT THE CORRECT WAY TO USE PATH libx1 = File.expand_path("test_1.txt", $LOAD_PATH[0]) => "C:/Users/browntiger/Documents/Chief Architect Premier X10 Data/Scripts/test_1.txt" Call can (also include backslashes) libx1 = File.expand_path("../test_1.txt", $LOAD_PATH[0]) or this mycsv = File.expand_path("../csv/myLibrary.csv", __FILE__) or File.read(File.expand_path... Link to comment Share on other sites More sharing options...
Chopsaw Posted January 1, 2019 Share Posted January 1, 2019 9 hours ago, solver said: 20 hours ago, Chopsaw said: Would that search the entire imported text file and fix all instances ? If so that would be great. Could you help with that ? Post a representative example of the data and I'll have a look. Thanks Eric, this is just the sample file I have been tinkering with. Siding Test.txt Link to comment Share on other sites More sharing options...
Chopsaw Posted January 1, 2019 Share Posted January 1, 2019 You make that look easy Eric. Thanks so much. I did not even imagine it would be possible. Will give it a try and see how it goes. Fingers crossed. Link to comment Share on other sites More sharing options...
Chopsaw Posted January 1, 2019 Share Posted January 1, 2019 Ok the you explained the gsub and it makes perfect sense but where does it go ? This is just for display of data as text not an actual schedule as I could not get that to work in chief for this particular situation if you did not pick that up already. Link to comment Share on other sites More sharing options...
Chopsaw Posted January 1, 2019 Share Posted January 1, 2019 Thank you Eric. Now I have something useful and I may have a renewed interest in ruby for other uses. Happy New Year !! 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
Sign In Now