Ruby - Formatting TOL 1


Recommended Posts

Thanks Eric 

 

Perhaps Try tagging Ben Merritt or Natalie Plagman, both are with Chief and Posted to this Thread .......also see JoeC's and Michael's posts near the bottom.

 

M.

 

 

Link to post
Share on other sites

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Content removed and will continue at the thread mentioned above by Mick

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 

 

Link to post
Share on other sites
8 minutes ago, ACADuser said:

I've been messing around with this but the catch it seems is the Number Formatter must be activated before the macros will work.

Chief has no wake up setting for this formatter.

So you must click on something that will activate the formatter.

Attached file is X13

 

 

 

Thanks for Sharing, check the Thread I linked above , I think if you make the NF a Global Variable ie $NF  it may work better ?

( see JoeC's example in thread above.)             ..............................You may need to give each NF a number too so it is unique.

 

Mick.

 

Link to post
Share on other sites

Yes I have read the other thread & thought the nf = NumberFormatter.new  would be a local instance for that routine only & released when the routine finished.

It works fine if the NumberFormatter is activated one time but that means you must click & open the text box.

After that it works fine. 

As Eric points out in the other thread he had to create a polyline with the activation in the label before creating any other objects using the number formatter.. All others macros after that worked fine.

 

So my conclusion is that you must find a way to wake the formatter up when the plan is opened.

 

 

 

Link to post
Share on other sites

PS once the formatter is activated my code works fine.

But when you close Chief & restart Chief the plan opens and none of the macros work until you open one, they then all work.

Maybe I said that already. :)

 

Link to post
Share on other sites

Hi Alan , sorry had to go out earlier and I was in a bit of a rush, I am no expert on Marcos but reading your Code I see you are creating Functions (def)

So you could likely Load them every time Chief runs by creating Ruby Scripts (.rb) and putting them in the Scripts Folder then in Marcos Call the Function with 

 

require  xxxxxx.rb

 

Best to ask Eric or Joe though about that and integrating the NumberFormatter.

 

@solver

@Joe_Carrick  

Link to post
Share on other sites
20 hours ago, ACADuser said:

PS once the formatter is activated my code works fine.

But when you close Chief & restart Chief the plan opens and none of the macros work until you open one, they then all work.

Maybe I said that already. :)

 

 

If you're trying to use any kind of global variable, constant, user defined method, or anything else that gets stored in global memory in Chief, then you absolutely need to make sure the defining code is executed before you can use the results.  There are a number of ways you can execute the code including:

  • Simply opening and closing a text box or just about any dialog with a label
  • Simply opening and closing Text Macro Management
  • Manually executing the code using the Ruby console
  • Placing the defining code somewhere in your view (code gets executed during screen re-draw)

The first 3 require deliberate user involvement after a plan has been opened .  The latter approach ensures that no user involvement is necessary and there are a number of ways to do it.  You can even go so far as to define your own classes and methods so that your macro itself both executes the required code and takes arguments. 

Link to post
Share on other sites

Thanks Michael,

I wanted the routines to work/update when the plan is opened.

 

This my current macro routines saved in the plan (see blow):

They do not run from within a marker or text box etc. until one is opened.

Then they ALL update. I assume the NumberFormatter is then activated.

I added this line to the end of tutorial.rb file in an attempt to activate the Number Formatter, no joy.   $NF = NumberFormatter.new

I was looking at loading these routines via the tutorial.rb file but do not know the code to initiate the load.

Would loading my rb file cause the text box & marker to update without user actions?

 

I'm doing some early prep for the Tropical Storm as I live just east of Tampa so I,m in and out this afternoon.

 

 

# New 07/05/2021
# ACadUser version of the number formatter routines

 $NF = NumberFormatter.new  # reset Number Formatter to default values and use $NF global pointer to the new formatter


# macro to return decimal feet
#     Set the macro to [ Evaluate]  and  Context to [None]
def ft_d(n) # name the function to be called by you to "ft_d"
  nf = NumberFormatter.new  # nf becomes a pointer to the formatter, the new resets to default values
  nf.unit = :"ft" # set units to feet
  nf.show_trailing_zeros = true
  nf.decimal_places = 3
  nf.apply(n)    #  pass the n variable to the Number Formatter
end


#     Macro to return feet and inches
#     Set the macro to [ Evaluate]  and  Context to [None]
def ft_in(n)
  nf = NumberFormatter.new  # nf becomes a pointer to the formatter, the new resets to default values
  nf.unit = :"\'-\"" # set units to feet and inches
  nf.show_trailing_zeros = true
  nf.use_fractions = true  # turn on fractions
  nf.apply(n)    #  pass the n variable to the Number Formatter
