sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Change color entity group

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 538 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.
    • Y Offline
      ymagrini
      last edited by

      Hi!
      I need your help. I'am beginner and need change color to entity group by Ruby.
      I Attach the entity that I need change color.

      How can find this object and then change color?
      Thanks.
      Best regards, from Argentina!


      entity

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        You need to find the group.

        There are several methods, depending on how your 'tool' is getting its information...
        a. group = Sketchup.active_model.selection[0] assuming one group is selected...
        Assuming my_name = "Grupo#72"
        b. group = Sketchup.active_model.active_entities.grep(Sketchup::Group).select{|g| g.name = my_name }[0]
        which gives you the first group of that name in the current active entities context...
        c. named_groups = [] Sketchup.active_model.definitions.select{|d| d.group? }.each{|g| g.instances.each{|i| named_groups << i if i.name == my_name }}
        Now you have an array of all groups named ' my_name'
        Often there will be only one... but you CAN rename several groups with the exact same name !
        If you are sure then there'll only be one, then group = named_groups[0]

        Let's us assume you have a ' group' reference...

        Now you need to get a material...
        There are several ways to get a reference to the material...

        Assuming my_material_name = "My_Lovely_Material"
        a. material = Sketchup.active_model.materials[my_material_name]
        If it returns nil then it doesn't exist.
        Otherwise it's a reference to that material.
        b. To make the new material use:
        ` if material = Sketchup.active_model.materials[my_material_name]

        do stuff with 'material'

        else ### make the new 'material'
        material = Sketchup.active_model.materials.add(my_material_name)
        material.color = [123, 123, 123] ### some RGB value
        end`

        Now you have the references to the group and the material, use them thus...
        group.material = material


        There are many ways to skin a cat... πŸ˜‰

        TIG

        1 Reply Last reply Reply Quote 0
        • Y Offline
          ymagrini
          last edited by

          Excelente!
          Thanks very much!

          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