sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Drawing an array of boxes

    Scheduled Pinned Locked Moved Developers' Forum
    15 Posts 3 Posters 765 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C Offline
      Cleverbeans
      last edited by

      I would suggest breaking the code out into logical steps, and give each step a method. Normally I'd start with a blank file and write out what I want to happen in natural language as comments. Once I get it into a step-by-step form that makes sense I will declare method names around each step. Once I've done that I figure out what the inputs and outputs of each method should be and document them in a comment. Once that's done I pick the easiest one to test, write a simple test for it, then implement the method and see if it passes the test. Repeat until finished. It's hard to say why it's failing here because of all the variable kicking around, so maybe just try and split the methods into more bit sized portions then put it together at the end.

      1 Reply Last reply Reply Quote 0
      • Z Offline
        Zane
        last edited by

        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
        7700

        and assign each one of these values to a variable, then use those respective variables.

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          The namespace Examples::SU I really intended for the Google supplied examples.

          You should choose your own Toplevel namespace (Zane is good for now.)

          Beneath that you will have you various plugin namespaces (module blocks.)

          like this or similar:

          module Zane
            module BuildWizard # this plugin
              module Structure
                class Building
                end # class
                class Bridge
                end # class
                class Roadway
                end # class
              end # module Structure
              module Widget
              ebd # module Widget
            end # module BuildWizard
          end # module Zane
          

          etc..

          Once your namespace heirarchy is defined (in the first loaded file of your plugin,) you can break up the various code blocks into separate files (and save some indentation by using qualified blocks:

          file2

          module Zane;;BuildWizard;;Structure
            # define module vars and module methods
          end
          

          file3

          class Zane;;BuildWizard;;Structure;;Bridge
            # define instance vars and instance methods
          end
          

          file4

          class Zane;;BuildWizard;;Structure;;Building
            # define instance vars and instance methods
          end
          

          file5

          module Zane;;BuildWizard;;Widget
            # define module vars and module methods
          end
          

          .. etc...

          and use the require("filename") where needed to load the various files that make up your plugin project.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • Z Offline
            Zane
            last edited by

            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?

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @zane said:

              I think i've found it with the help you gave there (just a snippet of the code where the error might be):

              
              > 		#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")]
              

              $exStrings is not YOUR object. It is a hash of strings, created and used by the Google supplied code examples.

              Create your own local string, or a LanguageHandler hash object within your plugin namespace (DO NOTuse a global like Google did, it is bad programming.)
              Or just use a string literal.
              distprompts = ["Column Spacing"]

              Also with a prompt string that large, the UI.inputbox is likely to look crazy.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • Z Offline
                Zane
                last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  Another booboo:

                  coldistance = distresults

                  A UI.inputbox returns an Array, not a single value.
                  So to get the first value from an inputbox:

                  coldistance = distresults[0]
                  or
                  coldistance = distresults.first

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @zane said:

                    I think i've found it with the help you gave there (just a snippet of the code where the error might be):

                    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:

                    try stripping each line of whitespsce and control characters:

                    
                    		slab = IO.readlines('C;\\Users\\Zane\\My Documents\\slabout.txt')
                    		@slabdepth = slab[0].strip.to_f.mm
                    		@slabwidth = slab[1].strip.to_f.mm
                    		@slabheight = slab[2].strip.to_f.mm
                    
                    

                    Eventually you'll want these values on one line separated by commas (likely with the tag "slab" as the first vaule.

                    
                      lines = IO.readlines('C;\\Users\\Zane\\My Documents\\slabout.txt')
                      lines.each {|line|
                        data = line.strip.split(',')
                        if data[0]=='slab'
                          @slabdepth = data[1].to_f.mm
                          @slabwidth = data[2].to_f.mm
                          @slabheight = data[3].to_f.mm
                        elsif data[0]=='wall'
                          # do something else
                        end
                      }
                    
                    

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      @zane said:

                      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 ...

                      When you write complex plugins that have 1000s of lines of code, you WILL get tired of scrolling up and down. It is easier if you have a tabbed code editor to click another tab, find what you need in another file (a constant name, etc.,) and then click the tab of the file your working on. (I use Notepad++ which also allows splitting the editor into 2 panes.)

                      @zane said:

                      ...and what is the purpose of using modules, ...

                      See my info topic: [info] Using Ruby Modules

                      @zane said:

                      ...I've read they're similar to classes ...

                      Actually, class Class is the child subclass of class Module, and subclasses inherit objects (like methods,) from their superclass, so of course they are similar.

                      @zane said:

                      I'm also curious as to what you meant when you wrote module_function(:function) in the box.rbfile, what does it do exactly? I presume it can only be used for external functions and not ones in classes?

                      Well... you won't understand this issue until you do some reading... but basically the module_function() allows a coder to write a double-duty module, that can act as both a library module (it's methods are called from outside using name qualification,) and a Mixin-Module (that is mixed into classes, giving the class all it's instance methods.)
                      The box.rb is really a poor example of such a "double-duty" Module.

                      see Ruby Pick-Axe book: module_function

                      Jim asked a similar question, and I answered in the box.rb Example topic, see:
                      Re: module_function

                      Zane.. did you read my "Newbie's Guide" ? (If not click the Ruby Resource link in my signature.)

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • Z Offline
                        Zane
                        last edited by

                        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.

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement