sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Transformation of single entities ???

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 4 Posters 309 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.
    • artmusicstudioA Offline
      artmusicstudio
      last edited by

      hi,
      again i cannot really find a solution in the api-description:

      when i have a group of 100 entities (edges and faces) and i know, that entity(50) is always the one i have to transform (it is a face),

      how can i MOVE this face (like with the mouse) , so that all connected edges and faces adapt automatically?

      i have the distance, the vector and the number of the entity.

      thanx for helping!
      stan

      1 Reply Last reply Reply Quote 0
      • S Offline
        slbaumgartner
        last edited by

        @artmusicstudio said:

        hi,
        again i cannot really find a solution in the api-description:

        when i have a group of 100 entities (edges and faces) and i know, that entity(50) is always the one i have to transform (it is a face),

        how can i MOVE this face (like with the mouse) , so that all connected edges and faces adapt automatically?

        i have the distance, the vector and the number of the entity.

        thanx for helping!
        stan

        I can't give you a working code snippet, but I can advise you that this operation is a lot more complicated than it might seem on the surface. The API has transform methods only for Group and ComponentInstance because primitive objects don't have Transformations associated with them. The GUI engine knows how to move primitive Entities such as Faces and Edges around, but it does so by continuously revising the Point3d values in them. I believe there is no way to alter these values via the API; you have to delete the existing objects and redraw them. The GUI also knows how to find and maintain the connected Edges and Faces. Perhaps this capability would be a reasonable feature request for a future release of the API.

        In pseudo-code, you want to:

        • get the Vertex positions of the Face you want to move
        • find all Edges and Faces connected to that Face
        • get the positions of the far end of each Edge emanating from a Vertex of your Face that is not one of the Face's own Edges
        • now delete your Face and all the Faces and Edges connected to it (!)
        • add your offset to the Vertex positions of your Face and redraw it.
        • redraw the Edges from each Vertex of your new Face to the corresponding original far end(s)
        • use the API to find the Faces associated with each Edge of your new Face

        Not having coded it, I'm not 100% sure there aren't some flaws in that sequence, but it makes sense to me ๐Ÿ˜•

        Steve

        1 Reply Last reply Reply Quote 0
        • jolranJ Offline
          jolran
          last edited by

          You may also have to account for inner faceloops..

          So I pass along a solution TIG gave me ages ago. The "face-clone". Don't know where it orginates from..
          Anyway have worked perfect with faces with holes. It may serve as a startingpoint..

          It does what slbaumgartner just mentioned more or less. Not deleting the original face though!

          There are some recent threads as to why one have to rewrite the faceloops if having "holes", but I can't relocate them..
          http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=55238

          
          # You will have to create and collect;
          #gents = a new group which will be containing the face clone( group.entities )
          #faces is a collection of original faces
          
          faces2go=[]; 
          
          faces.each{|face|
          	face.loops.each{|loop|gents.add_face(loop.vertices)}   # make innerfaces and all faces
          	oface = gents.add_face(face.outer_loop.vertices)       # make outer faces again to be sure
          	gents.each{|face| 
          		next if face.class!=Sketchup;;Face     
          			face.edges.each{|e|
          			if not e.faces[1]
          			   break
          			end
          		faces2go << face
          		}
          	}
          }
          
          gents.erase_entities(faces2go)   #erase inner faces
          

          BUT! Rereading the topic I wonder if you are not just wondering how to translate entities ?

          The danger in that is that the original face & Id might get altered, and your reference to the original selection then get's lost.

          Translating the face vertices "en masse" I'd think you should look into [highlight=#ff0000:wcl7fvpm]transform_by_vectors[/highlight:wcl7fvpm]
          http://www.sketchup.com/intl/en/developer/docs/ourdoc/entities.php?hl=sv-SE#transform_by_vectors

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

            Try something like this...
            vector.length = distance tr = Geom::Transformation.translation(vector) face.parent.entities.transform_entities(tr, [face])
            The 'face' [and its connecting edges/vertices] will be transformed by the 'vector', having set its length to 'distance'...
            You can get the 'entities' context in several ways - this gets it from the 'face' container...

            "entities.transform_by_vectors" needs matching arrays of vectors and objects [often vertices] - because all of the translations are the same in your case the "transform_entities" using a single 'translation-transformation' and a lone 'face' will suffice...

            TIG

            1 Reply Last reply Reply Quote 0
            • jolranJ Offline
              jolran
              last edited by

              Ah, yeah it's only one face..
              Then TIG's solution is more accurate.
              Was wondering though, is the "output" the same between those 2 methods ?

              Why I ask, is that I somehow was under impression that to avoid referencing to deleted or nil faces, since sometimes when translating faces the reference to a face in an Array may become deleted due to just that translation, cause some translations creates new faces etc. And to avoid that one use transform_by_vector.
              (may not be relevant here since were only dealing with 1 face, but curious while at it )

              edit: reffered to vertices when meant faces..

              Or am I misslead ?

              1 Reply Last reply Reply Quote 0
              • S Offline
                slbaumgartner
                last edited by

                @tig said:

                Try something like this...
                vector.length = distance tr = Geom::Transformation.translation(vector) face.parent.entities.transform_entities(tr, [face])
                The 'face' [and its connecting edges/vertices] will be transformed by the 'vector', having set its length to 'distance'...
                You can get the 'entities' context in several ways - this gets it from the 'face' container...

                "entities.transform_by_vectors" needs matching arrays of vectors and objects [often vertices] - because all of the translations are the same in your case the "transform_entities" using a single 'translation-transformation' and a lone 'face' will suffice...

                I stand corrected and educated ๐Ÿ˜ณ Never noticed that method on Entities. Thanks TIG.

                Steve

                1 Reply Last reply Reply Quote 0
                • artmusicstudioA Offline
                  artmusicstudio
                  last edited by

                  hi everybody,
                  thanx for this interesting discussion,

                  and yes, tig's way worls perfectly, so it is possible to immitate the mouse movement of single entities in any angle and direction.
                  fantastic!

                  
                  
                                  new_line10 = entities31.add_line pts[1], pts[0]
                  		tr = Geom;;Transformation.rotation(pts_senkrecht1,@vector,@angle_m.degrees)
                  		group31.entities.transform_entities(tr, new_line10)
                  
                  #MOVE 1 FACE  >>>> number
                  						
                  		distance_m_result = @carrier_w *@totaloffset_x_center/@run 
                  		vector2 = new_line10.line[1]
                  		vector2.length = distance_m_result.abs
                  		
                  		tr = Geom;;Transformation.translation(vector2)
                  		group31.entities.transform_entities(tr,group31.entities[number])
                  				
                  
                  

                  stan

                  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