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

    Entity.parent gives wrong type

    Scheduled Pinned Locked Moved Developers' Forum
    20 Posts 3 Posters 1.0k Views
    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.
    • S Offline
      spring.freediver
      last edited by

      Is there a known bug with the Entity.parent method (in SU7.1)?

      I use the InputPoint.face method to get the face a user picks, then the face.parent method to get the Group the face is in. But the API returns a Sketchup::ComponentDefinition object rather than a Group. I am sure that the face I am selecting is in a Group, not a Component. In fact, my model has no components at all.

      AM I doing this wrong?

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

        A group is actually an instance of a definition too.
        So the 'result' is 'correct'...
        You can test it with if result.group? and then if true use group=result.instances[0]
        Awkward but doable...

        TIG

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

          What you need to do is use the PickHelper - it will let you scan through the possible pick paths ( ph.path_at(n) ) for the face you picked.

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

          1 Reply Last reply Reply Quote 0
          • S Offline
            spring.freediver
            last edited by

            Thanks very much guys. I didn't know that groups were actually components. Nor that the group? method existed.

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

              You also have .image? as Image entities are instances of ComponentDefinition as well.

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

              1 Reply Last reply Reply Quote 0
              • S Offline
                spring.freediver
                last edited by

                Thomas,

                Does the PickHelper.transformation_at give the tranformation to transform back to model coordinates, or do you have to apply the transforms for each level?

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

                  ph.transformation_at(n) gives you the total transformation for the leaf_at(n). If you need the transformation for an item in one of the paths you need to calculate that yourself.

                  I'm attaching the pick_helper test I used to familiarize myself with the pickhelper.
                  The API docks doesn't explain very well the pick paths - and methods like ph.all_picked as it only returns all the possible pickswithin current context - not all the entities you get via the paths.
                  I tried to make a diagram over the PickHelper - but it didn't do so well... ๐Ÿ˜ณ ๐Ÿ˜’


                  tt_picktest.rb

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

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    spring.freediver
                    last edited by

                    Thanks Thomas, that's very helpful.

                    I've seen several scripts lately with a reload method. That seems like a good idea too. What calls the reload? Do you have some sort of "master" script that calls the various reloads?

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

                      @spring.freediver said:

                      Thanks Thomas, that's very helpful.

                      I've seen several scripts lately with a reload method. That seems like a good idea too. What calls the reload? Do you have some sort of "master" script that calls the various reloads?

                      No - but I intend to. Some weeks ago I started organizing all my plugins in a new way - they are all under TT::Plugins - so I can iterate the TT::Plugins module for child-modules and call reload on them.
                      But at the moment I just type in the console TT::Plugins::PluginName.reload. (Or make a temp menu/toolbarbutton)

                      I started adding a .reload because when developing I've started to place my plugins in isolated folder as another location - which a proxy loaded scans and loads. That let me set up subversion etc for each project.

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

                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        spring.freediver
                        last edited by

                        TIG,

                        If I get a face (or edge) from an inputpoint, and see that it's parent is a ComponentDefinition, I can use parent.group? to see if it is actually a group, and then know that there is only one instance, in parent.instances[0].

                        But, if parent.group? is false, I then know that it really is a component, and there may be multiple instances. Is there a way to find out which instance the selected face came from, and therefore what transformation needs to be applied? Is this a case where the PickHelper must be used because it is the only way to get the information?

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

                          @spring.freediver said:

                          TIG,
                          If I get a face (or edge) from an inputpoint, and see that it's parent is a ComponentDefinition, I can use parent.group? to see if it is actually a group, and then know that there is only one instance, in parent.instances[0].

                          No - groups can have multiple instances. If you copy a group around you see that Entity Info lists how many copies there are.
                          The only difference between Groups and ComponentInstances is that SU automatically makes Group instances unique when you edit them.

                          @spring.freediver said:

                          Is this a case where the PickHelper must be used because it is the only way to get the information?

                          Yes- PickHelper to get entities, InputPoint to get 3d coordinates.

                          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

                            I'm reluctant to post this, as it caused more confusion that anything else - but just in case: http://forums.sketchucation.com/viewtopic.php?f=180&t=30232

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

                            1 Reply Last reply Reply Quote 0
                            • S Offline
                              spring.freediver
                              last edited by

                              Thomas,

                              Your description that group component definitions can have multiple instances does not make sense to me. I think that when you make copies of a group, each copy has it's own definition. That is what allows you to change the geometry in one copy, and the change is not seen in the other copies. Each group has it's own set of entities.

                              But with components, there are multiple instances that refer to a single component definition, and share a set of entities. So if you change any of the entities in the component definition, the change is seen in all of the instances.

                              That is why it surprised me to learn that groups are actually component instances inside the Sketchup model. But I assumed that meant that they are "special" components that can only have one instance. And the group? method tells you that this is the case. If group? is false, then it is a "normal" component, which can have multiple instances, which led to my question about how to figure out which instance a given entity came from. I am starting to believe that it is not possible to tell if you only have an entity address, and that is why you must use a PickHelper.

                              Thanks again for your help... You are truely a Sketchup Pro

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

                                @spring.freediver said:

                                I think that when you make copies of a group, each copy has it's own definition.

                                Incorrect.

                                When you make a copy of a group, the copy does not get its own definition. It will share the definition of the group instance you copied from. You can see this by inspecting the definition's instance count after making a group copy.
                                (It's why my Selection Toys plugin allows you to convert group copied into component instances - because SU keeps the definition references.)

                                The catch here is that when you use the native SU tools to modify a group SU makes that group instance unique.
                                But, if you modify a group via Ruby, then you modify all instance! ๐Ÿ˜ฎ This is why we have the Group.make_unique which we must call if modifying groups. (SU will output a deprecated warning in the console - but there really is no other means around this.)

                                @unknownuser said:

                                Group.make_unique
                                The make_unique method is a deprecated method used to force a group to have a unique definition.

                                Copying a group using the copy tool in SketchUp will create copies of the group that share a common definition until an instance is edited manually or this method is used. If multiple copies are made, all copies share a definition until all copies are edited manually, or all copies have this method used on them. This method ensures that the group uses a unique definition entry in the drawing database.

                                Beware: Group.entities.parent can on occasions return an incorrect definition! See this thread for more info and workaround: http://forums.sketchucation.com/viewtopic.php?t=19765

                                @spring.freediver said:

                                I am starting to believe that it is not possible to tell if you only have an entity address, and that is why you must use a PickHelper.

                                Yes - you do need some way to return the path for the entity.

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

                                1 Reply Last reply Reply Quote 0
                                • S Offline
                                  spring.freediver
                                  last edited by

                                  Wow, that is even stranger. Especially the part about changing a group in Ruby is different that changing one in Sketchup.

                                  Before I read your post, I had written a script to loop through the model.definitions and report how many instances each had. I saw that after copying a group, the corresponding definition had multiple instances. But then I changed the geometry of each of the copies, and re-wrote the definition list. There were now separate definitions for each of the copies, with one instance each. So Sketchup does the "make unique" as soon as it sees you make a change to one of the copies of a group.

                                  So it seems that Sketchup really doesn't have a unique entity that is a group. It just has component definitions and instances, and a special flag on the definition that says to make it "act" like a group. And if any instances of the definition get changed (interactively), it makes a new definition and instance, so it is still just another component with a "group" flag on it.

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

                                    Yup - and you can use an Image definition and Group definition along with entities.add_instance.

                                    I'm guessing the behaviour of group instances is to preserve resources....

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

                                    1 Reply Last reply Reply Quote 0
                                    • S Offline
                                      spring.freediver
                                      last edited by

                                      I have also noticed that the Instance.name method sometimes returns an empty string. In the outliner, I see the correct name, but when I traverse the instances in Ruby, and print out each instances name, I get a blank string for one of the groups. And I get the blank string whether I refer to it as an instance or a group (I assume that calls to Group.name and Instance name are actually the same.)

                                      Is this a known bug? Is there any kind of work-around?

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

                                        Both definitions and instances has a .name method.

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

                                        1 Reply Last reply Reply Quote 0
                                        • S Offline
                                          spring.freediver
                                          last edited by

                                          Yes, but the Instance.name method is returning an empty string. The Definition.name method returns a name like "Group#5".

                                          This code is traversing the model hierarchy. For most groups and instances, it gets the correct name. But for one particular group, the name method returns an empty string. That is why I thought it might be a known bug.

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

                                            If you make a group into a component it will take the original 'Group#nn' name as the definition's name.
                                            You have to use definition.name="new_name" to change it to something else.
                                            When you place an instance you can give that a separate name [Entity Info].
                                            So you can have a component definition named "My_component" and the instances of it can also have their own names "v1", "v2" etc...

                                            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