sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Face.clone

    Scheduled Pinned Locked Moved Developers' Forum
    16 Posts 6 Posters 4.5k Views 6 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.
    • thomthomT Offline
      thomthom
      last edited by

      I thought adding existing geometry to groups made SU go rampage and bugsplat?

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

      1 Reply Last reply Reply Quote 0
      • K Offline
        kwalkerman
        last edited by

        I think that creating it as a group (and I may have a few faces), copying the group and then exploding the group is my best option. I don't want to use the first method because if I have another face (or sub-face if you want to think of it that way) in the hole, and I copied the sub-face first, then deleting the center of the hole will delete the face in the middle.

        It just seemed to me that there should be a simpler way to do this.

        I just tried TIG's method, and it works, although I have had a problem creating and exploding groups using the webconsole. The exact same script that will splat in the webconsole will run fine if I create an external rb file. I think this may be fixed in the next release?

        Thanks as always for your help!!

        --
        Karen

        1 Reply Last reply Reply Quote 0
        • Didier BurD Offline
          Didier Bur
          last edited by

          Hi,
          Here is my code for it, i used it a while ago and it seems to do its job, no matter the number of holes in the face

          Call with: clone_face=face.copy(v,d,ents)

          assuming face is a face objet, v param is a vector3d object (direction of copy), d is a distance of copy along vector v, and ents is an entities object (in what entities collection to add the copied face). Normal is preserved.

          class Sketchup;;Face
          def copy(vec,dist,ents)
            ov=[]
            vec.length = dist if dist != 0
            self.outer_loop.vertices.each do |v|
              if dist != 0
                ov.push(v.position.offset(vec))
                else
                ov.push(v.position)
              end
            end
            outer_face = ents.add_face ov
            inner_faces = []
            if self.loops.length > 1
              il = self.loops
              il.shift
              il.each do |loop|
                ov=[]
                loop.vertices.each do |v|
                  if dist != 0
                    ov.push(v.position.offset(vec))
                    else
                    ov.push(v.position)
                  end
                end
                inner_face = ents.add_face ov
                inner_faces.push(inner_face)
              end
              inner_faces.each do |f|
                f.erase!
              end
            end
            return outer_face
          end
          end # Class Face
          

          Hope this helps,

          DB

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

            @thomthom said:

            I thought adding existing geometry to groups made SU go rampage and bugsplat?

            It does, BUT NOT if you make, copy and explode the group immediately - many of my tools use this method without issues. It will Bugsplat if you try and do too much with these grouping, and especially if you try and group entities across sets - try and see -it won't splat... πŸ˜‰

            PS: The advantage of this method is that the face's material[s], layer and attributes are kept automatically.

            TIG

            1 Reply Last reply Reply Quote 0
            • Didier BurD Offline
              Didier Bur
              last edited by

              A little OT but this code will avoid bugsplat when creating a bunch of empty groups at once:

              class Sketchup;;Entities
              
                      alias add_group_su add_group
                      def add_group(*args)
                              g=self.add_group_su(*args)
                              while g.class!=Sketchup;;Group
              					g=self.add_group_su(*args)
              					Sketchup.active_model.definitions.purge_unused
                              end
              				return g
                      end
               end 
              

              DB

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                @kwalkerman said:

                So apparently, you can do face.clone, ... I if so, I might be able to determine what is happening with face.clone

                Karen,

                The .clone and .dup methods come from standard Ruby class Object, and create "shallow" copies. Ie, (from the book,) "the instance variables of the obj are copied, but not the objects they reference."

                Anyway.. it does NOT matter, because all of the Sketchup::Entity and Sketchup::Drawingelement subclasses are NOT pure Ruby objects. They are C++ objects, that are only exposed to Ruby in whatever manner (ie methods,) that the API makers decide(d). They do not really have Ruby attributes (instance variables,) they have C++ properties that we can access only if the API exposes them (thru a getter or setter method.)

                If you attempt to use the .clone or .dup methods on any C++ object, you will see a special "boo-boo" class returned:
                f.selection[0] #<Sketchup::Face:0x6023f54> f2=f.clone #<Deleted Entity:0x6020188>

                So don't use them. Really in the API they (.clone and .dup) should have been undefined for all the Sketchup subclasses that they don't work with, or overrriden with versions that do work (such as Didier's examples above.)

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • C Offline
                  cjthompson
                  last edited by

                  @tig said:

                  @thomthom said:

                  I thought adding existing geometry to groups made SU go rampage and bugsplat?

                  It does, BUT NOT if you make, copy and explode the group immediately - many of my tools use this method without issues. It will Bugsplat if you try and do too much with these grouping, and especially if you try and group entities across sets - try and see -it won't splat... πŸ˜‰

                  PS: The advantage of this method is that the face's material[s], layer and attributes are kept automatically.

                  .add_group(entities) should work fine as long as the entities are from model.active_entities.

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

                    OR any single ' entities' set - e.g. definition.entities.add_group(entities_already_in_the_definition_entities)

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • C Offline
                      cjthompson
                      last edited by

                      @tig said:

                      OR any single ' entities' set - e.g. definition.entities.add_group(entities_already_in_the_definition_entities)

                      but then you have to explode it right away (at least that's what it sounded like). If you only use active_entities, you can create it without having to worry about exploding it or bug-splatting SketchUp.

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

                        Yes you can create a group from entities immediately, and leave it made - just keep the entities-set the same fro all entities and the group itself

                        You don't have to use 'active_entities' - BUT just use one set fro all of the entities for the group and geometry...

                        Cross-threading entities causes splats.

                        How do you think some of my EEbyxxx tools work ?

                        What I was saying was, to to clone a face you can group it, copy the face-group and immediately explode the original group - that way the face is back where it was, and you have a group with an exact copy of the face in it - materials/layer/attributes etc...

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • K Offline
                          kwalkerman
                          last edited by

                          Didier - thanks for posting this. For my current purposes, I sometimes have another face bounded by the inner loops that I don't want to erase, so If I copy a bunch of faces together, and copy the inner loop faces first, then they'll get deleted when I copy the outer faces. So, creating a group, copying the group, and immediately exploding the original group is the best method for me.

                          Dan - thanks for the info on face.clone and face.dup. I saw <Deleted Entity: xxxxxxxxx> pop up in the ruby console, but I just assumed that the face was immediately deleted because it was placed on top of the other face.

                          --
                          Karen

                          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