# Creates "cloud of points" from input-file # # Copyright 2008, Henry Palonen henry.palonen@gmail.com # # Made mainly for Finnish eCars-Now! electric car conversion project # to display 3D-measurements taken from EV-cars. # # For more information about the EV-project, please see: http://www.sahkoautot.fi/eng # # # # # # # # # # # # # Usage Instructions: # # 1. Put this file to the plugins directory. For Mac OS X it's # # '/Library/Application Support/Google SketchUp 7/SketchUp/plugins' # # for other os's out there, please see the Google SketchUp documentation to determine # correct path. # # 2. Launch the Google ScetchUp. There should be "Plugins"-menu item available # 3. From the Plugins-menu, choose "Plugins->Import Point Cloud from File" # 4. Enter file name that contains the point-data # # data should be in format X Y Z, separated by spaces # # For example # # -669.5391 -263.8589 -229.9035 # -1367.9122 -971.0400 -1229.7052 # -1677.9938 -1286.3921 -1673.9830 # -292.1946 50.6521 137.0593 # ... # # 5. It takes a while, but there should be cloud of points in your application after the script is run. # # (6. If needed, you can debug the script by launcing Ruby-console from SketchUp and issuing commands # # load 'pointcloud.rb' # create_point_cloud # # Happy modeling ! # # Henry Palonen, 18.11.2008 / henry.palonen@gmail.com # # # # # # # # # # # # # Based on Google's Examples # Copyright 2005-2008, Google, Inc. # This software is provided as an example of using the Ruby interface # to SketchUp. # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted, provided that the above # copyright notice appear in all copies. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- require 'sketchup.rb' #----------------------------------------------------------------------------- def create_point_cloud # Prompt for the filename. # File should contain points separated with spaces prompts = [$exStrings.GetString("Filename")] values = ['/tmp/data.dat'] results = inputbox prompts, values, $exStrings.GetString("Filename ?") return if not results # This means that the user canceld the operation filename = results.first # Now we can actually create the new geometry in the Model. There are # a number of ways that we could actually create the geometry. We will # show a couple of ways. # The first thing that we will do is bracket all of the entity creation # so that this looks like a single operation for undo. If we didn't do this # you would get a whole bunch of separate undo items for each step # of the entity creation. model = Sketchup.active_model model.start_operation $exStrings.GetString("Create point cloud") # We will add the new entities to the "active_entities" collection. If # you are not doing a component edit, this will be the main model. # if you are doing a component edit, it will be the open component. # You could also use model.entities which is the top level collection # regardless of whether or not you are doing a component edit. entities = model.active_entities # If you wanted the box to be created as simple top level entities # rather than a Group, you could comment out the following two lines. group = entities.add_group entities = group.entities # width, height and depth of the boxes. width = 10 depth = 10 height = 10 # now we read the file and create one box per one point open(filename, "r+") { |file| while (l = file.gets) do x = l.split(" ")[0] y = l.split(" ")[2] z = l.split(" ")[1] if (x != nil && y != nil && z != nil) x = x.to_f y = y.to_f z = z.to_f puts(x,y,z) # First we will create a rectangle for the base. There are a few # variations on the add_face method. This uses the version that # takes points and automatically creates the edges needed. pts = [] pts[0] = [0+x, 0+y, 0+z] pts[1] = [width+x, 0+y, 0+z] pts[2] = [width+x, depth+y, 0+z] pts[3] = [0+x, depth+y, 0+z] base = entities.add_face pts # Now we can do the pushpull base.pushpull height # Now we are done and we can end the operation model.commit_operation end end } end # This shows how you can add new items to the main menu from a Ruby script. # This will add an item called "Box" to the Create menu. # First check to see if we have already loaded this file so that we only # add the item to the menu once if( not file_loaded?("pointcloud.rb") ) # This will add a separator to the menu, but only once #Note: We don't translate the Menu names - the Ruby API assumes you are #using English names for Menus. add_separator_to_menu("Plugins") # To add an item to a menu, you identify the menu, and then # provide a title to display and a block to execute. In this case, # the block just calls the create_box function UI.menu("Plugins").add_item($exStrings.GetString("Import Point Cloud from File")) { create_point_cloud } end #----------------------------------------------------------------------------- file_loaded("pointcloud.rb")