Hi everybody, I am a ruby beginner.
I have a small background in developpment.
I started this summer with the lecture of the book Automatic Sketchup, I look after exemples in this forum…but since few weeks i am face to a problem.
I want to make a list of components and I only succed to make a component in a component. My design look like a Russian doll.
this is my code exemple
# load "C:/ruby_scripts/CubeComponent.rb"
#First we pull in the standard api hooks
require 'sketchup.rb'
Sketchup.send_action "showRubyPanel:"
# Add a menu item to Launch our plugin
UI.menu("PlugIns").add_item("Cube") {
Sketchup.active_model.start_operation "Cube"
# Create a new layer
model = Sketchup.active_model
l_new = model.layers.add "Cube"
model.active_layer = l_new
#List of entities of the roof
cube1
cube2
}
def cube1
#Create the component definition
ents = Sketchup.active_model.entities
#Get handles to our model and the Entities collection it contains
model = Sketchup.active_model
entities = model.entities
x1 = 0
x2 = 1000.mm
y = 0
z1 = 0
z2 = 1000.mm
pt1 = [x1, y, z1]
pt2 = [x1, y, z2]
pt3 = [x2, y, z2]
pt4 = [x2, y, z1]
# Call methods on the Entities collection top drax stuff
new_face = entities.add_face pt1, pt2, pt3, pt4
new_face.pushpull 1000.mm
# Create a group and make it a component
cube1_group = ents.add_group ents.to_a
component_instance = cube1_group.to_component
definition = component_instance.definition
definition.name = "cube1"
end
def cube2
#Create the component definition
ents = Sketchup.active_model.entities
#Get handles to our model and the Entities collection it contains
model = Sketchup.active_model
entities = model.entities
x1 = 2000.mm
x2 = 3000.mm
y = 0
z1 = 0
z2 = 1000.mm
pt1 = [x1, y, z1]
pt2 = [x1, y, z2]
pt3 = [x2, y, z2]
pt4 = [x2, y, z1]
# Call methods on the Entities collection top drax stuff
new_face = entities.add_face pt1, pt2, pt3, pt4
new_face.pushpull 1000.mm
# Create a group and make it a component
cube2_group = ents.add_group ents.to_a
component_instance = cube2_group.to_component
definition = component_instance.definition
definition.name = "cube2"
end
could you give me hint? I am sure, it will look so obvious to you…
thank you in advance
Best regards,