Running a .rb file in Chief


tlinder
 Share

Go to solution Solved by Alaskan_Son,

Recommended Posts

1 minute ago, tlinder said:

 

We have over 200 template files. If I placed them in every file and that macro changes, I would have to update every macro in every file manually. I'm trying to prevent re-entry.

So in each system just set the additional LOAD+PATH as a separate line in the Ruby dbx.  It's that simple.

Link to comment
Share on other sites

22 minutes ago, solver said:

 

Why?

 

Why do you want to do this rather than placing the same code in the plan file?

 

This has been pretty clear to me from the start...at least if my understanding is correct: 

 

The idea seems to be that macros can be defined and edited in a single source file so that any changes don't have to be made in every plan and on every computer.  I think its actually a really good approach for offices with lots of templates and/or lots of users.  In fact, using this approach, an office could drop one single macro into every template plan.  That macro would require/reference the same rb file.  Within that single file, a company could hypothetically create ALL their own custom macros as methods.  Modify the source file to include a new method and voila, that method/macro is available to every user and in every plan. Realize something needs to be tweaked?  Tweak the source file and every other instance gets tweaked accordingly. 

 

It makes solid sense to me. 

  • Like 1
Link to comment
Share on other sites

By the way, you don't have to change the load path at all.  The require method can take an entire file path as an argument as well.

 

OR, you could even optionally set your $LOAD_PATH with the same macro that requires your rb file that way no one even needs to change their preferences.  Any machine that opens the plan would get the load path set automatically.  

Link to comment
Share on other sites

On 7/26/2022 at 3:02 PM, Alaskan_Son said:
  1. Add your desired folder to the $LOAD_PATH OR place the desired file inside your currently defined $LOAD_PATH.  This way you can just use a file name instead of having to use the whole folder structure.
  2. Define a method inside your rb file
  3. Use require as Joe already mentioned instead of using File.read
  4. Call your defined method inside your Chief macro.

All said and done, it would look more like this (using your originally supplied example):

 

Macro: In CA

require 'scope1'

my_method

 

 

Output: from text stored on a local drive

def my_method

 

rafter_length = (length.to_f.round / 12) + 1

convert_to_int =  rafter_length.even?

case
  when convert_to_int == true
  resut = rafter_length

  when convert_to_int == false
  result = rafter_length +1
end

 

end

 

I finally got everything to work!!!

Thanks everyone all your help!

I was able to use Alaskan_Son's method.

I couldn't get Chief to evaluate the macros for the longest time, so after much thought, I decided to restart Chief and everything works as it should. 

Link to comment
Share on other sites

5 minutes ago, tlinder said:

I couldn't get Chief to evaluate the macros for the longest time, so after much thought, I decided to restart Chief and everything works as it should. 

 

Changes to many of your Preferences do not take affect till next time you start the program.  This is true not only of your Ruby settings but of other settings as well.

Link to comment
Share on other sites

I think it has something to do with one drive. When I went to my $LOAD_PATH on my local and right clicked on tutorial > properties > file path

I had a different file path than what was listed in chief for the $LOAD_PATH.

Link to comment
Share on other sites

10 minutes ago, tlinder said:

I think it has something to do with one drive. When I went to my $LOAD_PATH on my local and right clicked on tutorial > properties > file path

I had a different file path than what was listed in chief for the $LOAD_PATH.

 

That's because the tutorial is located in Chief's Program Files...a location you really shouldn't be playing around with.  Your $LOAD_PATH should point to a user folder (probably the folder it was already set to).  I would suggest you just forget everything you have read about using the tutorial file and set your $FILE_PATH back to the default "C:\Users\Whatever Path\Chief Architect Premier X14 Data\Scripts" folder and/or your desired Z drive folder.

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