• Login
sketchucation logo sketchucation
  • Login
πŸ”Œ Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

[Bug] Add_group inside a component

Scheduled Pinned Locked Moved Developers' Forum
19 Posts 5 Posters 698 Views 5 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.
  • M Offline
    Matt666
    last edited by 17 Mar 2009, 06:43

    It's been a long time I try to convert all components into groups by ruby... See here ...

    Yes, thomthom, bug appears when parent of entities to group are not model.
    I have made a set of tools for components and groups. One of these tools can convert one component into a group. It also works with sub components!! It works because you have to select it before conversion, and if you want to select, you have to enter in the first component. So SU parent is the component definition... so 'model.entities.add_group' works. Now tool I want to create could convert ALL components into groups. It works well with components with model parent, but there is a bug with the other components....
    Sorry for my poor english it's quite difficult to explain clearly what I noticed 😳 !

    Frenglish at its best !
    My scripts

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 17 Mar 2009, 07:47

      Ahh. Heh. Looks like I'm trying to reinvent the wheel. Even the name of the ruby 'tt_c2g.rb', is pretty much similar to the name of yours. πŸ˜„ I was looking in to this yesterday. I managed to convert components to groups in the current selection fine. Though after a few bugsplats as SU was picky to how it was created. grouping the component and exploding seemed like the way to go.

      From there I thought it'd be an easy process off just making an recursive method, but alas. two hours of bugsplats later it's no go. I quicly realised the many issues.

      My latest attempt was to avoid using .parent and manually keep track of the entities space which the group could be added to. But something is wrong. SU still bugsplats. It was getting quite late so I might have done some logical errors.

      I've attached my version of it. I've only worked on it yesterday, but the cursed thing is getting to me. It shouldn't be this hard.

      And IMO, the .parent of Groups and Components should not return the Definition. That's just wrong. We have .definition for that. I find it very odd that there's nothing to trace back the model space entities and components is placed in.


      Nested version bugsplats

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

      1 Reply Last reply Reply Quote 0
      • C Offline
        Chris Fullmer
        last edited by 17 Mar 2009, 08:02

        @thomthom said:

        And IMO, the .parent of Groups and Components should not return the Definition. That's just wrong. We have .definition for that. I find it very odd that there's nothing to trace back the model space entities and components is placed in.

        If I select a component and type:

        Sketchup.active_model.selection[0].parent

        it returns:

        #<Sketchup::Model:0xcf39148>

        I don't get a definition. If I am inside a component and then select a nested component and run that code then I get a ComponentDefiniction. But that is to be expected since I am inside a component. It is returning the parent of the selected component, which happens to be a component. And its parent is the Model.

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 17 Mar 2009, 08:24

          @chris fullmer said:

          I don't get a definition. If I am inside a component and then select a nested component and run that code then I get a ComponentDefiniction. But that is to be expected since I am inside a component. It is returning the parent of the selected component, which happens to be a component. And its parent is the Model.

          No, that's not the parent ComponentInstance. It's the definition of your selected ComponentInstance that's returned.

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

          1 Reply Last reply Reply Quote 0
          • M Offline
            Matt666
            last edited by 17 Mar 2009, 09:40

            tt_c2g!! 🀣

            @unknownuser said:

            And IMO, the .parent of Groups and Components should not return the Definition. That's just wrong. We have .definition for that. I find it very odd that there's nothing to trace back the model space entities and components is placed in.
            .parent (that returns the definition) is useful to know where we are. Inside a component, or not. However I think it's the .add_group function is bugged... We should be able to transform a component directly in its definition.
            I tried to create a group of all entities from the definition, and it create the group on the origin of the definition. And when you close the drawing, it bugs. So when you try this 'component.definition.entities.add_group(sub_component)' and you aren't inside this component on your model space, it bugs.
            PS : Sorry I don't know how to tell clearly when you are inside a component by double-clickinf on it... 😳

            Frenglish at its best !
            My scripts

            1 Reply Last reply Reply Quote 0
            • T Offline
              thomthom
              last edited by 17 Mar 2009, 09:56

              @matt666 said:

              However I think it's the .add_group function is bugged...

              Well, there sure is something about it, as the manual says: http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/entities.html#add_group

              @unknownuser said:

              NOTE: calling add_group with entities in its parameters has been known to crash SketchUp. It is preferable to create an empty group and then add things to its Entities collection.

              Though, how you go about not providing entities to the method's argument, I don't know. http://www.sketchucation.com/forums/scf/viewtopic.php?f=180&t=17153

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

              1 Reply Last reply Reply Quote 0
              • T Offline
                thomthom
                last edited by 17 Mar 2009, 09:57

                @matt666 said:

                I tried to create a group of all entities from the definition, and it create the group on the origin of the definition. And when you close the drawing, it bugs. So when you try this 'component.definition.entities.add_group(sub_component)' and you aren't inside this component on your model space, it bugs.

                Exactly the same as what I see. Wonder if we could summon a SU developer to provide some feedback.

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

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TIG Moderator
                  last edited by 17 Mar 2009, 12:07

                  # get the required component-definition and the required transformation...
                  g1 = model.active_entities.add_group
                  g1ents = g1.entities
                  g1ents.add_instance(component_definition,transformation)
                  g1ents.add_line([0,0,0],[1,1,1])
                  # this adds a component, then an edge...
                  # you can even add a group inside a group thus...
                  g2 = g1ents.add_group
                  triangle_face= g2.entities.add_face([0,0,0],[1,0,0],[0,1,0])
                  # etc etc...
                  
                  

                  ...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    Chris Fullmer
                    last edited by 17 Mar 2009, 15:23

                    How would you add existing geometry to a group though TIG? There is no entities.add_existing_entitiesmethod. or new_ents = entities.copy! or anything.

                    Lately you've been tan, suspicious for the winter.
                    All my Plugins I've written

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      TIG Moderator
                      last edited by 17 Mar 2009, 17:01

                      @chris fullmer said:

                      How would you add existing geometry to a group though TIG? There is no entities.add_existing_entitiesmethod. or new_ents = entities.copy! or anything.

                      model=Sketchup.active_model
                      g1=model.active_entities.add_group ### initially empty
                      g2=model.entities.add_group(model.selection)
                      ### or any other 'list' of miscellaneous geometry,
                      ### text, instances, groups, dims etc
                      g1.entities.add_group(g2)
                      g2.explode ### if required...
                      ### misc stuff moved into a group.
                      ### I know you can skip making g1 and just use g2
                      ### but here g1 is either 'pre-existing' or needed later...
                      ### OR
                      ### to copy items into a group, rather than move them
                      ### into a group you can use...
                      g1=model.active_entities.add_group ### initially empty
                      g2=model.entities.add_group(model.selection)
                      ### as above...
                      g3=g2.copy
                      g2.explode ### to restore originals back as they were...
                      g1.entities.add_group(g3)
                      g3.explode ### if required...
                      ### more misc stuff copied into a group.
                      ### I know you can skip making g1 and just use g2 and g3
                      ### but here g1 is either 'pre-existing' or needed later...
                      
                      

                      ...

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • C Offline
                        Chris Fullmer
                        last edited by 17 Mar 2009, 17:24

                        So the problem isn't with adding existing geometry to a group, it is with adding geometry to a group that is nested.

                        Seems like it should be quite possible then to find all nested components. Then find the deepest one. Then add its existing geometry to a new group created inside the component. Then explode the outer componentinstance. Thanks TIG (again and again and again)

                        Chris

                        Lately you've been tan, suspicious for the winter.
                        All my Plugins I've written

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          TIG Moderator
                          last edited by 18 Mar 2009, 20:08

                          Adding entities to a definition is bug ridden... you can try...

                          
                          g1=model.active_entities.add_group(model.selection)
                          component=instance.definition
                          g=component.entities.add_group(g1)
                          g.explode
                          g1.explode
                          
                          

                          to give you 'loose' stuff inside the component definition...
                          BUT when it Bug-splats it's NOT my fault !
                          It doesn't work because it's trying to move these grouped entities from their parent - the model - into the definition, which itself is another 'parent'. You CAN add new geometry or a group into a definition, BUT then to do that you need to add each of these bits as brand-new geometry. It would be possible to 'copy the info' of each of the group's entities as base-level entities and then recreate them inside the definition bit-by-bit, and at the end you can delete the original items since they are 'moved' into the definition... However, that's a pretty complex task... Info for every group, mining down into it's components, then info for each face, its edges, its materials, its layer etc etc...
                          We need a 'definition.entities.adopt(array_of_another_parents_entities)' method to transfer to another 'parent' ? I don't have time to do it right now - has anyone go one ???
                          ...

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • M Offline
                            Matt666
                            last edited by 18 Mar 2009, 20:13

                            ... Google? πŸ˜„

                            Frenglish at its best !
                            My scripts

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              TIG Moderator
                              last edited by 19 Mar 2009, 14:01

                              Work around...

                              I've go a half-baked script that might work. I'll post it in a separate thread soon...
                              ...

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • M Offline
                                Matt666
                                last edited by 20 Mar 2009, 09:03

                                Aaah... Cool!

                                Frenglish at its best !
                                My scripts

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

                                Advertisement