Importing multiple models on a specific pivot point

Hi everyone,

Im developping an extension for the company i work for.
basicly what the extension should do, is:

when the extension is launched a textbox should appear, prompting the user for the amount of pannels (the model) horizontally and veritcally. then i need the extension to Make a grid like structures with the right amount horizontal and vertical “copies”.

This is what i have now: but i’m struggeling finding a solution to set a specific location for the imported model.

thanks in advance

You have the right idea but the wrong API method. You want to load a ComponentDefinition from a file into the DefinitionList, then add an instance of the definition to the model at some location. Not tested, just going from memory…

model = Sketchup.active_model
definition_list = model.definitions
component_definition = definition_list.load('C:\Users\sande\Desktop\Bematrix skp plugin\606 ++++ ++++ 30.skp')
location = Geom::Point3d.new(0, 0, 0)
component_instance = model.active_entities.add_instance(component_definition, location)

Also the UI.inputbox is “type-aware” meaning if the default types are String objects then it returns String objects, but if you use Integers you will get Integers back in the return value. This means defaults = ["1", "1"] can be defaults = [1, 1] Otherwise you need to convert the strings to integers like this: horizontal = input[0].to_i

Here’s a working example using arbitrary spacing along the X axis:


require 'sketchup.rb' 
#------------------------------------------------------------------------  

UI.menu("Plugins").add_item("Bemat Iwall") {

  # load a component definition into the model's definition list.
  model = Sketchup.active_model
  defn = model.definitions.load('C:\Users\Jim\SketchUp\models\Wall.skp')
  
  #Creating an input textbox for rows and columns
  prompts = ["Horizontal", "vertical"]
  defaults = [1, 1]
  input = UI.inputbox(prompts, defaults, "Wall specifications")
  horizontal = input[0]
  vertical = input [1]
  
  
  #for loop create multiple copies  
  for i in 0..horizontal
  
    # add instances of the definition
    model.active_entities.add_instance(defn, [i * 50, 0, 0])
  
  end
}
#------------------------------------------------------------------------

1 Like

Wow great answer, i think i get it now,
i am still not adjusted to the ruby api i guess haha

and i didn’t know this about the textboxes, i was going to try type casting it.

I’ll try this tomorrow as soon as i have the chance!

Kind regards.