TimSchrock Posted January 8, 2021 Share Posted January 8, 2021 Hey all, I have an idea that I want to create a macro to help my cabinet code. For this specific cabinet (from my manufacturer), if the cabinet is 42" or less, the code is "VTC30 *width*-1B" and greater than 42", the code is "VTC30 *width*-2B". First, I'm starting with the macro and trying to get the width of the referenced object, but I keep getting an evaluation error that there is an undefined local variable or method. I've tried "width", "referenced.width", "owner.width" and all the same thing. Can you point me to the right direction? Link to comment Share on other sites More sharing options...
TimSchrock Posted January 8, 2021 Author Share Posted January 8, 2021 So, I can enter a macro "referenced.width" and I receive the correct width of the cabinet, but then I cannot figure how to get it to do the logic of *if referenced.width <= 42 then cablabel = "1B" else cablable = "2B"" Link to comment Share on other sites More sharing options...
Alaskan_Son Posted January 8, 2021 Share Posted January 8, 2021 Are you using X11 like your signature says or X12? Link to comment Share on other sites More sharing options...
TimSchrock Posted January 9, 2021 Author Share Posted January 9, 2021 11 hours ago, Alaskan_Son said: Are you using X11 like your signature says or X12? Whoops. No. Signature is out of date. Using X12. Link to comment Share on other sites More sharing options...
TimSchrock Posted January 9, 2021 Author Share Posted January 9, 2021 10 hours ago, solver said: With X12 you can place this in the Label of the cabinet, and I'm sure there is better Ruby code to do it. VTC30 %width.to_s.to_i%-%width.to_f > 42 ? '2' : '1'%B Thanks! I’ll try that Link to comment Share on other sites More sharing options...
TimSchrock Posted January 9, 2021 Author Share Posted January 9, 2021 17 minutes ago, solver said: Update by clicking on your user name at the top right of the page, click Account Settings, then Signature on the left. I updated my signature after OP, but it still shows X11 here. odd..... Anyway, the real reason for replying is that the code worked! Can I beg another question? What does it mean? I had the %width% working - it showed the accurate width. What is the "width.to_s.to_i" and "width.to_f" doing? convert "to string" and "to integer"? Not sure what to guess on "to_f". Link to comment Share on other sites More sharing options...
Chopsaw Posted January 9, 2021 Share Posted January 9, 2021 Just now, TimSchrock said: Not sure what to guess on "to_f". "to_float" and good guesses on everything else. Link to comment Share on other sites More sharing options...
TimSchrock Posted January 9, 2021 Author Share Posted January 9, 2021 1 minute ago, Chopsaw said: "to_float" and good guesses on everything else. what does that do? Link to comment Share on other sites More sharing options...
Chopsaw Posted January 9, 2021 Share Posted January 9, 2021 4 minutes ago, TimSchrock said: what does that do? I might leave that to Eric because I am not even sure it needs to be there in X12 as the width should already be a float value. You could try removing it and see what changes. I might be wrong though. Float Float objects represent inexact real numbers using the native architecture's double-precision floating point representation. Link to comment Share on other sites More sharing options...
Chopsaw Posted January 9, 2021 Share Posted January 9, 2021 Oh I forgot that will remove the punctuation generated by the new measurement class so it is necessary for this purpose. Link to comment Share on other sites More sharing options...
TimSchrock Posted January 9, 2021 Author Share Posted January 9, 2021 @solver or @Alaskan_Son, I'm on a mission to get some cabinetry codes working with Ruby. I see a property that is "has_stile_between_double_doors" (TrueClass) and a property that is "num_doors" (Integer). If num_doors = 2 and has_style_between_double_doors is false, I want to add "-BT" to the code. Link to comment Share on other sites More sharing options...
TimSchrock Posted January 9, 2021 Author Share Posted January 9, 2021 13 minutes ago, TimSchrock said: @solver or @Alaskan_Son, I'm on a mission to get some cabinetry codes working with Ruby. I see a property that is "has_stile_between_double_doors" (TrueClass) and a property that is "num_doors" (Integer). If num_doors = 2 and has_style_between_double_doors is false, I want to add "-BT" to the code. I've tried this in a macro I call %ButtDoors% - has_stile_between_double_doors.to_s = 'true' ? (num_doors = 2 ? '' : '-BT') It only returns that very same text when I place %ButtDoors% in the text box Link to comment Share on other sites More sharing options...
Alaskan_Son Posted January 9, 2021 Share Posted January 9, 2021 1 hour ago, TimSchrock said: Whoops. No. Signature is out of date. Using X12. The reason I asked is because Chief introduced the Measurement class in X12. Prior to X12, object attributes like owner.width were stored and reported as Floats which are numeric. They are no longer stored and reported as Floats but as Measurements with specified units. In Imperial plans, the units are inches, and in Metric plans, the units are millimeters. The reason your initial code wouldn't work is because "if referenced.width <= 42..." didn't make any sense. Since referenced.width is being stored as inches you needed to specify 42 of what. Eric's code got around this by converting width to a float (decimal) or an integer (whole) number with no unit. He could then compare the 2 values apples to apples. My recommended approach would be different and I would suggest taking advantage of Chief's Measurement class by just adding a unit to 42... "if referenced.width <= 42.in..." or "if referenced.width <= 3.5.ft..." As a parting tip, I would also strongly recommend against coercing a value into an integer unless it really makes sense for the application. It will always round down to the nearest whole number and values below 1 will always result in 0. It's just bad practice in my opinion. A 41.75" cabinet would report as 41 and any values multiplied by a value less than one would result in zero. The better approach is .to_f.round with or with an argument. Link to comment Share on other sites More sharing options...
TimSchrock Posted January 9, 2021 Author Share Posted January 9, 2021 (edited) 5 minutes ago, solver said: Lots of ways to do this. Suggest you either spend some time learning the ins and outs of macros and Ruby, or hire someone to set things up for you. This isn't something easily done via the forum. I'm actually decent at programming languages, but the Ruby tutorials I've found aren't geared toward Chief and talk about local, class, instance, and global variables, of which I can't figure out how that connects to Chief. Can you point to tutorials of Ruby within Chief? Edited January 9, 2021 by TimSchrock clarification Link to comment Share on other sites More sharing options...
TimSchrock Posted January 9, 2021 Author Share Posted January 9, 2021 (edited) I solved it! Enter this into the label or code (under the "Object Information) box: %automatic_label%%has_stile_between_double_doors == false ? (num_doors.to_f > 1 ? '-BT' : '') : ''% Edited January 9, 2021 by TimSchrock Corrected code 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