lavorhaynie

Ruby Macros

Recommended Posts

Anyone out there offer Ruby services for $?  I need a fairly simple macro created.

I need a label for my layout files that will display the path of the layout file (%file%), truncating the first nn characters.

i.e.  d:\Users\username\DesignWork\CAX11\Builders\Builder_1\Standard_Plans\Plan_1

       with nn=43 would display as:

       Builder_1\Standard_Plans\Plan_1

 

-or-

 

Can this be done in X11 without writing a macro?

 

Thanks much!

Share this post


Link to post
Share on other sites
On 10/9/2019 at 2:58 PM, lavorhaynie said:

Can this be done in X11 without writing a macro?

No, but it's fairly simple to do. 

There are 2 Ruby Attributes of a Layout Box that can be used:

  • referenced_full_filename  -  same as %file%
  • referenced _filename  -  just the name of the file that was sent to layout.

It would actually be better to know what set of letters you want to eliminate rather than a specific number of characters.

For example:

  • d:\Users\username\DesignWork\CAX11\Builders\

where you provide the actual username.

Share this post


Link to post
Share on other sites

Try this as a custom macro placed in the Layout Box Label:

 

nlen = referenced_full_filename.length-1

referenced_full_filename[43,nlen].gsub(".plan","")

 

  • Like 1

Share this post


Link to post
Share on other sites

Note:  %file% displays the name of the Layout File, not the Plan file the Layout Box came from.

IAE. It's not possible to manipulate the Chief standard Global and Object macros from within a user macro because the underlying data is basically not directly available.

Share this post


Link to post
Share on other sites
10 hours ago, Joe_Carrick said:

It would actually be better to know what set of letters you want to eliminate rather than a specific number of characters.

 

How would that look Joe if you just wanted to hide the directory and /Users/Username/ and maybe a file or two ?

 

Or are you wanting the exact characters ?

Share this post


Link to post
Share on other sites

@Alaskan_Son contacted me and wrote a macro that pulls the path string I need.  Did a great job at a very reasonable price. Thank you @Alaskan_Son!

 

Joe, I set up your suggestion and found that it works well too.  I do have a question for you, or anyone that might know the answer... how do you get the Ruby Attributes of a Layout Box that can be used?

 

Actual path (filename not included):

C:\Users\zbook17g3\OneDrive\_Business\DesignsByLaVor\_WorkX11\_Builders\CH - Compass\Clients\Working\Hancock - Hardin

Your suggestion from above:

                                                                                                                                CH - Compass/Clients/Working/Hancock - Hardin/Hardin

I would like to have:

                                                                                                                                CH - Compass/Clients/Working/Hancock - Hardin

 

Thanks!

Share this post


Link to post
Share on other sites

I have a macro that will show (in the Ruby Console) all the attributes for any selected object.

Here's the list for a typical Layout Box:

 

automatic_label ------------ "Graph Schedule Section/Elevation" ------------------------------------------------------------------------------------ String

box_scale ------------------ "1/4 in = 1 ft" ------------------------------------------------------------------------------------------------------- String

drawing_group -------------- 1 --------------------------------------------------------------------------------------------------------------------- Integer

floor_number --------------- 1 --------------------------------------------------------------------------------------------------------------------- Integer

height --------------------- 5.390048486681028 ----------------------------------------------------------------------------------------------------- Float

layer ---------------------- arch-d_layout_box_borders --------------------------------------------------------------------------------------------- Symbol

layer_line_color ----------- 255 ------------------------------------------------------------------------------------------------------------------- Integer

layer_line_style ----------- 0 --------------------------------------------------------------------------------------------------------------------- Integer

layer_line_weight ---------- 1 --------------------------------------------------------------------------------------------------------------------- Integer

layer_set ------------------ "Arch-D Print" -------------------------------------------------------------------------------------------------------- String

layer_text_style ----------- "HIDDEN" -------------------------------------------------------------------------------------------------------------- String

line_style ----------------- solid ----------------------------------------------------------------------------------------------------------------- Symbol

line_weight ---------------- 1 --------------------------------------------------------------------------------------------------------------------- Integer

object_type ---------------- layout_box ------------------------------------------------------------------------------------------------------------ Symbol

referenced_filename -------- "Jason Bales Residence - Phase 1" ------------------------------------------------------------------------------------- String

