RUby Rescue or


MarkMc
 Share

Recommended Posts

I have macro

mods=owner.supplier

x=mods.delete!("\r\n")

y=x.gsub!(/>[0-9]*>/,'')

y.gsub!(/>[0-9]*/,'')

Does what I need UNLESS owner.supplier is a single line. When I first discovered that I made a second macro that applies only if there is a single line but realize that I need to have only one.

 

I tried to use Rescue but can't get that to work, likely bad syntax. Thing is I don't even know if this is the correct method to use.

Can "rescue" solve this? in which case I can continue to work it out... or do I need something else like an if statement?

Link to comment
Share on other sites

4 hours ago, GerryT said:

Try this

x = owner.supplier.gsub(/(>[0-9]*>)|\s/,'')

OR

x = owner.supplier.gsub(/(>[0-9]*>)|\n/,'')

the second worked once I figured out that I need to use part of what I had. I didn't see that one initially.

final is

x = owner.supplier.gsub(/(>[0-9]*>)|\n/,'')

x.gsub!(/>[0-9]*/,'')

 

works for all the filled in fields, single lines, or if field is blank.

I didn't realize at first that this was the same macro Eric and Joe were helping me with yesterday (in the rabbit hole again).

 

 

Now I have to go back to the reference so I can understand what is actually going on and learn something :) Thanks Gerry

Link to comment
Share on other sites

Just looked at your response and have to say that I did not realize that you could have a condition with or without a > sign (optional??)on the end?

 

in that case, the proper code would be:

 

x = owner.supplier.gsub(/(>[0-9]*>?)|\n/,'') --(note the ? mark) -- only if the optional > is always on the end. If the optional > might also be in the front - a different macro is needed if that number is not to be removed?

 

Your solution looks OK though, you can get too cute in putting everything in one statement. Many times it's easier to understand with multiple statements in lieu of one.

 

  • Upvote 1
Link to comment
Share on other sites

17 hours ago, GerryT said:

in that case, the proper code would be:

That works perfectly Gerry, thanks. I'll read up on the "?" tonight.

I tried to fix the first two since they eliminated the exception error with blank or single line fields but nojoy getting it to work properly with more lines.  Now it does-

#sample field content
>1>FLSHENDB-L>65;
>1> LeMans 50>0;
>1> REL-RAIL (opening 19 3/8)>170;
>1> 4" Filler Overlay Loose, finish & lip 3 edges>19;

 

Your most recent does it perfectly (and looks better than what I put together with duct tape)
x = owner.supplier.gsub(/(>[0-9]*>?)|\n/,'')
=>FLSHENDB-L;  LeMans 50;  REL-RAIL (opening 19 3/8);  4" Filler Overlay Loose, finish & lip 3 edges;

 

Me doing Ruby is kind like a guy with his hands in his back pockets playing whackamole with his head ;-> 

With the changes I've made to the system I use this past week I'll just have to get back to it I suppose. Got slammed last year so forgot what I learned to being with. I can think of a few more improvements I can make to what I'm doing that make the head banging worthwhile.

Thanks.

 

Link to comment
Share on other sites

The ? is a modifier, like the * before it.

 

* - Zero or more times

+ - One or more times

? - Zero or one times 

{n} - Exactly n times

{n,} - n or more times

{,m} - m or less times

{n,m} - At least n and at most m times

 

Link to a website where you may test your patterns to see how they work.

 

http://rubular.com

  • Upvote 2
Link to comment
Share on other sites

12 minutes ago, solver said:

The ? is a modifier, like the * before it.

 

* - Zero or more times

+ - One or more times

? - Zero or one times 

{n} - Exactly n times

{n,} - n or more times

{,m} - m or less times

{n,m} - At least n and at most m times

 

Link to a website where you may test your patterns to see how they work.

 

http://rubular.com

