Sign in to follow this  
LevisL

Door Width Macro

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.

Share this post


Link to post
Share on other sites

Levis,

 

Just change

when dbl = true

 

to

 

when dbl

    or

when dbl == true

Share this post


Link to post
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(", ","/")

Share this post


Link to post
Share on other sites

Thanks Joe. That works almost perfectly. It puts square brackets around the size though ( [2/6] instead of 2/6 ). What is causing this?

Share this post


Link to post
Share on other sites

Size1 is an array.  Add this to the last line

 

.sub("[","").sub("]","")

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
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".

Share this post


Link to post
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? 

Share this post


Link to post
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}"

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

  • Member Statistics

    28833
    Total Members
    9156
    Most Online
    Chieftan_1
    Newest Member
    Chieftan_1
    Joined