sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Add a group to another group by rupy-code

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 3 Posters 241 Views 3 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.
    • A Offline
      Andreas
      last edited by

      Hi,

      I would like to insert "Group1" into "Group2" by ruby-code.
      What should I do to make this work?

      With best regards from Germany

      Andreas

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

        Lets call them group1 and group2
        They must be in the same 'context'.
        You then use a newly made temporary group to contain both groups and manipulate all of the three groups as needed...

        context = group1.parent ### e.g. 'model'
        group_temp = context.entities.add_group(group1, group2)
        ### now transfer all group1's properties to group_temp
        ### you can skip those that are definitely not needed for YOUR groups...
        group_temp.name = group1.name
        group_temp.description = group1.description
        group_temp.layer = group1.layer
        group_temp.material = group1.material
        group_temp.hidden = group1.hidden?
        group_temp.visible = group1.visible?
        group_temp.locked = group1.locked?
        group_temp.casts_shadows = group1.casts_shadows?
        group_temp.receives_shadows = group1.receives_shadows?
        group_temp.glued_to = group1.glued_to
        attrdicts=group1.attribute_dictionaries
        attrdicts.each{|attrdict|
          name = attrdict.name
          attrdict.each_pair{|key,value|newMat.set_attribute(name,key,value)}
        }if attrdicts
        ### Note; if 'group1' HAD "observers" you now need to add them to 'group_temp' too...
        group1.explode
        ### this puts the 'group1.entities' at the correct 'level' in the new container.
        ### IF you want group2's entities 'loose', rather than as the group itself,
        ### then add 'group2.explode' too...
        group1 = group_temp
        ### 'group1' now refers to the 'combined group'
        ### that now includes the original 'group1.entities' AND 'group2'...
        ### or 'group2.entities' if you exploded it too.
        
        

        TIG

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          @andreas said:

          Hi,

          I would like to insert "Group1" into "Group2" by ruby-code.
          What should I do to make this work?

          Are you talking about existing groups? If so, refer to TIGs post.

          If you are creating new groups via Ruby:

          group1 = model.active_entities.add_group group2 = group1.entities.add_group

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          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