Running a .rb file in Chief


tlinder
 Share

Go to solution Solved by Alaskan_Son,

Recommended Posts

There's no good reason to be placing code into the tutorial.rb file in my opinion.  Its just a messy and confusing kludge.  All you're actually doing by placing code in the tutorial file is bypassing the require line because Chief is pre-programmed to automatically load that tutorial.rb file.  You can easily replace the functionality by just using require in a text macro of your own though so you don't have to fool around with defining your methods in the tutorial file. 

 

Just create and display that macro somewhere in your template plan and all the methods defined inside your appropriately required rb files will be loaded into global memory just as if you had placed them in the tutorial file. Or require the desired rb file(s) inside specific macros.  Either way, just load them yourself (using require) instead of using the tutorial file workaround.

Link to comment
Share on other sites

5 hours ago, jasonn1234 said:

Although tutorial.rb is distributed by CA so it will be overwritten on installation, probably ok for testing but not long term

Yep, every time there's an update or new version.  That's why it's not a good idea.

Link to comment
Share on other sites

Thank you for the YouTube video Eric.

 

Is there a way to define a new $LOAD_PATH to a different drive. I ask this because, I'm not the only one that is going to be opening these files.

To my knowledge they all need to be "required" from the same file path. 

Link to comment
Share on other sites

3 hours ago, tlinder said:

Is there a way to define a new $LOAD_PATH to a different drive.

 

$LOAD_PATH is one or more paths that the program will search when looking for a file.

 

See my image upthread showing multiple paths.

 

--------

 

I still do not understand what you are trying to accomplish -- big picture, not how to run ruby from outside a Chief file. If you could explain, you would probably get better help.

Link to comment
Share on other sites

54 minutes ago, solver said:

I still do not understand what you are trying to accomplish -- big picture, not how to run ruby from outside a Chief file. If you could explain, you would probably get better help.

 

My overall goal is to create a macro in Chief to require a .rb file that is stored from a folder on a shared drive. I don't want to put it in my scripts folder that is connected to Chief because that drive (C: drive) is not shared. Instead IT is creating a new drive (Z: drive) for us, so everyone will have the same file path. There are many computers that will be opening the files in Chief.

 

I need to be specific with my file path and it needs to point to the Z: drive

 

I hope this helps.

 

For ex:

C: drive

- not shared

- where Chief is currently installed

 

Z: drive - IT created

- shared

- this is where I want to store my scope1.rb

- same file paths on every computer

 

Link to comment
Share on other sites

16 minutes ago, tlinder said:

My overall goal is to create a macro in Chief to require a .rb file that is stored from a folder on a shared drive.

 

Why?

 

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

Link to comment
Share on other sites

21 minutes ago, solver said:

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

 

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.

Link to comment
Share on other sites

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

  • Member Statistics

    32329
    Total Members
    9156
    Most Online
    DasDesign
    Newest Member
    DasDesign
    Joined
  • Similar Content

    • By Allen43
      I'll new to Chief and have learned that this form might be one of the best resources I have ever used. I am trying to streamline my design process and to do that I would love to be able to change cabinet ends to finished or paneled faster and easier. I tried to make a SP to do this, but I couldn't figure it out. I also thought that there might be a way to do this with macros is a SP, but I know even less about macros than I do Chief.
       
      Any help is appreciated, and if it's not possible that's fine I'll know not to spend more time on this.
    • By wazzubrad
      Guys, I am starting to find some of the limitations that I see discussed in the forums and am wondering if this is one of those. The current plan I am working on has various footing widths and depths specified by the engineer for the foundation walls. While trying to create a wall schedule that will show each wall based on footing width and depth and when I look at the available macro's under Object Properties for a macro I don't see anything specific to the footing depth. Anyone know if this property exists for a foundation wall?
       

    • By Renerabbitt
      Do you have 10+ years in the software and wonder if you've been missing some tips and tricks? Have you been able to break the 15 hour condoc set?
      Maybe you are a proficient user that wants to know everything that there is to know in Chief.
      Rendering, Automation, Resources, Symbols, Quick Tools, Style Pallets, PDF Tools, Templates, and more.

      We believe in lifting the community up. All of our tools and resources are available to you. With training that can be personal, team oriented, prerecorded, livestreamed, interactive. We offer training in over 15 softwares from Drafting and Detailing to Modeling, Advanced Texturing, Procedural Workflows, Node Based Design, Macro Creations, DAMs, Automation, VR Workflows, Streaming Overlays and Masks and much much more. Tell us your needs and we will connect you with the package or the right resource.

      Some example learning modules:
      Concentric Jump your dimension strings
      Enter-input your jumps and Enter-close your DBX's
      Snap jump your door widths, concentric jump your windows
      Alt behavior tips, contain-selection and deselection workflows with tool restrictions. 
      Tons of cabinet tools and tips, including custom one-off parametrically modelled vanities and more.
      Custom Toolbar Icons and Custom Library Objects.
      Toolbar Switching Tricks and Library workflows


       
      Other Offer Services Posts:
       
    • By DRyeHD
      I have a total of 14 possible layout pages I use.  I have my layout pages defined using the # sign.  On my "0" layout page I use %page.print% for the page number and %numpages% to get the total number of pages.  I don't always use all 14 pages but would rather not delete them from the client layout file in case they decide they want additional pages later.  So, as it is, even if I just need six pages the number 14 displays (see attachment).  Is there a way to get that macro to reflect the number of pages used in my layout schedule or the number of actual pages that I will print?  Also, is there an easier way to select which pages display in the layout table than opening each layout page and editing each one's layout page information (like a list of layout pages you could pull up and select/deselect the two checkboxes on this DBX?

    • By buzzsaw204
      hi all,
      i have a Library of Ruby macro that was custom coded for me few years back.
      some the task/script is not working anymore cuz of the X12 upgrade.
      i would like have this Library upgraded and refresh the Code to the X12 version. and get it working again.
       
      the Library was very well and beautifully coded by another guru/ruby master.
      But unfortunately, iam unable reach the original programmer to redo this project.
       
      im looking for someone that could help and take over and upgrade this Library.
       
      Please contact me.