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

    How do you move vertices?

    Scheduled Pinned Locked Moved Developers' Forum
    24 Posts 4 Posters 1.1k 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.
    • thomthomT Offline
      thomthom
      last edited by

      hm.. if you do a pushpull on a face, and do not create a copy of the starting face, you still have a reference to it.

      
      sel = Sketchup.active_model.selection
      someFace = sel[0] # Assuming it's a face
      sel.clear
      someFace.pushpull(100)
      sel.add someFace # someFace still refers to your original face
      
      

      If you create a copy of the starting face I can see it being a problem though.

      someFace.pushpull(100, true)
      

      I suppose you could traverse the connected faces of your original face.

      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

        Oh yes, I did not specify. I do need to make a copy of the face when I push.pull. I think I have some ideas of how to find that face using the distance I pushpulled and vertices or edges locations or something. I was hoping there was an easier way though πŸ˜„

        ok, question about when and why to create a method. So lets say I do write code that does the above for me. Is that an example of something that might be nice to write as its own method that I could call anytime I wanted to find the newly created push.pulled face? Because for example, I have 6 different ways that I might create that face, so there are 6 places in my code that I might have to write out the test to find the name of the new face. Is that a good reason to write it as its own method? So instead of re-writing it, I can just call the method, pass the original face name and the pushpull distance into the method and make it return the new face name?

        Chris

        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

          Yes. That's when you want a method. You don't want code doing the same thing multiple places. You'll eventually forget to update all occurrences.

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

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

            An idea to find the new push pulled face:

            
            # get a face
            myFace = Sketchup.active_model.selection[0]
            
            # build an array of the currently connected faces
            connected_faces = []
            myFace.edges.each { |edge| connected_faces += edge.faces }
            connected_faces.uniq!
            
            # push/pull
            myFace.pushpull 100, true
            
            # find the new faces connected to our face
            new_faces = []
            myFace.edges.each { |edge| new_faces += edge.faces }
            new_faces.uniq!
            # eliminate the ones we had before
            side_faces = new_faces - connected_faces
            
            # find the new push/pulled face
            opposite_face = get_opposite_face(side_faces[0], myFace)
            
            # find the opposite face
            def get_opposite_face(connected_face, original_face)
              # We take one of the side faces,
              # loop through all it's edges,
              # until we find a face that has the same normal
              # as our original face.
              connected_face].edges.each { |edge|
                edge.faces.each { |face|
                  if face != original_face && (face.normal == original_face.normal || face.normal.reverse == original_face.normal)
                      return face
                  end
                }
              }
              return nil # method failed
            end
            
            

            Note: code not tested.

            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
              todd burch
              last edited by

              Chris and Thom, I think I've posted maybe 6 times (in different forums) how to reliably get the new face. The process boils down to using set arithmetic on arrays.

              • Basically, take an inventory of your active_entities.
              • Perform the push pull. In the simplest form of push pull, you get a minimum of 4 new faces and 6 new edges (the case when you extrude a triangle), perhaps thousands of new faces and edges.
              • Subtract the initial inventory of entities from the now current active_entities and that result is all the new geometry created.
                Now, you can weed through the result to find the geo you want to work with.

              If you can find it via distance, good luck, and I hope you don't run into a pre-existing face at the same distance. I would like to see .pushpull return an array of newly created edges and faces, with the opposite face listed first.

              @Chris - a terminology thing: we're not dealing with "names" of faces. We're dealing with Object References. No, there is no built in method. When you .pushpull, you will ONLY EVER get one face with the same normal.

              Todd

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

                Thanks Todd.
                Seems that I wasn't too far of.

                @unknownuser said:

                I would like to see .pushpull return an array of newly created edges and faces, with the opposite face listed first.

                I second this.

                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

                  @unknownuser said:

                  I would like to see .pushpull return an array of newly created edges and faces, with the opposite face listed first.

                  That would be great.

                  That makes sense to compare and subtract, then find the leftover entity with the normal that matches the original face. That did not cross my mind to search that way. Thanks guys! I'll post it when I get it written (probably after work or during lunch).

                  @unknownuser said:

                  @Chris - a terminology thing: we're not dealing with "names" of faces. We're dealing with Object References.
                  Oops, I'll work on my terminology πŸ˜„

                  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

                    ok, here is the code I put together based on your guys comments. It gets all geometry before pushpulling, then all geometry after pushpulling and does a subtraction, leavin just the new stuff. Then searches through that for a face with a normal == to the original face's normal. Thanks for the help on this. Now I can do a uniform scale on the new face. So I'll incorporate it all into my greeble script later today I hope. Thanks!

                    model = Sketchup.active_model
                    entities = model.selection
                    # Initialize my Arrays
                    existing_ents = []
                    current_ents = []
                    new_ents = []
                    # Define existing entities and then push.pull my face
                    existing_ents = entities[0].all_connected
                    entities[0].pushpull( 100, true)
                    # Define all entities after the push.pull
                    current_ents = entities[0].all_connected
                    # Define new entities through subtraction
                    new_ents = current_ents - existing_ents
                    # Loop through each new entity to find the faces, 
                    # then find just the face with its normal matching the original face
                    # Send a quick text to the Ruby console and paint the face to show it worked
                    new_ents.each do |ent|
                    	if ent.typename == ( "Face" )
                    		if ent.normal == entities[0].normal
                    			puts "Found it!  The Object Reference is " + ent.to_s
                    			ent.material = [0,0,0]
                    		end
                    	end
                    end
                    

                    This script requires having a single face selected when the script is run.

                    Chris

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

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      todd burch
                      last edited by

                      For your playing around with stuff like this, (and I encourage it), here's a tip. Instead of this:

                      
                      entities = model.selection
                      .
                      .
                      existing_ents = entities[0].all_connected
                      
                      

                      Do this, and it's less typing:

                      
                      entity = model.selection[0]
                      .
                      .
                      existing_ents = entity.all_connected
                      
                      

                      That way, you get rid of the array reference early and no more qualifying every use with [0].

                      For short stuff (shorter than this), I just use the console.

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

                        Ahh, very helpful, thanks again Todd,

                        Chris

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

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

                        Advertisement