tlinder

Members
  • Posts

    19
  • Joined

  • Last visited

Posts posted by tlinder

  1. 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. 

  2. 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.

  3. 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

     

  4. 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. 

  5. 2 minutes ago, solver said:

     

    What did you get?

    Evaluation Error: Ruby SecurityError: Insecure operation - require

    Stack Trace:

    from (eval):2:in `block (3 levels) in <main>'

    from (eval):1:in `instance_eval'

    from (eval):1:in `block (2 levels) in <main>'

    from eval:9:in `eval'

    from eval:9:in `block (2 levels) in <main>'

    from eval:3:in `loop'

    from eval:3:in `block in <main>'

  6. 5 minutes ago, Alaskan_Son said:

     

    Did you set the macro to Evaluated:Owner?  And did you move your script to a folder in the $LOAD_PATH or adjust the $LOAD_PATH to add your desired folder?

    Are you saying to create a folder and name it $LOAD_PATH? I'm not sure what you mean.

  7.  

    14 minutes ago, Joe_Carrick said:

    Macro: In CA

    require 'scope1'

    my_method(length)

     

     

    Output: from text stored on a local drive

    def my_method(x)

     

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

       convert_to_int =  rafter_length.even?

       case
          when convert_to_int == true
            result = rafter_length

          when convert_to_int == false
            result = rafter_length +1
        end

     

    end

    Joe and Michael

    I tried both of those approaches and I wasn't able to get the right output in Chief.

  8. 3 hours ago, solver said:

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

    rafter_length.even? ? rafter_length : rafter_length + 1

    Thank you for the easier format and the YouTube videos. You gained yourself a new subscriber!

     

    Quote

    Are you looking for standard lumber lengths?

    Yes I'm just trying to have the standard lumber lengths populate in the rafter labels.

  9. 1 hour ago, jasonn1234 said:

    wouldn't you have to open every file anyway to actually use the new functions you wish to define in the .rb file?

    Initially yes, but for future updates I can just change the macro on the .rb file and it automatically updates the file when they are opened. 

  10. Quote

    Here's a sample rb file that has a series of defined methods.  Note that I no longer use this since it's problematical to update with each new version of chief.

    Thank you Joe I will do some more research I this. I appreciate all your help!

  11. 3 minutes ago, Joe_Carrick said:

    You should just make this an evaluated macro in chief, context: owner

     

     

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

    convert_to_int =  rafter_length.even?

    case
      when convert_to_int == true
      result = rafter_length

      when convert_to_int == false
      result = rafter_length +1
    end

     

    Using an rb in this case is superfluous.  IAE, to use one you would need to "require" it in your chief macro and then call the "defined" function within that rb file.

    Thanks Joe

    The macro works in evaluated, just trying to take it one step further and save the company a lot of time.

    I'm am trying to read it from my local so I don't have to open every CA file and update them 1 by 1. We have hundreds of files.

  12. I'm trying to run a .rb file that's on my local in CA by using a marco. Right now I can only get it to read the file. Does anyone have any insight on how I might be able to to this or where I need to look?

     

    Macro: In CA

    File.read("C:/Users - Desktop/scope1.rb")

     

     

    Output: from text stored on a local drive

    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

     

    image.thumb.png.cead1fc53c54f9b5db1e2d8aa77354ed.png

     

  13. On 6/24/2022 at 7:07 PM, Alaskan_Son said:

     

     

     

    Now if you ask me: I would suggest an entirely different approach that completely bypasses Text Macro Management.

    • In your polyline object use something like %$my_box = area%
    • In your text box use either %$my_box.round(2).to_s%  or  %$my_box.to_f.round(2)% SQ. FT.

     

    Thank you so much for your help!

    • Like 1
  14. 1 hour ago, solver said:

     

    To be more clear, there is no "polyline schedule". You may use a Custom Schedule to report polylines, and the polylines you want in the schedule need to have Include in Schedule checked.

    I have not tried that route. Thank you for suggesting it. 

  15. 2 hours ago, solver said:

    Do you understand the macro -- the syntax of each line and what it's supposed to do?

     

    There are at least 2 people here on the forum that sell packages to do this.

    Thank you for you quick reply. I am new to Ruby. All this language is still new to me.

  16. I'm trying to create a macro that will calculate the area in polylines and show it in a separate text box. This is needed to calculate sod, concrete, sidewalk ect.

    I found a macro that I have been trying to manipulate to do this. Attached is a simple file that a have been experimenting with to achieve my desired results.

     

    This is the script:

     

    $_2ExistingBoxSQFT = area rescue $_2ExistingBoxSQFT

     

    if $_2ExistingBoxSQFT == 0

    na = "N/A"

    "#{na}"

    else

    "#{$_2ExistingBoxSQFT.round(2)} SQ. FT."

    end

     

    This is the evaluation error it is giving me:

     

    Evaluation Error: Ruby NoMethodError: undefined method `round' for nil:NilClass

    Stack Trace:

    from (eval):1:in `instance_eval'

    from (eval):1:in `block (2 levels) in <main>'

    from eval:9:in `eval'

    from eval:9:in `block (2 levels) in <main>'

    from eval:3:in `loop'

    from eval:3:in `block in <main>'

     

    Macro Test.plan