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

    [Plugin] Voxelize - Updated 2011-04-04

    Scheduled Pinned Locked Moved Plugins
    48 Posts 21 Posters 61.2k Views 21 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.
    • T Offline
      TheDro
      last edited by

      Thanks for the changes, Dan. It's my first time programming in ruby and I'm still a bit iffy about modules and classes and when to use which. I've looked at some documentation about them but haven't had time to read it thoroughly. I've preceded my method names by td_ based on something I read in a thread around here having to do with name conflicts between plugins. Do I need to do that or can I skip it since my plugin is now in its own module?

      1 Reply Last reply Reply Quote 0
      • K Offline
        Khai
        last edited by

        guys...

        Minecraft!?!?!

        if you can get this to save out to the Minecraft format...

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

          @thedro said:

          I've preceded my method names by td_ based on something I read in a thread around here having to do with name conflicts between plugins. Do I need to do that or can I skip it since my plugin is now in its own module?

          You can skip it now... since it's within it's own namespace, it cannot clash with any other method outside the namespace (including your other plugin submodules.) So td_voxelize() can become just plain ol' voxelize()

          I wrote a couple of topics on using modules:
          [info] Using Ruby Modules
          [talk] Using Ruby Modules

          I'm not here much anymore.

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

            Another suggestion for the Undo operation:

            (1) Define a module var @@op=0 (or whatever) at the top of the code.

            (2) Then in your td_voxelize() method, wrap the operation in a begin .. rescue .. end block:

            begin
              model.start_operation( "Voxelize(#{@@op+=1})" )
              # .. voxelize code ...
              model.commit_operation
            rescue Exception => e
              model.abort_operation
              puts("Voxelize Operation Error; #{e.message}")
              return nil
            else
              # only executes if no errors occur
              return true # or whatever for success
            ensure
              # ALWAYS executes no matter what happens
            end # operation
            

            (a) If any untrapped errors occur, the rescue clause will abort the operation (hopefully preventing model corruption.) Also if you do trap any errors that you feel should cause an abort, you can raise an exception (of some kind,) within the voxelize code, to cause execution of the rescue clause.
            If you don't know which exception to raise, using RuntimeError is fine, and you can set the message to whatever suits your fancy:
            raise(RuntimeError,"Some custom Voxelize Error Message here.")

            (b) The @@op counter gives each operation a unique name on the Undo stack. (Similar to when you open multiple new documents in an application. The first gets a name "untitled.doc", the second "untitled2.doc", etc.)

            EDIT: Added the else and ensure clauses to example, so you can see where they'd go (if you use them.)

            I'm not here much anymore.

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

              @thedro said:

              It's my first time programming in ruby and I'm still a bit iffy about modules and classes and when to use which.

              Generally...

              If only 1 copy of the code is needed, it should be a module.

              If more than one copy (instance,) is needed, it should be a class. (There are exceptions, the so-called "Singleton Classes" like TrueClass, FalseClass, NilClass and in practice, most Sketchup Tools should be written as a Singleton Class. For a Singleton, only 1 instance should be in existance any any given time.

              The link in my signature line will lead you to a bunch of Resources. Tutorials and alot of books you can downlaod for free.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • T Offline
                TheDro
                last edited by

                @Khai Hah! Minecraft is actually what first inspired me to write this plugin since it would be a relatively simple way of creating complicated geometries (building plans). It may have other applications though such as Monte Carlo simulation using Geant4. Geant4 is basically a particle physics toolkit that's used to simulate particles interacting with matter. Making geometry with the toolkit can be quite tedious to do code-wise and is far more difficult than using Sketchup. Making cubes is simple though and the application of my plugin is obvious in this case. Anyways, back to Minecraft 😛. As for exporting to a compatible format, I would first have to figure out what that format is but I'm sure it wouldn't be too difficult since the plugin already creates a 3D "binary" matrix. I'll get to that ... eventually.

                @Dan Thanks again. I'll get to reading your links concerning modules either tomorrow or the day after.

                1 Reply Last reply Reply Quote 0
                • 2 Offline
                  22curious
                  last edited by

                  Thanks TheDro & Dan!

                  How about adding options for:

                  • spreading the cubes out, with inputs for x, y, and z separation spaces
                  • choosing which planes to slice, one, some, or all... x-z, y-z, x-y
                    ?

                  Are there any existing plugins do these slicing, dicing, and spread-em-out actions?

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    TheDro
                    last edited by

                    Well it's possible to spread out the cubes just by modifying any one of the cubes since they are all instances of the same component. So you can double click on one of the cubes, then use the scaling tool to shrink it, and they will all shrink while remaining in position, and this will produce spacing between them all. As for the plane slicing, I'm not sure I follow. Could explain in more detail, 22curious?

                    I'll probably release a new version tonight that calculates the position of the cubes MUCH faster.

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

                      @thedro said:

                      I'll probably release a new version tonight that calculates the position of the cubes MUCH faster.

                      It is customary (here at SCF,) to replace the file in the first post of the topic, with the new version, and then edit the topic title (which only you can do because you "own" the topic,) to reflect the revision date.
                      Example revised topic title:
                      "[Plugin] Voxelize - Updated 2011-03-24"

                      *** standard date format for Ruby is YYYY-MM-DD**

                      Then you can slide all the way down to the bottom of the webpage, and click the "Bump" link to bring the topic to the top of the forum list (without needing to post a new message.)

                      After you do that, I'll remove my version 1a and put a link back to the first post.

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • 2 Offline
                        22curious
                        last edited by

                        @unknownuser said:

                        spread out the cubes...double click on one...use scaling tool to shrink it.

                        This is where that Homer [doh] audio plugin button comes in handy. Of course!
                        'Wearing too many hats, my SKU skills are SKrUsty...

                        @unknownuser said:

                        As for the plane slicing
                        My need may be met using asteronimo's SliceModeler.rb "plugin that slices a solid 3d model along 2 axes, f.i. an X- and a Z-axis." SliceModeler.rb is based on Tig's Slicer.rb (that isn't on the plugins list? but found at http://forums.sketchucation.com/viewtopic.php?f=180&t=10413&p=68825&hilit=slicer.rb#p688). I'm checking SliceModeler and Voxelize out now!

                        ...another path may be combining a lattice>>cutting component>>Tig's Hole punching Tool.

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

                          Made a few changes for you Andrew:

                          • properly module wrapped the plugin.

                          • cube size is remembered during session in var @@cube_size

                          • made it easier to control menu with constants defined at top of file

                          • added validation for the menu item

                          I think the "group test" should fire before the inputbox is displayed.
                          But otherwise it looks good.


                          Latest version now in the first post

                          I'm not here much anymore.

                          1 Reply Last reply Reply Quote 0
                          • G Offline
                            Gillman
                            last edited by

                            Very intesting plug-in, and practical too. I was looking for a quick way to place a repeating element on a sphere (in this case Clint Howard's ship from Star Trek TOS "The Corbomite Manuver"). I edited the cube and replaced it with a pyramid with geodesic spheres at each angle.Fesperus.jpg

                            It turned what would have been a mind-numbing task into something trivial. Now all I have to do is upload it to the warehouse.

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              TheDro
                              last edited by

                              @Gillman: I'm glad to hear that it was of use to you.

                              @Khai: I've been looking at the structure of the .schematic file which is used to import structures into Minecraft using MCEdit. I think I've got it figured out but I still need to write the code and I'm reading the book of ruby to try and figure out the best way to do it.

                              @Everyone: I've added a new "spiral" algorithm to prevent interpreting sharp edges of solids as "entrances" to the solids. Basically, I improved the algorithm to work with more solids which is good. I'll upload the new version once I'm not too busy with work/school.

                              1 Reply Last reply Reply Quote 0
                              • 2 Offline
                                22curious
                                last edited by

                                @TheDro, the spiral refinement will be useful - looking forward to it - thanks!

                                1 Reply Last reply Reply Quote 0
                                • K Offline
                                  Khai
                                  last edited by

                                  thanks Dro 😄

                                  1 Reply Last reply Reply Quote 0
                                  • mitcorbM Offline
                                    mitcorb
                                    last edited by

                                    You will discover, while scaling an instance of a component, that the others do not scale accordingly, at least while using the native scale tool.

                                    I take the slow, deliberate approach in my aimless wandering.

                                    1 Reply Last reply Reply Quote 0
                                    • TIGT Offline
                                      TIG Moderator
                                      last edited by

                                      Scaling one Component Instance from the 'outside' won't affect other Component Instances of the same Component BUT scaling a Component Instance's 'contents' will change all Component Instances of that Component - that's because when you edit the contents of a Component Instance you change the Component Definition itself and this is repeated across all of its Instances]...

                                      TIG

                                      1 Reply Last reply Reply Quote 0
                                      • mitcorbM Offline
                                        mitcorb
                                        last edited by

                                        Aaah yes. Thank you. 😄

                                        I take the slow, deliberate approach in my aimless wandering.

                                        1 Reply Last reply Reply Quote 0
                                        • L Offline
                                          Lobster
                                          last edited by

                                          Thanks for this,

                                          Interesting plug in.

                                          voxelise.png

                                          1 Reply Last reply Reply Quote 0
                                          • Dave RD Offline
                                            Dave R
                                            last edited by

                                            Is there any chance of making this work to allow selection of a component as well as a group?

                                            Etaoin Shrdlu

                                            %

                                            (THERE'S NO PLACE LIKE)

                                            G28 X0.0 Y0.0 Z0.0

                                            M30

                                            %

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

                                            Advertisement