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

[poss. BUG] Best-Fastest way to loop through all objects

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 2 Posters 447 Views 2 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.
  • P Offline
    Pout
    last edited by Pout 13 Nov 2008, 07:50

    Facts of our dev.

    1. In certain objects we store a generated ID in the data dictionary (Since the id from Sketchup changes each time you open the model)
    2. We have a list that contains some of those ID's
    3. We want to give all the objects that are in that list another color.

    Now.
    We have that working but it is slow, probabbly because:

    • We loop through all SU objects and see if their ID is listed in the list of ID's. So in some cases up to 99% of the loop is not necessary. Isn't it possible to make this faster? Instead of looping and checking each time, just like 'pick' them?
    • To change the color we have a procedure:
      check if the selected object is a group-entity-instance
    1. if entity: set material to red
    2. if group: go in the group and execute the procedureagain
    3. if instance; go in the instance and execute the procedureagain

    So we like go into the element, go to it's smallest 'part' and change the color of that part.
    It would off course be easy to just set the group material or instance material to red but that does not override the material of the elements in the group/instance.

    As you can imagine: if an instance contains a group and then another instance with 25 entities in that the loop tends to take a long time.
    What is the fastest way to loop through all objects?

    Thx ๐Ÿ˜„

    1 Reply Last reply Reply Quote 0
    • P Offline
      Pout
      last edited by 13 Nov 2008, 14:54

      from the previous procedure i think i have found a bug in SU:

      setup:

      1. create a square and extrude it
      2. make a component of it
      3. bring another instance of the component in the model
      4. make a group of those two
      5. duplicate the group

      Now when looping i have set a 'flag':
      the loop

      • when it is a face show messagebox with 'face' in it
      • when it is a group show messagebox with 'group' in it
        for each entity in the group execute the loop again
      • when it is a instance show messagebox with 'instance' in it
        for each entity in the instance definition execute the loop again

      Now this give me this result:
      messagebox group
      messagebox instance
      messagebox group (automatically goes away and immediately shows:)
      messagebox instance
      ...

      Now this is not correct.

      If, before i execute the loop, i just go into one of the two groups (just double click it and click next to it again) this is the result when executing the loop:
      messagebox group
      messagebox instance
      messagebox face (6 times)
      messagebox instance
      ...
      This is correct.

      Is there any know bug about this? It seems SU threats the loop differtly just based upon a single 'not changing anything' action.
      Can someone please verify? And maybe give some advise?
      Thx!!

      1 Reply Last reply Reply Quote 0
      • R Offline
        RickW
        last edited by 13 Nov 2008, 15:45

        There is a known bug in SU that copies of a group act like component instances unless the copies are individually edited manually, or you use group.make_unique in a script.

        If you don't do one of those two things, any changes to one group will be applied to all copies of the group.

        I suggest you first loop through the definitions and query each definition's instances to see if they are groups, and if so, call group.make_unique on each. This will make all groups unique and eliminate the problem.

        RickW
        [www.smustard.com](http://www.smustard.com)

        1 Reply Last reply Reply Quote 0
        • P Offline
          Pout
          last edited by 13 Nov 2008, 19:00

          Rick,

          Thank you very much. Is it possible that when you just go into a group the group is also made unique?
          As I understand i can do it like this:

          • when it is a group show messagebox with 'group' in it
            execute the make_unique command
            for each entity in the group execute the loop again

          Correct?
          Or should it be possible to handle groups and instances in one loop
          like: if it is a group or instance do...

          1 Reply Last reply Reply Quote 0
          • R Offline
            RickW
            last edited by 14 Nov 2008, 21:30

            I would structure it like this:

            1. loop through the definitions
              a. if a definition has multiple instances,
                 i. if they are groups, make them all unique, then loop through the only remaining group's entities and paint everything that's not a group or component
                 ii. if they are component instances, loop through the definition's entities and paint everything that's not a group or component
              b. if a definition has a single instance, loop through the entities (of the group if it's a group, or of the definition, if it is a component instance) and paint everything that's not a group or component
            2. loop through the model.entities and paint everything that's not a group or component instance
            

            Based on my experience with bomb.rb (which explodes all groups and components in a model), it is always faster to parse the definitions than it is to recursively parse groups and components from the entities list.

            RickW
            [www.smustard.com](http://www.smustard.com)

            1 Reply Last reply Reply Quote 0
            • P Offline
              Pout
              last edited by 17 Nov 2008, 08:06

              ah thx, will give that a try ๐Ÿ˜„
              see if it goes faster

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

              Advertisement