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

    Flatten Plane / Match plane

    Scheduled Pinned Locked Moved Plugins
    30 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.
    • S Offline
      stevo7122
      last edited by

      Technicallly the first face clicked should be f0=m.selection[0] If I were to select two faces...correct?

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

        **selection=Sketchup.active_model.selection** f0=selection[0] f1=selection[1] n0=f0.normal n1=f1.normal
        etc etc

        With selections, arrays etc the first element is index 0, second index 1 etc...
        So when you select two faces.
        The selection has two elements - [0] and [1]
        These are the faces referred to as f0 and f1 above...
        From these we get their 'normals' [vectors - drawn perpendicular from their 'planes'] - n0 and n1...

        That's also why you can't Select any other things and hope this'll work, as there's no code in there [at the moment] to 'extract' the just the two faces from everything else that you might have selected... but then that's the subject for a separate thread... πŸ˜‰

        TIG

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

          Right. However in the array will the first position = the first item clicked? For example if I select one face the first array position[0] should contain that face. And in another instance if i click on the first face then the second face will the position[0] still be the first face I clicked on or will the second face be in that position as it changes how the model is enumerated? For some reason when I use the code no matter which face I click on it always flattens the same face regardless of the first face clicked. Currently as it stands if I click the first face and then the second face it will always flatten the first face to the second face....Basically to test the code I will select 1 face then select the next face and it will flatten. However If I perform an undo to reset the faces to the original position and select a different face as the first one it will still flatten the same face regardless of which order I clicked on.
          ` f0=m.selection[0]; #first face selected
          f1=m.selection[1]; #second face selected

          n0=f0.normal; #first plane normal
          n1=f1.normal; #second plane normal

          c=n0.cross(n1);

          set a equal to the angle between the first and second faces.

          a=n0.angle_between(n1);

          t=Geom::Transformation.rotation(f0.vertices[0].position,c,-a);
          m.active_entities.transform_entities(t,f1);
          m.commit_operation;`

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

            As an edit I just realized I think my comments should be #first face normal and #second face normal not #first plane normal etc...

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

              I have been doing some debugging of sorts and if you do a puts f0.normal and a puts f1.normal then select face1 then face2 (look at the two values and the order they are outputted) then perform an undo and select face2 then face1 it produces the same values in the same order. Shouldn't the order be reversed if I clicked on a different plane first in each instance?

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

                Sorry I meant to say clicked on a different face first...For some reason I keep wanting to say plane..

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

                  edge.erase!

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

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

                    To get the faces in a specific order you really need to make a Tool class - then pick the faces after the tool is activated, that way the first picked face is set.
                    We are only using the 'selection' based process to simplify things, as you try to get your head around how to find normals, crosses and transform vertices etc...
                    The order objects appear in a selection is not necessarily determined by the initial selection order, it may well relate to their 'creation' order - it's arbitrary.
                    If you recall my initial example even excluded a 'second' face as the selected face was laid 'flat'...

                    If you need a Tool class to select the faces there are many examples available - find an 'unfold' tool's script...
                    That will have many details of selecting faces and getting suitable data from them and neighbors etc, used to 'unfold' them - much like you want to do...

                    TIG

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

                      Thanks for the response I suspected something like that was going on. I do have code to make sure that only 2 faces have been selected and no other parts of the model. I will look into using the tool class so I can get the correct order of faces. Again Thanks to both of you for all of your help.

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

                        If you're new to SketchUp plugin development you might want to have a look at this article: http://www.thomthom.net/thoughts/2012/01/golden-rules-of-sketchup-plugin-development/

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

                        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