Two different colors to the same shape
-
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.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 -
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...vfaces = entities.grep(Sketchup;;Face).find_all{|f| f.normal.z == 0 } vfaces.each{|f| f.material = clr }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement