LevisL Posted April 5, 2016 Share Posted April 5, 2016 I have a custom macro for door widths where the feet and inches are separated by a slash (e.g.: 2/6). I'd like for this macro to recognize when I put in a double door and note it as 'DBL', plus the width of each leaf (e.g.: DBL 2/6) instead of the full door width. This is the macro I currently have: arr = width.round.divmod(12) "#{arr[0]}/#{arr[1].round}" Can one of the macro gurus guide me in creating this new macro? I know the macro needs to check the is_double_door variable and then divide the size by 2 if it is in fact double. I'm trying to learn Ruby, but I'm limited on time right now. I tried this: dbl = is_double_door size1 = width.round.divmod(12) "#{size1[0]}/#{size1[1].round}" size2 = width.round.divmod(12) "#{size2[0]}/#{size2[1].round}" case when dbl = true result = "DBL #{size1}" else result = size2 end result This results in the label showing DBL whether it actually is a double door or not. Plus, it formats the width as [2, 6] instead of 2/6. And I'm not sure what to do to divide the width by 2. I tried sticking in /2 in a few different spots in the 'size1' variable, but it just results in an evaluation error. Link to comment Share on other sites More sharing options...
Joe_Carrick Posted April 5, 2016 Share Posted April 5, 2016 Levis, Just change when dbl = true to when dbl or when dbl == true Link to comment Share on other sites More sharing options...
Joe_Carrick Posted April 5, 2016 Share Posted April 5, 2016 Levis, Try this instead: if is_double_door size1 = (width/2).round.divmod(12) else size1 = width.round.divmod(12) end "#{size1[0]}/#{size1[1].round}" if is_double_door result = "DBL #{size1}" else result = size1 end result.to_s.sub(", ","/") Link to comment Share on other sites More sharing options...
LevisL Posted April 5, 2016 Author Share Posted April 5, 2016 Thanks Joe. That works almost perfectly. It puts square brackets around the size though ( [2/6] instead of 2/6 ). What is causing this? Link to comment Share on other sites More sharing options...
Joe_Carrick Posted April 5, 2016 Share Posted April 5, 2016 Size1 is an array. Add this to the last line .sub("[","").sub("]","") Link to comment Share on other sites More sharing options...
LevisL Posted April 5, 2016 Author Share Posted April 5, 2016 That didn't quite work. But I got it to work by appending the subs to the end of the other result line: result.to_s.sub(", ","/").sub("[","").sub("]","") Thanks again! Link to comment Share on other sites More sharing options...
Joe_Carrick Posted April 6, 2016 Share Posted April 6, 2016 I decided to take another look at this. referenced ? obj = referenced : obj = owner if obj.is_double_door asize = (obj.width/2).round.divmod(12) result = "DBL #{asize[0]}/#{asize[1].round}" else asize = obj.width.round.divmod(12) result = "#{asize[0]}/#{asize[1].round}" end Definitely simpler and the 1st line eliminates the need to set the "Context". Link to comment Share on other sites More sharing options...
Greg_NY61 Posted April 6, 2016 Share Posted April 6, 2016 Joe is there a way to add height to this macro like 6/8 or you have to make a separate macro for that? Link to comment Share on other sites More sharing options...
Joe_Carrick Posted April 7, 2016 Share Posted April 7, 2016 Joe is there a way to add height to this macro like 6/8 or you have to make a separate macro for that? referenced ? obj = referenced : obj = owner if obj.is_double_door asize = (obj.width/2).round.divmod(12) result = "DBL #{asize[0]}/#{asize[1].round}" else asize = obj.width.round.divmod(12) result = "#{asize[0]}/#{asize[1].round}" end asize = obj.height.round.divmod(12) result = result + ",#{asize[0]}/#{asize[1].round}" Link to comment Share on other sites More sharing options...
Greg_NY61 Posted April 7, 2016 Share Posted April 7, 2016 Thank you Joe!!! That worked Perfect. 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