Ruby objects


TimSchrock
 Share

Recommended Posts

I'm back at it again...Ideas for Ruby macros.

I want to use the Layout client info to enter my title block information (I've got that set up) and then since I have the state entered as the two-letter abbreviation, I figure the general notes could recognize that data and spell out the state's name ("PROJECT TO BE BUILT ACCORDING TO THE BUILDING CODE OF THE STATE OF xxx"). 
I'm struggling trying to find the object to reference for %client.state%. If I do NOT evaluate, I can enter %client.state% and return the same IN but cannot perform any functions on it.

When I change the macro to evaluated and "Referenced Object" I can enter "%client.state%" (with quotes) and return IN. But then I want to pass that to a hash to show INDIANA so I set up my hash array and pass states["%client.state"] only to get evaluation error. 

Here is my hash setup currently...

 

states = {

"IN" => "Indiana",

"VA" => "Virginia",

"MD" => "Maryland",

"MA" => "Massachusetts",

"DC" => "District of Columbia"

}

states["IN"] will see Indiana 

states[%client.state%] will see evaluation error

states["%client.state%"] will see evaluation error

 

Is there a place that I can find the objects or hooks that a file has and what class the instances will return? I'm assuming the %client.state% will return a string, but it almost doesn't act that way since I have to put quotes around %client.state% in the macro just to pass the info to the text box. 

 

Edited by TimSchrock
Added for clarity.
Link to comment
Share on other sites

Tim,

 

You have to mentally separate Text Macros (simple string replacement) and Ruby (a programming language) .  They are 2 entirely different things.  Chief has Text Macros, and as an option, Chief allows us to use Ruby as a programming language inside those Text Macros.  In X12, Chief added the ability to enter Ruby Code directly into various data entry fields.  

Link to comment
Share on other sites

Copied and pasted from something I posted a while back...

 

I tell it like this:  People have to look at Chief and Ruby as 2 entirely separate constructs/entities.  Whenever CHIEF sees two % signs enclosing some text, it will display any appropriate automated text.  If that text happens to match a user defined, evaluated text macro then Chief will defer to RUBY to run the code.  RUBY has no clue what anything between percentage signs means though.  Only Chief knows that.  When CHIEF “sees” the percentage signs on screen, Chief either fills it in per the defined macro, leaves it as dumb text, or defers to RUBY.  The only thing Ruby can and ever will do with the text wrapped in % signs is display it as a “%name%” string or error out.  

 

My favorite example is to write a custom evaluated macro with a value of “%layer%” into an object.  You should see the result is what you might expect...it reports the layer of the object.  Now modify the macro to “%layer%”.reverse and see what you get.  In both cases, RUBY is doing nothing more than placing the dumb text on the screen.  CHIEF is the one that replaces the text with something else when the resulting on screen text results in either a defined macro (either internal or user defined) or (starting in X12) when Chief recognizes valid Ruby code.  

 

The above is the fundamental reason we cannot access those built in macro values using Ruby.  It's because Chief is the one producing that output.  Ruby has no access to it.  Yes, Chief chooses to allow some things to route through Ruby, but not every macro in Chief is handled like that. 

Link to comment
Share on other sites

@Alaskan_Son, I was following your global variable thought from a previous post, and I have a question re: global variables. I found if I set the variable %$Client_Name = "Bill & Nancy"% then that variable is set across any and ALL files that I have open, until I set the variable again within a specific file. Otherwise, the a textbox with the variable %$Client_Name% will just reflect the set value of the last file I looked at. Correct?

Link to comment
Share on other sites

1 hour ago, TimSchrock said:

I guess this is why the "Global Variables" disappears when I check the "evaluate" box? They're just not accessible.

You're right that they're inaccessible, but you're really thinking about it all wrong.  Don't think of it as accessible vs. inaccessible.  Just realize that those "global" Text Macros are Chief things, not Ruby things.  Ruby has no clue what %blahbahblah% means.  It's gibberish.   %blahblahblah% is pure Chief. 

  • Like 1
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