rgardner

Simple year macro

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! :)

Share this post


Link to post
Share on other sites

There are a lot of macro's that really should be a part of the software...   Maybe some day.

 

Give this a try: 

 

Copyright Year.json

  • Upvote 1

Share this post


Link to post
Share on other sites
Just now, Chopsaw said:

There are a lot of macro's that really should be a part of the software...   Maybe some day.

 

Give this a try: 

 

Copyright Year.json

Thanks! 

Share this post


Link to post
Share on other sites

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.

 

  • Upvote 1

Share this post


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

 

Share this post


Link to post
Share on other sites

Just as Joe posted in the simplest form.

 

year.JPG

  • Upvote 1

Share this post


Link to post
Share on other sites

AWW I was missing the Evaluate - The referenced object part...  

 

THANK YOU BOTH!

 

I was thinking since it wasn't for a specific physical object that didn't need to be selected.  

Share this post


Link to post
Share on other sites

Referenced doesn't need to be.  None will work fine, but it does need to be Evaluated.

Share this post


Link to post
Share on other sites
1 hour ago, Joe_Carrick said:

Referenced doesn't need to be.  None will work fine, but it does need to be Evaluated.

Thanks for the clarification.  You are a rockstar!

Share this post


Link to post
Share on other sites

"Evaluated" simply means that the macro should be considered a "program" rather than just "text".  

Share this post


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

 

 

Share this post


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

Share this post


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

 

 

Share this post


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

Share this post


Link to post
Share on other sites
14 minutes ago, Alaskan_Son said:

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

 

macro_a = 3 ----> 3

macro_b = 7 ----> 7

 

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

 

That's a cool method - I just wish any of these would work in the Ruby Console. ;)

Share this post


Link to post
Share on other sites

Cool I did not realized there was a "macros" object. Very cool.

I bet Ruby engine set to replace %object_properties% with macros.object_properties when it executes.  

Share this post


Link to post
Share on other sites
13 minutes ago, BrownTiger said:

Cool I did not realized there was a "macros" object. Very cool.

I bet Ruby engine set to replace %object_properties% with macros.object_properties when it executes.  


Not sure what you are trying to say.

Share this post


Link to post
Share on other sites

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!

 

Share this post


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

 

Share this post


Link to post
Share on other sites
2 hours ago, Alaskan_Son said:

FWIW, the extra line is actually necessary. 

I think you meant "unnecessary".

 

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

Share this post


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

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

  • Member Statistics

    27486
    Total Members
    6254
    Most Online
    Camian
    Newest Member
    Camian
    Joined