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

    Merge groups

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

      Hello.

      It's possible merge two groups into one group via ruby? Thanks.

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

        Yes.
        If the two groups are in the active_entities context then
        group2=group0.parent.entities.add_group([group0, group1])
        will work - however, if they are not in the active_entities context if will Bugsplat! big time!!!
        Adding any entities to a group directly will cause disasters IF you cross-thread the entities' contexts. So it's always safer to use this way - you can write a method to use it repeatedly...

        def combine_groups(ents,group0,group1)
          d0=group0.entities.parent
          t0=group0.transformation
          d1=group1.entities.parent
          t1=group1.transformation
          group2=ents.add_group()
          g0=group2.entities.add_instance(d0,t0)
          g1=group2.entities.add_instance(d1,t1)
          ### remember the originals properties as needed
          l0=group0.layer
          m0=group0.material
          n0=group0.name
          d0=group0.description
          attrdicts0=g0.attribute_dictionaries
          g0.layer=l0
          g0.material=m0
          g0.name=n0
          g0.description=d0
          attrdicts0.each{|attrdict|
            name=attrdict.name
            attrdict.each_pair{|key,value|g0.set_attribute(name,key,value)}
          }if attrdicts0
          l1=group1.layer
          m1=group1.material
          n1=group1.name
          d1=group1.description
          attrdicts1=g1.attribute_dictionaries
          g1.layer=l1
          g1.material=m1
          g1.name=n1
          g1.description=d1
          attrdicts1.each{|attrdict|
            name=attrdict.name
            attrdict.each_pair{|key,value|g0.set_attribute(name,key,value)}
          }if attrdicts1
          ###
          group0.erase!
          group1.erase!
          ###
          return [g0, g1, group2]
        end#def
        

        The usage is then
        ents=group0.parent.entities ### or any entities context required group0,group1,group2 = combine_groups(ents,group0,group1)
        Where the references group0 and group1 are transferred to the new instances of the groups, and group2 is the combined group containing them both.
        If you want the contents of those two groups to merge then simply add this after the combine_groups line of code
        group0.explode group1.explode
        The contents of the new group2 are the combined entities of the now defunct group0 and group1...

        TIG

        1 Reply Last reply Reply Quote 0
        • C Offline
          csharp
          last edited by

          TIG thank you 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