Ruby-Sketchup改变面孔的颜色

时间:2019-04-03 14:56:01

标签: ruby sketchup

我想用rfClr将此形状的顶部着色,有什么想法吗?我可以将整个东西更改为灰色,但是如何将顶部更改为蓝色?

l=100
w=60
h=20
hl=8
slope=4
clr='Gray'
rfClr='blue'
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, 0, h*12+hl]
    @pt2 = [w*12/2, 0, 12*h+hl+(w/2)*slope]
    @pt3 = [w*12, 0, 12*h+hl]
    @pt4 = [w*12, 0, 0]

newface = entities.add_face(@pt0, @pt1, @pt2, @pt3 , @pt4)
    newface.material=Sketchup::Color.new clr
#newface.reverse!
    newface.pushpull l*12

enter image description here

1 个答案:

答案 0 :(得分:1)

我找到了这个答案。 我想它会找到具有z值的面孔

vfaces = entities.grep(Sketchup::Face).find_all{|f| f.normal.z.abs != 0 }
vfaces.each{|f| f.material = rfClr }