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

      @chris fullmer said:

      Transformation is taking me a long time to figure out. Is there a resource that everyone uses to learn how to transform things? I assumed it would be a little easier than it is......

      Chris

      I second this. The documentation entry on the transformation class didn't make me much wiser.

      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

        Let's discuss it. What do you want to know?

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

          What I'm trying to do specificity at the moment is trying to move a vertex to a new 3D location.

          Then at a later point I will try to rotate an object (group/component or selection of entities) around an axis. For instance, you have a component and a line that goes through that component at some position. How would you rotate the component with the pivot point being that line?

          What happens when you modify entities within nested groups or components, will you need to take into account the nested rotation and scaling?

          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

            From the doc on the Transformation class:

            @unknownuser said:

            Second, and foremost, the transformation class can be used to apply transformations on geometry, such as a move (called a translation),

            Then the entry on translation:

            The translation method is used to create a transformation that does translation. 
            

            I don't understand much more of that.

            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

              
              p1 = Geom;;Point3d.new
              [Point3d(0, 0, 0)]
              > p1
              Point3d(0, 0, 0)
              > p2 = Geom;;Point3d.new
              [Point3d(0, 0, 0)]
              > p3 = Geom;;Point3d.new
              [Point3d(0, 0, 0)]
              > p4 = Geom;;Point3d.new
              Point3d(0, 0, 0)
              > p2 = [10,0,0] 
              [10, 0, 0]
              > p3 = [10,10,0] 
              [10, 10, 0]
              > p4 = [0,10,0] 
              [0, 10, 0]
              > am = Sketchup.active_model 
              #<Sketchup;;Model;0x19935d64>
              > am.entities.add_face(p1,p2,p3,p4) 
              #<Sketchup;;Face;0x199358c8>
              #
              # select one of the edges at this point  
              #
              > v = Sketchup.active_model.selection[0].start
              #<Sketchup;;Vertex;0x19935710>
              
              #
              # a vector transform, 5 in +x direction and 5 in +y direction 
              #
              > t = Geom;;Transformation.new([ 5,5,0]) ; 
              #<Geom;;Transformation;0x19935508>
              > am.entities.transform_entities(t,v) 
              true
              
              
              1 Reply Last reply Reply Quote 0
              • T Offline
                todd burch
                last edited by

                In simple terms, (terms good enough to code by), think of a "transformation" as the "equation" or "specification" for how to move (translate) an entity.

                A transformation can define a translation (a move) or a rotation or a scaling.

                There is a fairly recent thread here that Scott L. posted that went through the whole group/component nest translation thingy. And yes, you have to apply all those transformations when working with groups/components and nested groups/components.

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

                  Thanks for stepping in Todd. Here's what I am wanting to do.

                  I have a rectangular face that is not lying flat, its slanted (like a sphere, one of the faces that is pointing at an odd angle for example). So I pushpull the face a distance. I know how to isolate the push/pulled face and its normal. I would like to scale it using its normal as the Z direction, and then scale it equally on the X and Y. Does that make any sense? I just want to scale the face so it stays flat (well, flat to its original off kilter angle - so flat to its normal).

                  I started to set it up last night, and I got it to scale, but not how I wanted, and its the "normal" info that I'm not taking into account. That would be of interest to me. Thanks Todd and anyone else who joins in,

                  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

                    Is this what you mean?

                    
                    require 'sketchup.rb' 
                    
                    am = Sketchup.active_model ; 
                    
                    # Make a face, and tilt it some 
                    
                    p1 = Geom;;Point3d.new(0,0,0) ; 
                    p2 = Geom;;Point3d.new(10,0,5) ; 
                    p3 = Geom;;Point3d.new(10,10,5) ; 
                    p4 = Geom;;Point3d.new(0,10,0) ; 
                    
                    am.entities.add_face(p1,p2,p3,p4) ; 
                    
                    # find the face just created 
                    # call it "oface", for "original face" 
                    
                    oface = nil ; 
                    am.entities.each {|ent| if ent.is_a? Sketchup;;Face then oface = ent ; break; end }
                    
                    # point it "up" so it won't be inside out or upside down 
                    oface.reverse! if oface.normal.z < 0 ; 
                    
                    # save the orignal face's normal before we extrude it
                    normal = oface.normal ; 
                    
                    # extrude it 
                    oface.pushpull(10) ;
                    
                    # find the opposite face with the same normal as the original face 
                    # call it "nface" for "new face"
                    
                    nface = nil ; 
                    am.entities.each {|ent| 
                    	next if !(ent.is_a? Sketchup;;Face) 
                    	next if (oface==ent) ; 
                    	next if (normal != ent.normal)
                    	nface = ent ; 
                    	break 
                    }
                    
                    # nface is the face we want to scale.  
                    # Find it's center point 
                    
                    cp = Geom;;Point3d.new( nface.bounds.center ) ; 
                    
                    # A uniform scaling transformation about a point 
                    scale_t = Geom;;Transformation.scaling( cp, 0.5) ; 
                    
                    am.entities.transform_entities(scale_t, nface) ; 
                    
                    
                    
                    

                    (edited: forgot to add the normal check in the loop to find the opposite face)

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

                      Thanks Todd. I'll dig into this when I get back from work today.

                      One thing, when you created the face, you then searched for it afterwards:

                      am.entities.add_face(p1,p2,p3,p4) ;
                      
                      # find the face just created
                      # call it "oface", for "original face"
                      
                      oface = nil ;
                      am.entities.each {|ent| if ent.is_a? Sketchup;;Face then oface = ent ; break; end }
                      

                      Why not not use the return value of add_face? Is it not reliable?

                      oface = am.entities.add_face(p1,p2,p3,p4) ;
                      

                      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

                        That's how I originally coded it, but I changed it and don't remember why now. You are right, that would have been simpler.

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

                          Hey Todd, the example you gave me worked great (as expected)! I am wondering if there is an easier way to located the push/pulled face though. I tried

                          new_face = orig_face.pushpull length

                          And I was hoping thay would return the name of the new face, but it doesn't. I think it returns a true/false status or something.

                          So is there a built in way to get the name of the newly created face? In my actual model, I have lots of faces that will be parallel, so just comparing normals does not quite do it in practice. So if there is no built in way to get the name of the newface, I'll play around with how to compare vertices or edges of the original face to the push/pulled distance and see if I can find the face that way.

                          Thanks so much Todd! (and thanks for letting me piggy back on your transformation thread Thom!)

                          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

                            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
                                            • 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