All very useful, thanks. I have a cheat sheet I got somewhere that lists a lot of things like modifiers but since it only lists them, doesn't say what they are I have to go elsewhere to see what they mean, then I usually have to go somewhere else to figure out how to place them properly and see what they do. Think I'm going to love that website. :)

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

    30642
    Total Members
    9156
    Most Online
    oppguenard1
    Newest Member
    oppguenard1
    Joined
  • Similar Content

    • 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.
    • By justin-c
      I'm trying to figure out if there is a way to display room occupancy load, using a text color tag.
      For example if a room was 100 ft.² and the fire occupancy load is 7 ft.² per person able to take the (room area divided by 7)
      the formula would also need to round up or down to the nearest whole number
       
      Here is the "Callout Specification" dialog window
       
           
       
       
      Here is the "callout tag" with the formula, but I would like it to be modified so instead it  show the red text or something similar
       
       

    • By HCremodel
      I am trying to create a custom texture detail schedule that references an object's texture and displays the assigned texture image. Problem is, I am fairly inexperienced with Ruby/macro in general although I have a very basic understanding. Has anyone created something similar to this, or have suggestions on how to get started with creating this type of custom macro? I am using Interiors 12X
    • By KTransue
      Anyone know if there is a text macro that reflects the name of a "Saved Plan View" attached to a layout window view port?  I've looked, and searched ChiefTalk, and even a general Google search, but I'm not finding anything.  Am I missing the obvious?
    • By ACADuser
      Looking at the ROOM data I'm not sure where the Room Area variable is.
      Looking at Joe's macro, he used obj.room.internal_area.round(2)
       
      It appears that the variable is already rounded. Not sure if this is new.
      What I wanted is the area the Room polyline is based on.  369.83  --> Measurement
      I see several area variables, but how to get the one I want?
      How do you know what prefix to get the area you want?
       
      Data Type: String
      base_moldings ------------------- size = 1 ---------------------- Collection
      [0] ------------------------- ------------------------------ NVPublisher
      component_moldings ------ size = 0 ---------------------- Collection
      description ------------- "base molding: PVC 4" Base" --- String
      formatted_size ---------- "1x4" ------------------------- String
      length ------------------ 600 in ------------------------ Measurement
      room -------------------- ------------------------------ NVPublisher
      SEE ABOVE ----------- ------------------------------
      cantilever_underside_material --- ------------------------------ NVPublisher
      id -------------------------- 133 --------------------------- Integer
      name ------------------------ "Color - White" --------------- String
      ceiling_elevation --------------- 108 in ------------------------ Measurement
      ceiling_finish_layers ----------- size = 2 ---------------------- Collection
      [0] ------------------------- ------------------------------ NVPublisher
      area -------------------- 373.153214 sq ft -------------- Measurement
      material_data ----------- ------------------------------ NVPublisher
      description --------- "Square Ceiling Tiles" -------- String
      formatted_size ------ "24"x24"x1/2"" ---------------- String
      quantity ------------ 93.5 -------------------------- Measurement
      owner ------------------- ------------------------------ NVPublisher
      SEE ABOVE ----------- ------------------------------
      thickness --------------- 0.5 in ------------------------ Measurement
      [1] ------------------------- ------------------------------ NVPublisher
      area -------------------- 369.825474 sq ft -------------- Measurement
      material_data ----------- ------------------------------ NVPublisher
      description --------- "Color - White" --------------- String
      formatted_size ------ "" ---------------------------- String
      quantity ------------ 369.825474 sq ft -------------- Measurement
      owner ------------------- ------------------------------ NVPublisher
      SEE ABOVE ----------- ------------------------------
      thickness --------------- 0 in -------------------------- Measurement
      ceiling_finish_name ------------- "Color - White" --------------- String
      ceiling_insulation -------------- ------------------------------ NVPublisher
      area ------------------------ 369.825474 sq ft -------------- Measurement
      cavity_r_value -------------- 0.0 --------------------------- Float
      continuous_r_value ---------- 0.0 --------------------------- Float
      depth ----------------------- 12 in ------------------------- Measurement
      formatted_size -------------- "12x24x48" batts" ------------- String
      length ---------------------- 48 in ------------------------- Measurement
      num_batts ------------------- 46.25 ------------------------- Measurement
      owner ----------------------- ------------------------------ NVPublisher
      SEE ABOVE --------------- ------------------------------
      width ----------------------- 24 in ------------------------- Measurement
      ceiling_platform_layers --------- size = 1 ---------------------- Collection
      [0] ------------------------- ------------------------------ NVPublisher
      area -------------------- 0 sq ft ----------------------- Measurement
      material_data ----------- ------------------------------ NVPublisher
      description --------- "Steel Stud 24" OC" ----------- String
      formatted_size ------ "" ---------------------------- String
      quantity ------------ 0 ----------------------------- Measurement
      rebar_length ------------ 0 in -------------------------- Measurement
      rebar_size -------------- 0 ----------------------------- Integer
      room -------------------- ------------------------------ NVPublisher
      SEE ABOVE ----------- ------------------------------
      thickness --------------- 2 in -------------------------- Measurement
      ceiling_thermal_envelope_area --- 369.825474 sq ft -------------- Measurement
      chair_rail_moldings ------------- size = 0 ---------------------- Collection
      crown_moldings ------------------ size = 0 ---------------------- Collection
      custom_pattern_scale ------------ 1.0 --------------------------- Float
      dimensions ---------------------- "14'-10" x 23'-10"" ----------- String
      drawing_group ------------------- default:_35_-_room_fill ------- Symbol
      fill_line_weight ---------------- 1 ----------------------------- Integer
      finished_ceiling_elevation ------ 107.5 in ---------------------- Measurement
      finished_floor_elevation -------- 0.125 in ---------------------- Measurement
      floor_ceiling_group ------------- 1 ----------------------------- Integer
      floor_elevation ----------------- 0 in -------------------------- Measurement
      floor_finish_layers ------------- size = 1 ---------------------- Collection
      [0] ------------------------- ------------------------------ NVPublisher
      area -------------------- 371.216099 sq ft -------------- Measurement
      material_data ----------- ------------------------------ NVPublisher
      description --------- "Floor-C4 Laminate" ----------- String
      formatted_size ------ "1/8" thick" ------------------ String
      quantity ------------ 371.216099 sq ft -------------- Measurement
      owner ------------------- ------------------------------ NVPublisher
      SEE ABOVE ----------- ------------------------------
      thickness --------------- 0.125 in ---------------------- Measurement
      floor_finish_name --------------- "Floor-C4 Laminate" ----------- String
      floor_insulation ---------------- ------------------------------ NVPublisher
      area ------------------------ 0 sq ft ----------------------- Measurement
      cavity_r_value -------------- 0.0 --------------------------- Float
      continuous_r_value ---------- 0.0 --------------------------- Float
      depth ----------------------- 12 in ------------------------- Measurement
      formatted_size -------------- "12x24x48" batts" ------------- String
      length ---------------------- 48 in ------------------------- Measurement
      num_batts ------------------- 0 ----------------------------- Measurement
      owner ----------------------- ------------------------------ NVPublisher
      SEE ABOVE --------------- ------------------------------
      width ----------------------- 24 in ------------------------- Measurement
      floor_number -------------------- 1 ----------------------------- Integer
      floor_platform_layers ----------- size = 2 ---------------------- Collection
      [0] ------------------------- ------------------------------ NVPublisher
      area -------------------- 0 sq ft ----------------------- Measurement
      material_data ----------- ------------------------------ NVPublisher
      description --------- "OSB-Hrz" --------------------- String
      formatted_size ------ "48"x96"x3/4"" ---------------- String
      quantity ------------ 0 ----------------------------- Measurement
      rebar_length ------------ 0 in -------------------------- Measurement
      rebar_size -------------- 0 ----------------------------- Integer
      room -------------------- ------------------------------ NVPublisher
      SEE ABOVE ----------- ------------------------------
      thickness --------------- 0 in -------------------------- Measurement
      [1] ------------------------- ------------------------------ NVPublisher
      area -------------------- 0 sq ft ----------------------- Measurement
      material_data ----------- ------------------------------ NVPublisher
      description --------- "Concrete" -------------------- String
      formatted_size ------ "4" thick" -------------------- String
      quantity ------------ 0 cu ft ----------------------- Measurement
      rebar_length ------------ 0 in -------------------------- Measurement
      rebar_size -------------- 0 ----------------------------- Integer
      room -------------------- ------------------------------ NVPublisher
      SEE ABOVE ----------- ------------------------------
      thickness --------------- 4 in -------------------------- Measurement
      floor_thermal_envelope_area ----- 369.825474 sq ft -------------- Measurement
      function ------------------------ "Living" ---------------------- String
      internal_area ------------------- 370 sq ft --------------------- Measurement
      layer --------------------------- rooms ------------------------- Symbol
      layer_line_color ---------------- 2151678207 -------------------- Integer
      layer_line_style ---------------- 111 --------------------------- Integer
      layer_line_weight --------------- 18 ---------------------------- Integer
      layer_set ----------------------- "Floor Plan" ------------------ String
      layer_text_style ---------------- "Default Text Style" ---------- String
      moldings ------------------------ size = 1 ---------------------- Collection
      [0] ------------------------- ------------------------------ NVPublisher
      component_moldings ------ size = 0 ---------------------- Collection
      description ------------- "base molding: PVC 4" Base" --- String
      formatted_size ---------- "1x4" ------------------------- String
      length ------------------ 600 in ------------------------ Measurement
      room -------------------- ------------------------------ NVPublisher
      SEE ABOVE ----------- ------------------------------
      name ---------------------------- "Shared Medical" -------------- String
      pattern_angle ------------------- 0.0 --------------------------- Float
      pattern_horizontal_spacing ------ 8 in -------------------------- Measurement
      pattern_vertical_spacing -------- 8 in -------------------------- Measurement
      perimeter ----------------------- 1020.936748 in ---------------- Measurement
      schedule_number ----------------- "R69" ------------------------- String
      simple_schedule_number ---------- "69" -------------------------- String
      standard_area ------------------- 389 sq ft --------------------- Measurement
      stem_wall_height ---------------- 16 in ------------------------- Measurement
      stem_wall_top_elevation --------- 0 in -------------------------- Measurement
      type_name ----------------------- "Office" ---------------------- String
      volume -------------------------- 3309.16752 cu ft -------------- Measurement
      wall_coverings ------------------ size = 0 ---------------------- Collection
      wall_material ------------------- ------------------------------ NVPublisher
      id -------------------------- -32765 ------------------------ Integer
      name ------------------------ "No Change" ------------------- String