referenced_full_filename --- "D:/Dropbox/Chief Architect Projects/X11/Jason Bales Residence - Phase 1/Plan/Jason Bales Residence - Phase 1.plan" --- String

referenced_layer_set ------- "All On Set" ---------------------------------------------------------------------------------------------------------- String

width ---------------------- 3.6485143922610597 ---------------------------------------------------------------------------------------------------- Float

 

Share this post


Link to post
Share on other sites
41 minutes ago, lavorhaynie said:

would like to have:

                                                                                                                                CH - Compass/Clients/Working/Hancock - Hardin

 

nstart = 43

nlast = referenced_full_filename.length-1

result = referenced_full_filename[nstart,nlast]

result = result.gsub(".plan","")

result = result.gsub("/Hardin","")

 

explanation:

  line 3 sets the result to the characters starting at the 43rd character and ending at the last character

  line 4 strips all instances of ".plan" from the result

  line 5 strips all instances of "/Hardin" from the result

 

 

Share this post


Link to post
Share on other sites
3 hours ago, Chopsaw said:

Or are you wanting the exact characters ?

 

The actual characters would be required

  - or the number of "/" characters

  - or maybe if you just want to eliminate everything after the last "/".

 

There are several possibilities.  The macro can become more complex - actually just longer - depending on what rules you want to follow.

 

Ruby is mostly about manipulating data and performing calculations.  This case is basic manipulation of a text string - which is very much just an array of characters. 

Share this post


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

The actual characters would be required

  - or the number of "/" characters

  - or maybe if you just want to eliminate everything after the last "/".

 

There are several possibilities.  The macro can become more complex - actually just longer - depending on what rules you want to follow.

 

I was just looking at the macro you just wrote for LaVor and realized that it will only work for one particular file.

 

Is there a way to take his example of :

 

C:\Users\zbook17g3\OneDrive\_Business\DesignsByLaVor\_WorkX11\_Builders\CH - Compass\Clients\Working\Hancock - Hardin\Hardin.plan

 

 

Then write a macro that effectively eliminates everything before the 8th instance of "\" and after the 12th instance.

 

Producing the result of :

 

CH - Compass\Clients\Working\Hancock - Hardin

 

 

Then this would work for every project unless there was a change in the structure of the file path and then the macro could easily be rewritten or copied and edited ?

 

 

Share this post


Link to post
Share on other sites
2 minutes ago, Chopsaw said:

 

I was just looking at the macro you just wrote for LaVor and realized that it will only work for one particular file.

 

Is there a way to take his example of :

 

C:\Users\zbook17g3\OneDrive\_Business\DesignsByLaVor\_WorkX11\_Builders\CH - Compass\Clients\Working\Hancock - Hardin\Hardin.plan

 

 

Then write a macro that effectively eliminates everything before the 8th instance of "\" and after the 12th instance.

 

Producing the result of :

 

CH - Compass\Clients\Working\Hancock - Hardin

 

 

Then this would work for every project unless there was a change in the structure of the file path and then the macro could easily be rewritten or copied and edited ?

 

 

Yes.  That’s essentially the method I utilized.  In a nutshell, my method for this particular use case was to first convert the file path to a string, then to break that string up into an array of values to represent drive, directory, subdirectories, and file, and then to display only the first 3 of the last 4 values in the array.  

Share this post


Link to post
Share on other sites
2 minutes ago, Alaskan_Son said:

Yes.  That’s essentially the method I utilized.  In a nutshell, my method for this particular use case was to first convert the file path to a string, then to break that string up into an array of values to represent drive, directory, subdirectories, and file, and then to display only the first 3 of the last 4 values in the array.  

 

Ok that sounds much more logical.  Thank You.

 

I guess what you are saying is that useful macro's cost money.

Share this post


Link to post
Share on other sites
Just now, Chopsaw said:

 

Ok that sounds much more logical.  Thank You.

 

I guess what you are saying is that useful macro's cost money.


...or at the least, valuable time and expertise. The first of which you can of course spend freely...in order to arrive at the second if you should so choose to do so.  
 

Or, if your time is valuable enough to you, yes, you can just pay one of us (with money) to set something up for you or perhaps to coach you so you can start writing your own.

Share this post


