Simple year macro


rgardner
 Share

Recommended Posts

Hi everyone, hope you are having a wonderful week so far.  I was setting up a new layout for a builder I am doing more and more work for and went to type in my ©2019 when I thought...  I wonder if there is a 4 digit year macro I can put in there so I don't have to change that every year on all my layouts???   I am new'sh to macros so still have a ton to learn.  I couldn't find it in the chief macros and I did search here on the forum but have not found it. 

 

Anyone know what it is?  TIA for all your continued help and support.  You guys are amazing! :)

Link to comment
Share on other sites

4 minutes ago, Joe_Carrick said:

Macro "year"

  • t = Time.new
  • result = t.year 

returns the current year  --> 2019 as a numerical value

  • result = result.to_s

returns a character string --> "2019"

 

I obviously am doing something wrong because it isn´t coming out right.  What would i need to paste in there exactly to make it work. I have been trying to watch videos to figure this out but I am obviously missing a step.

 

Link to comment
Share on other sites

My understanding is that "non-evaluated" macro can use one or many evaluated macros and any global macros ... e.g. %client.name%.

While evaluated macro in CA can never execute another macro ( at least I have never been able to figure out how module_eval, or instance_eval can execute others )

 

Where it could be used: let say you have

labelCeiling macro none evaluated  macro that is defined:

%showCeilingsHeight%%collectRoomInformation%

 

 

Link to comment
Share on other sites

12 minutes ago, BrownTiger said:

My understanding is that "non-evaluated" macro can use one or many evaluated macros and any global macros ... e.g. %client.name%.

While evaluated macro in CA can never execute another macro ( at least I have never been able to figure out how module_eval, or instance_eval can execute others ) 

 

Where it could be used: let say you have

labelCeiling macro none evaluated  macro that is defined:

%showCeilingsHeight%%collectRoomInformation%

  

 

 

Think of it this way...

  • Evaluated = "Hey Chief, I want you to send all this text over to Ruby to execute as code".  Text macros are a pure Chief construct and have nothing to do with Ruby unless the macro is set to evaluate, and even then, it's only the code execution that involves Ruby.
  • Non-evaluated = "Hey Chief, I just want you to just use this as dumb text."
  • Anything between % signs is pure Chief and has nothing whatsoever to do with Ruby.  Ruby only sees the text value of the two % signs along with the characters between them. 
  • Chief sees %macro_name% onscreen in the plan and it spits out the results of whatever that macro is whether it be evaluated or not.
Link to comment
Share on other sites

33 minutes ago, BrownTiger said:

While evaluated macro in CA can never execute another macro ( at least I have never been able to figure out how module_eval, or instance_eval can execute others )

Within a custom evaluated macro just include another macro you want to use in quotes.  example:

  • result = "%my_other_macro%"

Here's an example of how I use this technique to display the label differently depending on the layer_set name.

 

if obj.layer_set.include? "Legend"

  result = "%window_label_legend_X11%"

elsif obj.layer_set.include? "Wall Area Analysis Plan"

  result = "%wall_opening_areas%"

elsif obj.layer_set.include? "Wall Area Analysis Elevation"

  result = "%wall_opening_areas%"

elsif obj.layer_set.include? "Wall Area Analysis Plan" or obj.layer_set.include? "Wall Area Analysis Ref"

  result = "%wall_opening_areas%"

elsif obj.layer_set.include? "Framing"

  result = "%opening_header_label%"

elsif obj.layer_set.include? "Section" or obj.layer_set.include? "Elevation"

  result = obj.schedule_number + "\n" + obj.automatic_label + "\n" + obj.type_name

else

  result = obj.schedule_number + "\n" + obj.automatic_label + " " + obj.type_name

end

 

 

Link to comment
Share on other sites

...and don't forget you can also use evaluated macros as methods:

 

macro_a = 3 ----> 3

macro_b = 7 ----> 7

 

macro_c = macros.macro_a + macros.macro_b ----> 10

 

instead of being limited to...

macro_d = "%macro_a%" + "macro_b%" ----> 37

or a non evaluated version of the same...

macro_e = %macro_a%%macro_b% ----> 37

 

  • Upvote 1
Link to comment
Share on other sites

  • 2 weeks later...

I've been wanting to automate my title block for years.  In addition to Joe's macro I added another that subtracts 1986 from the current year to give me a %years_open% value.

 

Thank you Joe for the answer and RGardner for asking the question!

 

Link to comment
Share on other sites

On 11/19/2019 at 5:35 PM, Joe_Carrick said:

Macro "year"

  • t = Time.new
  • result = t.year 

returns the current year  --> 2019 as a numerical value

  • result = result.to_s

returns a character string --> "2019"

 

This is pure Ruby and doesn't require anything else from Chief.

 

 

FWIW, the extra line is actually unnecessary. 

 

Time.new.year

or

Time.now.year

 

both work just fine as well. 

 

Link to comment
Share on other sites

15 minutes ago, Joe_Carrick said:

I think you meant "unnecessary".


Ya, that would make more sense wouldn’t it :)  Correction made.  Thank you.

 

15 minutes ago, Joe_Carrick said:

 

But of course if you want to perform calculations it makes it easier to understand if you assign the value to a variable.

 

Definitely.  Just throwing a side note out there is all.  

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