Door Width Macro


LevisL
 Share

Recommended Posts

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

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

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share