Thanks Dan, I have read the pragmatic programmers book but that was a while back and unfortunately I have a deadline submission I need to meet next week, i've managed to get the C++ side of the coding done but am struggling with the Ruby and don't have time to re-assess what i've learnt, just need to sift through the relevant information and collaborate it.
Posts made by Zane
-
RE: Drawing an array of boxes
-
RE: Drawing an array of boxes
ok, thanks for the headsup on that, any idea about the crazy looping issue or why I can't see the puts anymore? Oh, and that module question, sorry there's so much to ask.
-
RE: Drawing an array of boxes
Sorry Dan, i'm a bit lost as to what you mean by your last post, why is it that I would split the file up into bits and what is the purpose of using modules, i've read they're similar to classes but nothing specified a distinct reason as to why they are as they are?
I'm also curious as to what you meant when you wrote module_function(:function) in the box.rb file, what does it do exactely? I presume it can only be used for external functions and not ones in classes?
-
RE: Drawing an array of boxes
I think i've found it with the help you gave there (just a snippet of the code where the error might be):
class Building def io_calcs #distprompts = [$exStrings.GetString("What is the distance between the start of one column to the start of the next one? (make it at least 1m more than the width of the foundation")] #distvalues = [5500] # Now display the inputbox #distresults = inputbox distprompts, distvalues, $exStrings.GetString("Distance between each column (mm)") #return if not distresults # This means that the user cancelled the operation #coldistance = distresults ##Enter values from C++ here slab = IO.readlines('C;\\Users\\Zane\\My Documents\\slabout.txt') @slabdepth = slab[0].to_f.mm @slabwidth = slab[1].to_f.mm @slabheight = slab[2].to_f.mm #UI.messagebox ("Sketchup will now take in the details and attempt to draw the building", MB_OK) end
It's either not taking in the values of slabheight, slapdepth nor slabwidth as i'm trying to take them in from an input file.
It's not even letting me "puts" the variables nor any other string I tell it to output like:puts 'test'
Ideally i want to input variables from a text file whose content is
250
5500
7700and assign each one of these values to a variable, then use those respective variables.
-
RE: Drawing an array of boxes
Ahh i see, thanks for that
Another error now, the code keeps looping and doesn't stop (doesn't draw either), the values seem to be wrong also... nothing seems to be working :s
-
RE: Drawing an array of boxes
I used Building.new and called the io_calcs function as well as the draw_slab_array function, what does that mean about my variables then, should I be able to use them within the functions that are in the class?
To my knowledge, within a class, Ruby makes all of it's variables and functions public unless specified otherwise, so it confuses me as to why I get this problem of the variable not being read
-
Drawing an array of boxes
module Examples module SU module Structure require 'sketchup.rb' class Building def io_calcs #distprompts = [$exStrings.GetString("What is the distance between the start of one column to the start of the next one? (make it at least 1m more than the width of the foundation")] #distvalues = [5500] # Now display the inputbox #distresults = inputbox distprompts, distvalues, $exStrings.GetString("Distance between each column (mm)") #return if not distresults # This means that the user cancelled the operation #coldistance = distresults ##Enter values from C++ here slab = IO.readlines('C;\\Users\\Zane\\My Documents\\slabout.txt') $slabdepth = slab[0].to_f.mm $slabwidth = slab[1].to_f.mm $slabheight = slab[2].to_f.mm UI.messagebox ("Sketchup will now take in the details and attempt to draw the building", MB_OK) end def draw_slab # Makes the process seem to be one rather than many; undo will undo the whole operation model = Sketchup.active_model model.start_operation $exStrings.GetString("Draw Slab") #Adds model to the active entities collection entities = model.active_entities #Creates the object as a group group = entities.add_group entities = group.entities #gives an initial location for the foundation $slabwidth += $start_of_slab #Creates an array of points for the base pts = [] pts[0] = [$start_of_slab, 0, 0] pts[1] = [$slabwidth, 0, 0] pts[2] = [$slabwidth, $slabdepth, 0] pts[3] = [$start_of_slab, $slabdepth, 0] base = entities.add_face pts # reverses direction of pushpull if incorrect. $slabheight = -$slabheight if( base.normal.dot(Z_AXIS) < 0 ) # pushpulls object base.pushpull $slabheight # ends operation model.commit_operation end def draw_slab_array #need to do $start_of_slab = 0.mm draw_slab wob = 30000.mm #not needed in the final one wobt = wob while ((wobt - $slabheight)>$slabheight) $start_of_slab = $slabwidth + $slabheight draw_slab wobt = wobt - $slabheight end $start_of_slab = wob - $slabheight draw_slab end end if( not file_loaded?("structureclasstestforstartpoints.rb") ) # Adds a separator to the menu add_separator_to_menu("Draw") # Adds item inside the menu allowing a bit of code to be #carried out if clicked on UI.menu("Draw").add_item($exStrings.GetString("Test Structural Slab")) do frame = Building.new frame.io_calcs frame.draw_slab_array end file_loaded("structureclasstestforstartpoints.rb") end end #Structure end #SU end #Examples
-
Why is it that I need to create global variables for my program to
say that the variable is recognised? Surely I can just use the
variable anywhere in the class and it will work so long as it has been
intialised before use? -
Do you guys see anything else wrong with the code?
-
The code keeps looping in the while loop... help? (slabheight is about 7700)
Thanks for your help guys!
-
-
RE: Pause until action is complete
some text files will available for input is one thing that will be available after the system call
-
RE: Pause until action is complete
Ah ok, sorry for posting it in the wrong section
-
Pause until action is complete
Hey guys,
Quick question for you all. I'm doing a system call for an exe file to be run in a ruby code and I don't want the ruby code to continue until the exe has finished running, is there any code or function I can use that will pause the script till the system call is complete?
Thanks for your time and help! -
RE: Input and Output files in Ruby
That's fantastic Jim, thanks!
I just happened to stumble across something similar where I can use IO.readlines and arrays to sort out the writing in lines one by one.
-
Input and Output files in Ruby
Basically i've tried to do some research on this but I can't seem to get anything that is working in Sketchup so I really need your help guys, here is the problem i'm having:
I have a text file in my documents which contain three numbers (they can either be seperated by spaces or by /n) and I want to have ruby read that file in line by line, storing each line as a new variable, the first variable being depth, the second being width and the third being length.
Do you guys think you can help? I can show you what I mean in C++ if that helps:
ifstream input("My Documents\\slabout.text"); input >> depth >> width >> length input.close();
Thank you for your help!
-
RE: Creating structural elements in Sketchup
@mitcorb said:
While you are thinking about it, see this:
http://www.forums.sketchucation.com/viewtopic.php?f=323&t=35798&p=315999&hilit=%2Astructural%2A#p315999
Not necessarily the same thing, not necessarily intended to be the same thing.
What you may be talking about might involve "Finite Element Analysis"? Search that in this forum.
Keep in mind, Sketchup is not a solid modeler, if that would have anything to do with it.It'll make beams, columns, slabs and foundations, not so much focused on the finite element, sorry for the confusion.
-
RE: Creating structural elements in Sketchup
The elements will be beams, columns, slabs and foundations not finite elements
Thanks for the link!
-
Creating structural elements in Sketchup
Hey guys, i'm new here and I have a question for you all, it's quite vague so I hope you can still help me nonetheless.
Basically, I need to make a plugin which is able take in specific details (variables), carry out structural calculations and then draw the results (a structural frame) automatically in sketchup.
The guidelines are to have the structural calculations in C++ and the variables as well as the drawing of the structure in Sketchup (Ruby). I was wondering if this is possible.
The main idea would be:
- Take variables via the input box on Sketchup.
- Send these values into a text file
- Run a compiled .exe C++ file within Sketchup Ruby Plugin which accesses these variables in the text file.
- Write into another text file in C++ giving new variables.
- End the C++ .exe
- Remainder of the Ruby code reads these variables in the new text document
- Draws the different structural elements in a specific order
So guys, is it feasible, I really need to stick to the main guidelines but the way to carry it out is my idea.
Thanks for the help!
Zane