end

 

#     Macro to return feet and decimal inches
#     Set the macro to [ Evaluate]  and  Context to [None]
def ft_din(n)  # Feet & Decimal inches
  nf = NumberFormatter.new  # nf becomes a pointer to the formatter, the new resets to default values
  nf.unit = :"\'-\"" # set units to feet and inches
  nf.show_trailing_zeros = true
  nf.decimal_places = 3  # set number of decimal places
  nf.use_fractions=false  # turn off fractions
  nf.apply(n)    #  pass the n variable to the Number Formatter
end

 

Link to post
Share on other sites
10 minutes ago, ACADuser said:

I added this line to the end of tutorial.rb file in an attempt to activate the Number Formatter, no joy.   $NF = NumberFormatter.new

 

 

To be clear, all the user ruby code can go directly into the tutorial.rb file.

 

I've just chosen to do it as shown in the video.

 

 

 

Link to post
Share on other sites

OMG that seems to work :)

 

require ("NFroutines")

 

File attached

 

It runs when the plan is opened and the text boxes update.

 

I put this in a polyline  box label within a 2nd floor room

 

Room Floor Elevation

%room.elevation.floor% [ Inches]

%ft_d(room.floor_elevation)% [Decimal Feet]

%ft_in(room.floor_elevation)% [Feet & Inches]

%ft_din(room.floor_elevation)% [Feet & Decimal Inches]

 

Thanks Eric.

NFroutines.rb Number Formatter AcadUser.plan

Link to post
Share on other sites
17 minutes ago, ACADuser said:

OMG that seems to work :)

 

require ("NFroutines")

 

File attached

 

It runs when the plan is opened and the text boxes update.

 

I put this in a polyline  box label within a 2nd floor room

 

Room Floor Elevation

%room.elevation.floor% [ Inches]

%ft_d(room.floor_elevation)% [Decimal Feet]

%ft_in(room.floor_elevation)% [Feet & Inches]

%ft_din(room.floor_elevation)% [Feet & Decimal Inches]

 

Thanks Eric.

NFroutines.rb 1.57 kB · 0 downloads Number Formatter AcadUser.plan 3.49 MB · 0 downloads

 

Oh great , I thought the Script may work in this case , thanks for sharing the Final result

 

and thanks to Eric , for helping out once again....

 

Mick.

Link to post
Share on other sites

FWIW,

 

With each new version of Chief you will need to copy the .rb file to the Scripts folder for that version.  I learned a long time ago that failure to do so would make a legacy plans brought forward to a new version potentially fail.

 

This is why I simply have the macros in my default plan files and initialize them within a common object's label.  That ensures they are always available with each plan regardless of the Chief version.  I actually check in each macro to see if the $Global exists or not:

 

if $NF_xx.nil?

  #create $NF_xx

  ......

  ......

end

""

Link to post
Share on other sites
1 minute ago, Joe_Carrick said:

With each new version of Chief you will need to copy the .rb file to the Scripts folder for that version.

 

That .rb file can go anywhere. You can specify where to look in the require, or add a path to the $LOAD_PATH variable in Preferences, which I assume transfers with an upgrade.

 

ct1.thumb.png.e7ce6fa7c8f0ea8e4e9786abcba95918.png

Link to post
Share on other sites
12 minutes ago, Joe_Carrick said:

With each new version of Chief you will need to copy the .rb file to the Scripts folder for that version.

 

Is the Scripts Folder not migrated along with Templates, textures etc?   

 

Maybe I copy it over myself without thinking? not sure but what few Scripts I have are in the X13 Scripts Folder

 

M.

Link to post
Share on other sites
57 minutes ago, Kbird1 said:

 

Is the Scripts Folder not migrated along with Templates, textures etc? 

I'm not sure.  I do know that back in some prior versions it wasn't.  Maybe it is now but I wouldn't count on it.

Link to post
Share on other sites
6 minutes ago, Joe_Carrick said:

I'm not sure.  I do know that back in some prior versions it wasn't.  Maybe it is now but I wouldn't count on it.

 

Thanks for the heads up Joe, I will keep an eye on it in the future as I don't remember copying it over myself but have been playing with X13 a while now.

 

M.

Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Member Statistics

    29842
    Total Members
    9156
    Most Online
    jcobbinhi
    Newest Member
    jcobbinhi
    Joined