I am using this, to add draw a box, then coloring the box.
l=96
w=60
h=60
clr='Gray'
ent = Sketchup.active_model.entities
#---------Clear All
Sketchup.active_model.entities.clear!
#----------------
model = Sketchup.active_model
model.start_operation "Create Box"
#-----------------------------------------------------------------------------
entities = model.active_entities
group = entities.add_group
entities = group.entities
group.name = "Box"
@pt0 = [0, 0, 0]
@pt1 = [0, l*12, 0]
@pt2 = [w*12.0, l*12, 0]
@pt3 = [w*12, 0, 0]
newface = entities.add_face(@pt0, @pt1, @pt2, @pt3)
newface.material = Sketchup::Color.new clr
newface.reverse!
newface.pushpull h*12
I would also like to add a texture but can't find how to do that.
Like "Metal Corrugated Shiny" but have not been able to find out how to do that.
Does anybody know how to add the texture with ruby?
The element that you want is Texture
. This is the class object that exposes information about image textures (such as width and height, average color, etc.).
The easiest way to set a texture is directly on the material.
newface.material = Sketchup::Color.new clr
newface.material.texture = "C:\\MyMaterialDirectory\\MyMaterial.jpg"
Obviously the file will need to be a valid image and in the appropriate directory.