Ruby program hanging SU on test - is there a log file?

Thanks again, Dan, for excellent advice.

My iterations are incremental, and variable, additions to the z-value of a ‘slice’ of a building. So I don’t have a set of ‘things’ to iterate over, and if (as I suspect) at some point I’m either calculating a step size of zero (so nothing gets added to the z-value), or else I’m somehow failing to increment the loop counter.

It’s intended to draw a quarter-ellipse sides and faces of columns, optionally on a slant, for the RiverArch building that NewThinking2 (Scott Baker) is designing. Earlier versions of the program worked, but I was trying to refactor it and enable it to use smaller slice heights, and have screwed it up completely at the moment.

In another glimpse of the Ruby console after I force quit the program, I see that my loop counter i has increased to absurdly large values, in spite ot a line while i <= 10.

LATER.
Put in a UI.messagbox to alert if height increment gets set to zero, and it does. So now to look for logic error that allows that to happen.

Well, I think I’ve sorted the logic error in calculating the slice height to take me either one standard slice up, to the next floor level if lower than a standard floor height, or to the top of the floor.

And also negotiated my way round the top of the lower apex of the ellipse and/or the upper apex.

But I still can’t get the looping to terminate when it has got to the top (z_level > a1) and the next_slice_height is calculated at 0.0.

I’ve put in UI.messageboxes with a break clause after them, but it isn’t stopping the looping.

The program gets stuck with i = 108, and keeps looping, popping up the messagebox saying the next slice height will be zero, and still requiring a force quit to stop it

Code attached if anyone would care to look and help me see where I’m going wrong.

draw_arch_v3-3.rb.zip (4.1 KB)

At the moment, I’m just drawing points, but I want faces and floor lines - the code to produce them is largely commented out.

An older version of the code produced columns like these, but it is not right at the top, and needed manual editing:


Columns.skp (1.5 MB)

But these were drawn one face at a time, before exploding and remaking into whole-column components. I want after I get this bit working to call draw_arch four times, once for each face of a column with a single set of inputs.

John, I think you botched the attachment! The above is what I see in your post, and I can’t download the code from it. Well, actually I managed to trick the website into giving me it, but by devious means.

Very sorry, Steve. Will try again here:
draw_arch_v3-3.rb.zip (4.1 KB)

I think I got the link mixed up with text , and didn’t disentangle it cleanly.

John, when I load that code (even after wrapping it in a module) I get this warning!

load "/Users/steve/Downloads/draw_arch_v3-3.rb"
/Users/steve/Downloads/draw_arch_v3-3.rb:36: warning: redefining Object#initialize may cause infinite loop

Initialize is supposed to be the method within a class that is implicitly called by Object#new when you create an instance. There is no class defined in the file you distributed, so you are affecting the base Object class!

I did see the warning, but didn’t understand its significance.

Should I just leave it out? It was my attempt to have ‘run once’ code to fill the input box with default values to get going.

I think I remember seeing an alternative something like:

@defaults.defined ? @defaults = [starting_values] || [last_used]_values}

but I don’t think I have the syntax right and can’t immediately find the example I thnk I saw some time ago
.
My normal method of operation is to:

  • load the .rb file in the console
  • type initialize
  • type get_inputs

then adjust the parameters if needed, and press OK.

Subsequent runs only need me to press up-arrow three times to retrieve the earlier line, then press {Enter} again.

Your Ruby code is quite poorly formatted.
Put it all inside a module.
Then run the relevant parts using some menu/command code…
e.g. why you include ‘initialize’ in it when it’s not a ‘class’ is a mystery…

Please explain - in non-code English - what t is you wish to do…

John I think the bug is that when you break out of the in-floor loop you fail to increment the i counter, so it get stuck at 107:

          if next_slice_height <0.05
            UI.messagebox "#{i}, next slice height is zero - breaking out of in-floor loop"
            next_slice_height = slice_height
            break
          end

# SLB: this isn't executed    
          i += 1 # next slice
          in_floor_level += next_slice_height
          z_level += next_slice_height
  
        end # while in floor

# SLB: because break jumps to here

By the way, I wrapped your file in a module I named JWMTest and then everything within that module in a class I named DrawArch. Then after loading the file I do:

da = JWMTest::DrawArch.new    # this implicitly invokes your initialize
da.get_inputs()               # this launches your processing

And it runs just dandy using the debugger!

TIG, Steve: I hadn’t bothered to wrap my code in a module, or a class, since it will only execute standalone on my own machine. However, I suppose with other installed plugins with which it might conflict, it would indeed be better practice to do so, and I shall.

You say (I’m sure rightly!) that the code is ‘poorly formatted’. In what ways could I improve it? I did use the NetBeans IDE to ‘Format code’ to get the indenting regular, but i may have mucked it up since doing that.

Or did you mean ‘poorly structured’ - which it quite likely is!

