rgardner Posted November 19, 2019 Share Posted November 19, 2019 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 More sharing options...
Chopsaw Posted November 20, 2019 Share Posted November 20, 2019 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 1 Link to comment Share on other sites More sharing options...
rgardner Posted November 20, 2019 Author Share Posted November 20, 2019 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! Link to comment Share on other sites More sharing options...
Joe_Carrick Posted November 20, 2019 Share Posted November 20, 2019 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. 1 Link to comment Share on other sites More sharing options...
rgardner Posted November 20, 2019 Author Share Posted November 20, 2019 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 More sharing options...
Chopsaw Posted November 20, 2019 Share Posted November 20, 2019 Just as Joe posted in the simplest form. 1 Link to comment Share on other sites More sharing options...
Chopsaw Posted November 20, 2019 Share Posted November 20, 2019 Using .strftime allows for multiple predefined configurations. https://ruby-doc.org/stdlib-2.6.1/libdoc/date/rdoc/DateTime.html#method-i-strftime Link to comment Share on other sites More sharing options...
rgardner Posted November 20, 2019 Author Share Posted November 20, 2019 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. Link to comment Share on other sites More sharing options...
Joe_Carrick Posted November 20, 2019 Share Posted November 20, 2019 Referenced doesn't need to be. None will work fine, but it does need to be Evaluated. Link to comment Share on other sites More sharing options...
rgardner Posted November 20, 2019 Author Share Posted November 20, 2019 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! Link to comment Share on other sites More sharing options...
Joe_Carrick Posted November 20, 2019 Share Posted November 20, 2019 "Evaluated" simply means that the macro should be considered a "program" rather than just "text". Link to comment Share on other sites More sharing options...
BrownTiger Posted November 21, 2019 Share Posted November 21, 2019 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 More sharing options...
Alaskan_Son Posted November 21, 2019 Share Posted November 21, 2019 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 More sharing options...
Joe_Carrick Posted November 21, 2019 Share Posted November 21, 2019 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 More sharing options...
Alaskan_Son Posted November 21, 2019 Share Posted November 21, 2019 ...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 1 Link to comment Share on other sites More sharing options...
Joe_Carrick Posted November 21, 2019 Share Posted November 21, 2019 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. Link to comment Share on other sites More sharing options...
BrownTiger Posted November 21, 2019 Share Posted November 21, 2019 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. Link to comment Share on other sites More sharing options...
Alaskan_Son Posted November 21, 2019 Share Posted November 21, 2019 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. Link to comment Share on other sites More sharing options...
JiAngelo Posted December 1, 2019 Share Posted December 1, 2019 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 More sharing options...
Alaskan_Son Posted December 2, 2019 Share Posted December 2, 2019 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 More sharing options...
Joe_Carrick Posted December 2, 2019 Share Posted December 2, 2019 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. Link to comment Share on other sites More sharing options...
Alaskan_Son Posted December 2, 2019 Share Posted December 2, 2019 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 More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now