sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Two different colors to the same shape

    Scheduled Pinned Locked Moved Developers' Forum
    2 Posts 2 Posters 12.9k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D Offline
      davesexcel
      last edited by

      SidesGrey.jpgWith 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
      
      1 Reply Last reply Reply Quote 0
      • TIGT Online
        TIG Moderator
        last edited by

        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 }
        
        

        TIG

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement