sketchucation logo sketchucation
    • Login
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Counting Components

    scheduled pinned locked moved SketchUp Discussions
    sketchup
    13 Posts 7 Posters 8.5k Views 7 Watching
    loading-more-posts
    • oldest-to-newest
    • newest-to-oldest
    • most-votes
    reply
    • reply-as-topic
    guest-login-reply
    deleted-message
    • jgbJ Offline
      jgb
      last edited by

      There can be a problem with the entity info count. The count is correct, but you may have copies on invisible layers, or, duplicate coincident copies that look as only 1, which is very difficult to find.
      So if the count seems wrong, start hunting.

      To correct coincident copies, you need to delete a suspect. If it disappears, hit [undo]. If it remains, it was a duplicate. Do it again. In my early drawings I have had as many as 7 instances coincident, due to my inexperience then.

      One very difficult situation to fix is where you have multiple copies INSIDE the group or component envelope. The only way I know of fixing that is to open the group/comp and rebuild it line by line. Deleting co-incident lines does not always work, and this condition is a major cause of faces that do not form. You have endpoints that are very close together.


      jgb

      one-reply-to-this-post last-reply-time reply quote 0
      • AnssiA Offline
        Anssi
        last edited by

        Another way is via Window>Model Info>Statistics. Selecting "Show nested components" will show the correct figure even if you have components nested within groups and other components. The report can even be copied from the window and pasted into Excel, for instance.

        Anssi

        securi adversus homines, securi adversus deos rem difficillimam adsecuti sunt, ut illis ne voto quidem opus esset

        one-reply-to-this-post last-reply-time reply quote 0
        • JuantxoJ Offline
          Juantxo
          last edited by

          If you insert a group with an instance of a component inside, count_instaces method and ComponentDefinition.instances["instance"].length fails.

          http://www.youtube.com/watch?v=kLAAAK2_APc
          You need to enter inside the groups, then the number of instances is corrected.
          ¿Is there another way?

          one-reply-to-this-post last-reply-time reply quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            Select one instance of the component in your model.
            Paste this 'one-liner' into the Ruby Console - it should return the number of its instances correctly - including any 'nested' ones. Use the ideas to make a short script...

            p Sketchup.active_model.selection[0].definition.instances.length
            

            An instance inside a definition only gets counted the once - so that requires you to then find the number of the container-instances using a similar technique, and simply multiply the numbers together... 🤓

            TIG

            one-reply-to-this-post last-reply-time reply quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @tig said:

              Paste this 'one-liner' into the Ruby Console - it should return the number of its instances correctly - including any 'nested' ones.

              No - it doesn't account for nested instances.

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

              one-reply-to-this-post last-reply-time reply quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                @thomthom said:

                @tig said:

                Paste this 'one-liner' into the Ruby Console - it should return the number of its instances correctly - including any 'nested' ones.

                No - it doesn't account for nested instances.

                Well it does for me 😕
                Make a component and say 6 copies of it.
                Make a component of say 2 of them - we now have 4 in the model and 2 inside a definition.
                When I run the snippet - it returns 6... NOT 4 ?
                If you copy the second component the reported figure is still 6 since there are 2 in its definition.
                To get the total you need to count the number of instances which nest them...
                I don't see what you are saying ? It does work ??
                As I thought I explained the nested ones are only counted once and you need extra steps to count up their container instances too...

                TIG

                one-reply-to-this-post last-reply-time reply quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  @tig said:

                  If you copy the second component the reported figure is still 6 since there are 2 in its definition.
                  To get the total you need to count the number of instances which nest them...
                  I don't see what you are saying ? It does work ??

                  That's what I meant - it doesn't return the total number of instance you can see in the model when one or more of its parents also have instances.
                  I guess it depends on what you expect.

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

                  one-reply-to-this-post last-reply-time reply quote 0
                  • JuantxoJ Offline
                    Juantxo
                    last edited by

                    In the video you can see 3 rectangles, but count_instaces only returns 1. If you click all the groups to edit them and then exit, count_instances returns the
                    rigth number, 3 rectangles. I think count_instances method has a bug. ¿What do you think?

                    one-reply-to-this-post last-reply-time reply quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      @juantxo said:

                      In the video you can see 3 rectangles, but count_instaces only returns 1. If you click all the groups to edit them and then exit, count_instances returns the
                      rigth number, 3 rectangles. I think count_instances method has a bug. ¿What do you think?

                      No - it's not bug. It's as expected. When you copy a group you create an instance of that same group. Inernally in SU groups are like Component Instances but with the exception that when you edit (or open one) they are made unique.

                      In order to get the correct count you need to also count the instances of all the parents for each instance of the group you count.

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

                      one-reply-to-this-post last-reply-time reply quote 0
                      • JuantxoJ Offline
                        Juantxo
                        last edited by

                        I understand. You are the best

                        Thanks very much!

                        one-reply-to-this-post last-reply-time 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