TIG: you asked “What is it I am trying to do?”

I’m trying to create quarter-elliptical columns and other arched parts of an arched building that Scott Baker (@NewThinking2) is designing, on which I offered to help, out of interest and curiosity.

The overall building looks like this:

A previous version of the program drew one quarter of the arch and the floor levels shown in the image, and later the columns shown in my earlier attachment.

That program drew one face at a time - outer curved face, inner curved face, and side faces. Then drew the floor lines as shown in the image, with their corners exactly on (quarter) elliptical curves.

Optionally, the arch and column faces may slant with a slope of 2 feet in every ten feet.

The building has almost 100 floors, and is 1000’ high and 2000’ overall end to end.

It has variable floor heights, shown in the image above. Most ‘standard height’ floors (variable name std_floor_height) are 10’ high. The lowest floor in line with the centre of the arch 1 is lower - 9’10", floors 2, 33 and 64 are 15’3, and the first floor (87) that spans all the way across the arch is 20’ high. There’s a hand drawn added floor 0, which is just a projection straight down of floor 1.

We wanted it drawn in ‘slices’ which could have a higher resolution than the floor height.

Near the top, the slice height needs to get smaller to preserve the appearance of curvature rather than just a few very long nearly horizontal straight lines.

There’s a notch 15’ deep and 21’ wide on the inner arch, to carry external elevators.

The shape proved impractical to draw ‘by hand’ with native tools, or even plugins, especially to draw the floor perimeters accurately with corners on the elliptical curve. I first tried by stretching a semicircle with 180 segments, and using Fredo Tools Shear to slant the sides and the notch, which gave the overall shape, but not the floor heights.

As I write, I see Steve Baumgartner has posted that he has identified the bug where my code fails to stop as it goes up the building.

But I’d still welcome further suggestions to improve structure and formatting, TIG, and thanks for looking at the code.

Steve, THANK YOU again. I’ve been going nuts for the last couple of days knowing the logic wasn’t right, and too close to it to see it.

Is this what you expected the component to look like?

By the way, for anyone who has been following this and our other thread about NetBeans setup for debugging, I found this error fairly quickly using the debugger!

I won’t attempt to get into the discussion on code, which I know nothing about, but on the arch itself, some things might make it easier:

  1. There is no floor 97, just a variable ceiling height on floor 96, up to 18’2" floor to ceiling.
  2. You can leave the end to end floor measurements. There are going to be several terraces up there, protruding out of the sides of the arch, and many floors in the inner arch too, though there’s less sun down there. This will actually extend the floors outside then.
  3. This may make it harder, so feel free to ignore it: But there’s going to be plaza levels from 4-32 in the apx. center of the 4th floor as a wedge cut-out. This can come later, but just so you don’t think the building it just a dense mass. Other stuff will be added onto the outside later too.
  4. The channel for the external elevators is actually 15’ D X 21’ W
  5. We do need to have more segments near the top, especially on the 87 floor, so I can realistically position the external elevators up there.

OK, back to you guys…

Yes, until I switch from drawing points to drawing faces and floor lines. I found it easier to check with just points - the mesh.add_polygon command could throw a wobbly if given an invalid point!

How did you use it?

I’m still slowly finding my way using the debugger. I can’t always even get it to break at a line, so would welcome tips on how you used it.

And maybe I should find documentation for the NetBeans IDE to clarify what it can do and how.

There are two parts to the answer:

  • how I set up and activated the debugger
  • how I used it to hunt for a problem

The former we have been discussing in the other topic. I didn’t do anything special beyond what is discussed there and the changes to your code I described earlier in this topic.

Because it seemed like a crucial aspect, I put a breakpoint at that break statement. Then each time it hit that breakpoint I looked at variables to see what was happening. I noticed that the value of i was not increasing and then noticed that your UI.messagebox was actually reporting the same thing. Single-stepping forward from the break statement made it clear that the reason was the code was jumping out of the loop (as expected) which caused it to bypass the statement that increments i.

Don’t feel bad - I have about 45+ years of experience debugging code! You’ll get there!

That’s helpful, thanks.

I probably put my test breakpoint in the wrong place, and it wasn’t triggering.

Did you just move the break until later, after the increment to i? Or how is that done?

Could you upload the modified code please, so I can see it?

@john_mcclenahan, I’ve already the done the “shame on you, virtual spankin’, ‘cause ya’ didn’t use minimum good coding”, for this month in the following post.

It has a simple code template (you just use another name for the top-level “namespace” module.)

Change a menu item

@DanRathbun: Consider me duly chastised!

I will indeed try to follow your excellent example in future attempts at coding, and amend this one retrospectively.

1 Like

I did the minimum to establish that was the bug. Dan will probably not find it fully up to his standards, but at least it isn’t really dirty :wink:

draw_arch_v3-3.rb (13.9 KB)

1 Like