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

    Entities.add_group bug?

    Scheduled Pinned Locked Moved Developers' Forum
    17 Posts 3 Posters 681 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.
    • voljankoV Offline
      voljanko
      last edited by

      @thomthom said:

      To move the face, why not group it, get it's definition, then place a new instance in the destination context and erase the old.

      Can you give the code sample,please(how to group it).I would like to test it.

      SuSolid.com - solid check - solid repair- solid intersection check - weight plugin

      1 Reply Last reply Reply Quote 0
      • voljankoV Offline
        voljanko
        last edited by

        It's working!!
        I cannot believe it.I have a theory that nothing can work without testing.You are breaking this theory 😄

        SuSolid.com - solid check - solid repair- solid intersection check - weight plugin

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

          I always get uneasy when a code is run the first time without any errors... 😕 😒

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

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

            It's only 100% safe to make a group directly with
            ents.add_group(an_entities_array)
            [or (an_entity)]
            if the 'ents' is the model.active_entities OR the same 'entities context'
            Doing it across a mix of 'entities contexts' can cause Bugsplats ???
            So then you normally make an empty group
            group=ents.add_group()
            and then add the entities to its group.entities; either by cloning raw geometry etc; or if it's a component, by using
            instance2=group.entities.add_instance(instance.definition, instance.transformation)
            or if it's a group, by using
            group2=group.entities.add_instance(group.entities.parent, group.transformation)
            If you are not immediately erasing the original 'group' then run group2.make_unique on the new group because, otherwise they as as if they are components - changing one changing one changes the other - behavior not expected in groups which ought to only ever have one instance of their definition.

            TIG

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

              If making a temp group of the face in situ works for you and you can then add an instance of that into another context and explode it and then erase the original face-group then that's good 😄 ... but if it splats you need to do it by 'cloning' 😞

              TIG

              1 Reply Last reply Reply Quote 0
              • voljankoV Offline
                voljanko
                last edited by

                @thomthom said:

                I always get uneasy when a code is run the first time without any errors... 😕 😒

                Reading your code, the line

                group.erase
                

                makes me curious because the erase should be with the !.
                So I discover that it was only half the code working.
                But the result is ok.
                So the working code is:

                def move_face(face, destination_entities )
                  source_entities = face.parent.entities
                  entities = face.edges << face # I think you need to include all the edges related to the face
                  group = source_entities.add_group( entities )
                end
                

                So the untested code theory remains 😄
                I will test it more,because of the Bugsplat fear.

                SuSolid.com - solid check - solid repair- solid intersection check - weight plugin

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

                  You need to add the
                  ###... definition = group.entities.parent transformation = Geom::Transformation.new # Adjust to place where you want it. copy = destination_entities.add_instance( definition, transformation ) copy.explode # Ungroup the copied face group.erase**!** # Erase the original temp group
                  otherwise all your code does is move the face into a group that is in the in the same context the face was. I thought your aim was to move the face into another group ?
                  The method move_face( face, destination_entities ) takes the two arguments 'face' - the face to move; and 'destination_entities' - where you want it to end up - e.g. group2.entities...
                  Thomthom's clever face>group,add_instance,explode,delete_original idea should work in this set of circumstances, without recourse to cloning...Note that this method 'moves' the face, and leaves it un-grouped - just as it was originally but now within another entities-context - if you want to copy the face into a group then the code needs tweaking - instead of deleting the original face [that's been grouped] with group.erase! you use group.explode to return the original face to its un-grouped state.

                  TIG

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

                    <span class="syntaxdefault"><br />def move_face</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> face</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> destination_entities </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  source_entities </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">parent</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br />  entities </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">edges </span><span class="syntaxkeyword"><<</span><span class="syntaxdefault"> face </span><span class="syntaxcomment"># I think you need to include all the edges related to the face<br /></span><span class="syntaxdefault">  group </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> source_entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_group</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> entities </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  definition </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> group</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">parent<br />  transformation </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Transformation</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">new </span><span class="syntaxcomment"># Adjust to place where you want it.<br /></span><span class="syntaxdefault">  copy </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> destination_entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_instance</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> definition</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> transformation </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  copy</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">explode </span><span class="syntaxcomment"># Ungroup the copied face<br /></span><span class="syntaxdefault">  group</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">erase</span><span class="syntaxkeyword">!</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Erase the original temp group<br /></span><span class="syntaxdefault">end<br /></span>
                    

                    Note: completely un-tested. Just a theory

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

                    1 Reply Last reply Reply Quote 0
                    • voljankoV Offline
                      voljanko
                      last edited by

                      Grrr,it is only working if the group is edited (so in the same context).
                      Otherwise strange behaviour and Bugsplat anytime. 😢

                      SuSolid.com - solid check - solid repair- solid intersection check - weight plugin

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

                        As I suspected then... 😒
                        Using ents.add_group(ent_array) only works safely if ents==model.active_entities
                        So use my cloning tips... 😕

                        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