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

    [Bug] Add_group inside a component

    Scheduled Pinned Locked Moved Developers' Forum
    19 Posts 5 Posters 702 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.
    • Chris FullmerC Offline
      Chris Fullmer
      last edited by

      @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
      • thomthomT Offline
        thomthom
        last edited by

        @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

          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
          • thomthomT Offline
            thomthom
            last edited by

            @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
            • thomthomT Offline
              thomthom
              last edited by

              @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
              • TIGT Offline
                TIG Moderator
                last edited by

                # 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
                • Chris FullmerC Offline
                  Chris Fullmer
                  last edited by

                  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
                  • TIGT Offline
                    TIG Moderator
                    last edited by

                    @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
                    • Chris FullmerC Offline
                      Chris Fullmer
                      last edited by

                      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
                      • TIGT Offline
                        TIG Moderator
                        last edited by

                        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

                          ... Google? πŸ˜„

                          Frenglish at its best !
                          My scripts

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

                            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

                              Aaah... Cool!

                              Frenglish at its best !
                              My scripts

                              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