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

    Duplicate Faces?

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 4 Posters 621 Views 4 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.
    • J Offline
      jasef
      last edited by

      I'm seeing a serious defect in a sizable fraction of SketchUp models, namely the existence of duplicate faces.

      By "duplicate", I mean, forFace a and Face b:

      • The .to_s method returns the same string for a and b* .entityID is identical for a and b* Setting an custom attribute or changing Face properties affects both Face a and Face b

      Note: The two faces are distinct visually and not connected or overlapping.

      This makes a number of model manipulations impossible.
      It's well known that the entityIDs of Faces are not persistent (and maybe not unique?), but this is far worse: saving references to Faces (for example, in a hash map with the key a custom ID attribute) is useless because one reference is referring to two faces.

      In case this still isn't clear, here is the output of printing the string representation of all the Faces in a simple model (and also the entityID):

      @unknownuser said:

      face=#Sketchup::Face:0xf464498, id=52
      face=#Sketchup::Face:0xf464498, id=52
      face=#Sketchup::Face:0xf464240, id=98
      face=#Sketchup::Face:0xf464128, id=1827
      face=#Sketchup::Face:0xf464010, id=1841
      face=#Sketchup::Face:0xf463f34, id=1848
      face=#Sketchup::Face:0xf463e58, id=1855
      face=#Sketchup::Face:0xf463d68, id=1863

      The duplicate faces above (two windows) are both part of separate Groups; I haven't seen this bug in models without groups. If you continually select all entities in the model and "explode", the Faces are then all unique. So basically, this bug is likely due to Groups of Faces.

      Any thoughts?

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

        o_O

        You got a sample model?

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

        1 Reply Last reply Reply Quote 0
        • Chris FullmerC Offline
          Chris Fullmer
          last edited by

          It could have to do with groups when they are first copied, the entity info window shows there being 4 of a single group in a model, which is absurd since groups in theory don't have copies. But until you double click on it, it counts itself as an instance of the group. So maybe that group instancing has something to do with it?

          Chris

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            Ahh, yes. I can duplicate it. Make a face, turn it into a group. Then copy that group. Then list the id's of the faces inside the two groups and they faces share the same id. They do not share the same group parent. So I suppose you could test for that.

            It looks like once the group no longer things its an instance then the faces become unique.

            Chris

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

            1 Reply Last reply Reply Quote 0
            • Chris FullmerC Offline
              Chris Fullmer
              last edited by

              And here's how you fix it, with make_unique.

              https://developers.google.com/sketchup/docs/ourdoc/group#make_unique

              Depending on what you're doing in your script, you might go through and make all groups unique before finding all the faces. Group definitions are listed in the model definitions collection. So if you iterate through the definitions, find the ones that are groups, then determine if they have more than one instance in the model, you can then make all their instances unique. Here's a working snippet.

              defs = Sketchup.active_model.definitions
              
              defs.each do |e|
               if e.group?
                instances = e.count_instances
                if instances > 1
                  e.instances.each do |ee|
                    ee.make_unique
                  end
                end
               end
              end
              

              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

                Oh! I thought it was two faces in the same context!

                Yes - Groups are just like ComponentInstances - you'll see the same behaviour there.

                Have a look at this article I wrote a while back about definitions and instances in SketchUp: http://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/
                It details the relationship and describes the special instances, Group and Image.

                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

                  When you duplicate a group manually [or in code] then you have two instances of it.
                  You can see this if you select the original group [or the copy] and use 'Entity Info', it says there are two in the model.
                  The faces etc inside this copy will all have the same id-references as the ones in the original group - because they are the very same definition !
                  Logically SketchUp should automatically make the group.copy into a unique instance of a new definition: but it doesn't.
                  If you manually edit that copy and close [without making any changes at all] it will become a unique instance of another definition - Entity Info will now say that there's only one instance of the original group, and/or that copy.
                  The faces etc inside this new definition will all have different id-references compared to the original group's definition, because they are no longer connected through that definition.
                  In code you can't 'edit/close' the copy, BUT you can do what Chris suggests.
                  This ensures you only ever have one instance of a copied group, so there's only ever one face reported with a particular id-reference etc.
                  Be prepared for some spurious warnings in the Ruby Console when you use the group.make_unique method - along the lines of "warning: make_unique is a deprecated method of group" - however, it works successfully. The API thinks you shouldn't ever need to use it, but since SketchUp doesn't run an auto-make_unique on group copies then you do need to use it to fix the anomaly !

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    jasef
                    last edited by

                    Awesome gents, make_unique solved it.

                    Much thanks!

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

                      @jasef said:

                      Awesome gents, make_unique solved it.

                      What about ComponentInstances?

                      I hope you're not making them uniqe - as I doubt the user will be expecting that - or be happy to see that happening...

                      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
                        jasef
                        last edited by

                        @thomthom said:

                        @jasef said:

                        Awesome gents, make_unique solved it.

                        What about ComponentInstances?

                        I hope you're not making them uniqe - as I doubt the user will be expecting that - or be happy to see that happening...

                        No, just Groups.

                        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