Link to post
Share on other sites

There are of course multiple ways of doing this.

 

For this string

 

C:\Users\zbook17g3\OneDrive\_Business\DesignsByLaVor\_WorkX11\_Builders\CH - Compass\Clients\Working\Hancock - Hardin\Hardin.plan

 

This regular expression (probably not ruby compatible) extracts everything after _Builders\ and before \[any number of alphanumeric characters].plan.

 

(?:_Builders\\)(?<str>.*)(?:\\\w+\.plan)

 

So the result is CH - Compass\Clients\Working\Hancock - Hardin

 

I generally prefer not to rely on character counts or specific positions and would write a routine where the delimiting values could be passed in rather than hard coded.

Share this post


Link to post
Share on other sites
9 hours ago, Chopsaw said:

Is there a way to take his example of :

 

C:\Users\zbook17g3\OneDrive\_Business\DesignsByLaVor\_WorkX11\_Builders\CH - Compass\Clients\Working\Hancock - Hardin\Hardin.plan

 

 

Then write a macro that effectively eliminates everything before the 8th instance of "\" and after the 12th instance.

 

Producing the result of :

 

CH - Compass\Clients\Working\Hancock - Hardin

Sure, but a better method would be to use:

  • result = referenced_full_filename.rpartition("_Builders/")
  • result = result[2].rpartition("/")
  • result = result[0]

This way you only have to know that you want to eliminate everything up-to and including "_Builders/" and everything after the last "/".

Note that I'm using the "/" instead of the "\" because that's what Chief uses in the referenced_full_filename attribute.

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, Joe_Carrick said:

Sure, but a better method would be to use:

  • result = referenced_full_filename.rpartition("_Builders/")
  • result = result[2].rpartition("/")
  • result = result[0]

This way you only have to know that you want to eliminate everything up-to and including "_Builders/" and everything after the last "/".

Note that I'm using the "/" instead of the "\" because that's what Chief uses in the referenced_full_filename attribute.

 

Thanks Joe,  I will give that a try.

Share this post


Link to post
Share on other sites
19 minutes ago, Chopsaw said:

 

Thanks Joe,  I will give that a try.

It might work as just a one line macro.  I'm not sure because sometimes Ruby doesn't like too many methods on a single line.  IAE you can try it:

  • result = referenced_full_filename.rpartition("_Builders/")[2].rpartition("/")[0]

Share this post


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

It might work as just a one line macro.  I'm not sure because sometimes Ruby doesn't like too many methods on a single line.  IAE you can try it:

  • result = referenced_full_filename.rpartition("_Builders/")[2].rpartition("/")[0]

 

Yes that works ok with Chief.   Thanks B)

Share this post


Link to post
Share on other sites

I am not very familiar with Ruby... trying to learn as I have time.

 

What precedes "result = referenced_full_filename.rpartition("_Builders/")[2].rpartition("/")[0] " and what follows it to get it to work in CA?

 

Thanks!

Share this post


Link to post
Share on other sites

Nothing. 

The macro just has to be assigned to the Label of a Layout Box.

Of course you need to create the macro - name it builder_plan_name

 

  • Upvote 1

Share this post


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

Nothing. 

The macro just has to be assigned to the Label of a Layout Box.

Of course you need to create the macro - name it builder_plan_name

 

Also needs to be an Evaluated Owner Object macro I believe.

Share this post


Link to post
Share on other sites

Is there a way to use it as a, and I am not sure of the terms to use, reference label? Such that it is in a text box with an arrow pointing to the layout box. This so I do not have to turn on the Layout Box Labels layer.

Share this post


Link to post
Share on other sites
5 minutes ago, lavorhaynie said:

Is there a way to use it as a, and I am not sure of the terms to use, reference label? Such that it is in a text box with an arrow pointing to the layout box. This so I do not have to turn on the Layout Box Labels layer.

 

Yes

Referenced Macro.JPG

Share this post


Link to post
Share on other sites

Does anyone know why rounding in Ruby acts like this?

 

image.png.cfd6153040001c082bf2f2b9dca6064b.png

 

3.4000....4  certainly shouldn't round to 4.08

Share this post


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

    28631
    Total Members
    9156
    Most Online
    sawallace64
    Newest Member
    sawallace64
    Joined