Macro Help


MikeJG
 Share

Recommended Posts

I'm brand new to macros and I've watched the training video.

 

I'm trying to create a macro that takes the result of the FormattedOpeningWidth macro and subtract 1 5/8" from it. Here's the FormattedOpeningWidth macro:

 

arr = width.round.divmod(12)

"#{arr[0]}#{arr[1].round}"

 

It seems like it would be simple to just put a -1.625 in there, but it isn't working.

 

How should the macro read to get the result?

 

Thanks

Link to comment
Share on other sites

You might have to modify this a bit depending on what you want for rounding.

Basically, you need to calculate the result before the formatting.  For fractions you would need to use another divmod of one of the array values.

 

w = width-1.625

arr = w.round.divmod(12)

"#{arr[0]}#{arr[1].round}"

 

If you can give me an example of a width and what you want the final output to look like I can give you a perfect macro.

Link to comment
Share on other sites

Mike,

 

Try the following.  It subtracts 1-5/8 from the width.  The it breaks that into inches and fractions and formats it to the nearest 1/8".  If you want the result to the nearest 1/16" just change the (8's) in line 3 to (16's).

 

w = width-1.625

inches = w.floor

frac = (w.remainder(inches)*8).round.quo(8)

case

  when frac == 1

    result = "#{inches + 1}"

  when frac == 0

    result = "#{inches}"

  else

    result = "#{inches} #{frac}"

  end

result

Link to comment
Share on other sites

Joe,

 

That works perfectly!

 

What I'm doing is making automatic labels for Andersen windows.  On double-hungs the width of the unit size is 1 5/8" wider than the window label.  For instance a 30 width window is actually 37 5/8" wide.  With the macro I can make the unit the correct size and have the label read correctly.  I've been doing it manually all this time.

 

Thanks!

Link to comment
Share on other sites

Mike,

 

The power of Ruby and Macros is good - but CA really needs to expand it so it's easier to use and has access to all the various objects and their parameters. 

 

What would be really great is if Chief had a set of macros doing such formatting tasks that could be inserted into user defined macros (within the define macro tool).  Sort of a "Super Macro Subroutine Library".

 

In your case, it could be something like:

 

w = width - 1.625

%format_inches(w,8)%

 

-or-

 

%format_inches(width-1.625,8)%

 

 

Having this kind of capability with predefined subroutines would make Chief's Ruby/Macro capability much easier for the novice.

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