sketchucation logo sketchucation
    • Login
    šŸ¤‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Transform a Face?

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 4 Posters 677 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.
    • Chris FullmerC Offline
      Chris Fullmer
      last edited by

      I was wondering if its possible to transform a face? I am able to transform a group, but not a single face. I'm hoping its just me and my syntax issues, but I'm afraid its not possible?

      model = Sketchup.active_model
      entities = model.selection
      entities.to_a
      cl_transform = Geom;;Transformation.scaling( 1, 3, 1 )
      entities[0].transform! cl_transform
      

      So that is enough to scale a group. But how could I alter it to work when entities[0] is a face? Thanks,

      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

        If the answer includes trigonometry and chickens I'm gonna scream...

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

          In order to transform individual entities such as faces and edges, you need to use the Entities.transform_entities method.

          This is closer, but I didn't try it.

          
          model = Sketchup.active_model
          entities = model.selection.to_a
          # entities.to_a # ! This does nothing to the entities variable. The result (an Array) is simply thrown away.
          cl_transform = Geom;;Transformation.scaling( 1, 3, 1 )
          entities.transform_entities cl_transform, [ entities[0] ]
          
          

          Another option would be to group it, transform it, then explode it.

          Hi

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

            I've been fumbling around with this, and I finally got something to work. It looks like this:

            model = Sketchup.active_model
            entities = model.active_entities
            ent = entities[0]
            t = Geom;;Transformation.scaling( 1, 3, 1 )
            entities.transform_entities t, ent
            

            That works. It takes the first entity in the entities array and transforms it by my "t" transformation. But I want to apply it to the selection, not the entire model. So I re-write "entities = model.active_entities" to

            entities = model.selection
            

            and it no longer works. Returns this error:

            (eval):6:in ā€˜initialize’: undefined method ā€˜transform_entities’ for #Sketchup::Selection:0xba333f0

            So what am I missing? It works when entities points to the entire active model, but not when it only points to the selection.

            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

              Chris, this gets back to your question the other day about "Are Entities Arrays?". Same thing here. A "Selection" is not an "Entities" or an "Array". It's actually even a bit further removed from an Array than Entities is. ("Entities is"... sounds funny to me).

              Anyway, you can do what you want by adding the .to_a to the end of the selection, like this:

              
              Sketchup.active_model.entities.transform_entities(  t  , Sketchup.active_model.selection.to_a  ) 
              
              

              The .transform_entities takes an Entity, an Entities, or an Array of entities as input.

              Todd

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

                Hey Todd, that works indeed! Immediately preceeding the .transform_entities needs to be sketchup.model_active and not model.selection. Perfect. Unfortunately I think I am in over my head with transforming for now. I'll have to devote some time to figuring out the rest of this. I was hoping that I could scale a face to be smaller by 50% or 10%, etc, and have the tranformation apply itself to the face follwing the faces axis or normal (or whatever the correct term is). So, give me some time and I'll be back hopefully to figure the rest of this out. One question though, in the line

                t = Geom;;Transformation.scaling( 1, 2, 1 )
                

                How dp you get it to scale to a .5 value, for example? How what do you input to make it scale itself smaller?

                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

                  Hey!! You said

                  @unknownuser said:

                  But I want to apply it to the selection, not the entire model.

                  so I answered how to do it from the current selection.

                  Kids these days... sheez.

                  Ok, about your scaling question... Without testing it, probably

                  
                  t = Geom;;Transformation.scaling( 0.5, 0.5, 0.5 )
                  
                  

                  Todd

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

                    @unknownuser said:

                    Hey!! You said

                    @unknownuser said:

                    But I want to apply it to the selection, not the entire model.

                    so I answered how to do it from the current selection.

                    Kids these days... sheez.

                    😳 I think I wasn't clear in my post.

                    @unknownuser said:

                    Immediately preceeding the .transform_entities needs to be sketchup.model_active and not model.selection

                    I was correcting my own poor logic, not anything you wrote. Your code worked perfectly and was tailored to what I asked for. Thanks for your help, and the help of everyone else on here!

                    I'm serisouly not used to coming on to the SketchUp forum and asking for help with stuff that I know is beginner stuff. SketchUp I understand. Ruby is sort of kicking my tail, but I'm optimistic. So I'm desperately trying to balance asking for help and not wearing out my welcome šŸ˜„ So a big thanks again to everyone who helps us wannabe Ruby programmers.

                    Chris

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

                    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