Two different colors to the same shape  Topic is solved

Two different colors to the same shape

Postby davesexcel » Wed Apr 03, 2019 3:08 pm

SidesGrey.jpg
With this code I am drawing a box and a box top, I am coloring the box gray and the top blue. I just require the top to be blue, the sides of the top need to be grey.
Code: Select all
l=96
w=60
h=60
heel=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, 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
       group = entities.add_group
    entities = group.entities
       group.name="Top"
#-----------Top----------------
    @pt0 = [0, 0, h*12]
    @pt1 = [0, 0, h*12+heel]
    @pt2 = [w*12/2, 0, 12*h+heel+(w/2)*slope]
    @pt3 = [w*12, 0, 12*h+heel]
       @pt4 = [w*12, 0, 12*h]
newface = entities.add_face(@pt0, @pt1, @pt2, @pt3, @pt4)
    newface.material=Sketchup::Color.new rfClr

    newface.pushpull l*12
0

davesexcel 
 

Re: Two different colors to the same shape  Topic is solved

Postby TIG » Wed Apr 03, 2019 4:53 pm

Please use 'code' blocks to format long Ruby extracts.
I've fixed your post for you this time...

You need to find all 'vertical' faces in the group named 'Top'.
After the last part of the code add this...
Code: Select all
vfaces = entities.grep(Sketchup::Face).find_all{|f| f.normal.z == 0 }
vfaces.each{|f| f.material = clr }
1
TIG
User avatar
TIG 
Global Moderator
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: Steppen and 7 guests

Visit our sponsors: