Rescue Macros


Renerabbitt
 Share

Recommended Posts

I have a macro that I wrote to input job info with a rescue that could easily be wrong. Often times when I open the plan that has the macro, the job info is from a previous job...do I have to have a trigger to update the macro in the plan every time I go to modify it? Is there a way to write this macro so that the data never changes once input?- should I delete the rescue from the macro?

Link to comment
Share on other sites

Rene,

I'm going to assume that your macro is using a $Global variable.  If you have not closed Chief then the value is a holdover from the previous plan.  One solution is to clear the $Global

  • open the Ruby Console - you can leave it open since it's a non-modal dialog
  • type the $Global variable name and set it to nil ---- $MyGlobal = nil <enter>
  • press the F5 key twice to force the macros to execute.

The macro in your current plan will update the $Global variable

Link to comment
Share on other sites

Here's another way to deal with this sort of problem.  Add these lines to your macro:

 

#================================================

# Refresh if more than 2 seconds has elapsed

#================================================

if $MyGlobalRefreshTime.nil?

  $MyGlobalRefreshTime = Time.now

end

if Time.now > $MyGlobalRefreshTime + 2

  $MyGlobal = nil

  $MyGlobalRefreshTime = Time.now

end

 

Then whenever you hit the F5 key twice the macro will execute, setting the $Global to nil which will cause the macro you have to set it to do its job.

I use this little trick to update hashes when I make changes.

 

Link to comment
Share on other sites

MAcros....AHHHHHHH.....I can't for the life of me figure out to get mine right.

 

Why, at this stage of development, is this not a standard macro?

 

I have to do these manually when I need them because everything I have tried fails!

 

I WANT THIS STANDARD!!!!

 

Sorry, I now return you to your regularly scheduled topic.

 

door & window label.png

  • Upvote 2
Link to comment
Share on other sites

9 hours ago, Renerabbitt said:

I have a macro that I wrote to input job info with a rescue that could easily be wrong. Often times when I open the plan that has the macro, the job info is from a previous job...do I have to have a trigger to update the macro in the plan every time I go to modify it? Is there a way to write this macro so that the data never changes once input?- should I delete the rescue from the macro?

 

Just a guess here, but I'd bet that your problem is this...

 

You're using the job_info macro to set a bunch of global variables but that macro isn't actually getting executed anywhere onscreen.  What you probably need to do is place that macro somewhere onscreen so that it actually executes whenever you open your plan, and just make the last line "" so that it doesn't actually show up.  I usually place macros like this in the title line of an appropriate schedule or list.

 

...again, just a guess.

Link to comment
Share on other sites

10 hours ago, Alaskan_Son said:

...again, just a guess

I think this is what I needed, I'll take a try at it later and report back,per usual, you're the man!

 

18 hours ago, Joe_Carrick said:

#================================================

# Refresh if more than 2 seconds has elapsed

#================================================

if $MyGlobalRefreshTime.nil?

  $MyGlobalRefreshTime = Time.now

end

if Time.now > $MyGlobalRefreshTime + 2

  $MyGlobal = nil

  $MyGlobalRefreshTime = Time.now

end

Love this, I need to study more, I actually do not know how to write and implement macros without making them global.

Link to comment
Share on other sites

9 minutes ago, ACADuser said:

Could you also set a global var to the current file name and if the file name does not match the current file then reset the variables?

 

 

Good idea, but no.  Chief hasn't given us access to the current file name anywhere except in layout boxes where they've given us access to the referenced file.

Link to comment
Share on other sites

14 hours ago, Joe_Carrick said:

Joey,

Do you want the "X" or "x" ? 

Is rounding to the nearest inch also acceptable?

 

This is a pretty easy one for me and it can be placed in the default door and window labels.

 

Either is fine with me. I do them manually and there is a capital X, but I don't care either way.

Link to comment
Share on other sites

1 hour ago, Alaskan_Son said:

 

Good idea, but no.  Chief hasn't given us access to the current file name anywhere except in layout boxes where they've given us access to the referenced file.

So programing in the Chief version of Ruby is like boxing with one arm tied behind your back.

 

  • Like 2
  • Upvote 1
Link to comment
Share on other sites

22 hours ago, Alaskan_Son said:

 

Good idea, but no.  Chief hasn't given us access to the current file name anywhere except in layout boxes where they've given us access to the referenced file.

 

I was hoping they would use like $0 to get the current file name... but instead it reports pointless "embedded"

 

Here is the script to check for globals

result = ""

result += "RUBY VERSION " + RUBY_VERSION + "\n"

result += "RUBY Release: " + RUBY_RELEASE_DATE + "\n"

result += "RUBY Platform: " + RUBY_PLATFORM + "\n"

result += "Scripts folder " + ($:).to_s + "\n"

result += "Loaded Features " + ($LOADED_FEATURES).to_s + "\n"

result += "Default Output " + ($>).to_s + "\n"

result += "Environment:\n" + ( ENV).to_s + "\n===== End of Environment\n"

global_variables.each { |gv| result += "#{gv}: #{eval(gv.to_s)}" }

result

Link to comment
Share on other sites

I like this one much better:

 

#=================================================

# Joe's Macro Service

# Ruby script: _global Variable Values

# Copyright September 22,2019

#=================================================

 

#=================================================

# This macro lists all the $Global variables and their current values

#=================================================

referenced ? obj = referenced : obj = owner

 

if obj.respond_to? "object_type" and obj.object_type.to_s.upcase.include? "TEXT"

  result = ""

else

  arr = Kernel.global_variables.sort

  i = 0

  j = arr.length - 1

  result = ""

  while i < j

    x = arr.id2name

    y = eval(x)

    result = result + x + "\t = " + y.to_s + "\n"

    i = i+1

  end

end

result

 

 

 

  • Upvote 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