• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Counting Components

Scheduled Pinned Locked Moved SketchUp Discussions
sketchup
13 Posts 7 Posters 8.4k 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.
  • J Offline
    JoelM3DM
    last edited by 7 May 2010, 10:54

    I have a model with a component that's repeated hundred of times (little LED lights). I need to figure out how many lights there are. I could could the instances, but there must be an easier way. Is there a utility that will count the number of a specific component in a model? -- Joel


    ceiling lights3.jpg

    || Joel Metzger 3D Modeling
    || story-shorts.net - Animation with SU

    1 Reply Last reply Reply Quote 0
    • M Offline
      massimo Moderator
      last edited by 7 May 2010, 11:16

      Joel, just right click-->entity info on your component. 😄


      Cattura.JPG

      1 Reply Last reply Reply Quote 0
      • J Offline
        JoelM3DM
        last edited by 7 May 2010, 11:28

        Oh!

        || Joel Metzger 3D Modeling
        || story-shorts.net - Animation with SU

        1 Reply Last reply Reply Quote 0
        • J Offline
          jgb
          last edited by 8 May 2010, 20:40

          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

          1 Reply Last reply Reply Quote 0
          • A Offline
            Anssi
            last edited by 11 May 2010, 17:21

            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

            1 Reply Last reply Reply Quote 0
            • J Offline
              Juantxo
              last edited by 14 Feb 2011, 07:40

              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?

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 14 Feb 2011, 09:29

                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

                1 Reply Last reply Reply Quote 0
                • T Offline
                  thomthom
                  last edited by 14 Feb 2011, 09:41

                  @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

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    TIG Moderator
                    last edited by 14 Feb 2011, 10:11

                    @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

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      thomthom
                      last edited by 14 Feb 2011, 10:21

                      @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

                      1 Reply Last reply Reply Quote 0
                      • J Offline
                        Juantxo
                        last edited by 14 Feb 2011, 11:34

                        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?

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          thomthom
                          last edited by 14 Feb 2011, 11:40

                          @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

                          1 Reply Last reply Reply Quote 0
                          • J Offline
                            Juantxo
                            last edited by 14 Feb 2011, 12:15

                            I understand. You are the best

                            Thanks very much!

                            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