sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    [REQ] Reverse curve script

    Scheduled Pinned Locked Moved Plugins
    11 Posts 2 Posters 1.7k Views 2 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

      You mean the order the edges appear? That start edge becomes end edge?
      Or is it related to the shape of the curve?

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

      1 Reply Last reply Reply Quote 0
      • PixeroP Offline
        Pixero
        last edited by

        Reversing the vertices order.
        I'm trying to animate using curves and some of them are reversed which makes the camera look backwards. πŸ‘Ž
        The secondary script is to put a construction point at the beginning of a curve for easy finding the reversed curves.
        "Mark curve start point" or something like that.

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

          Here's some code snippets

          
          curve = some_curve_object # fill in what you need
          
          
          # Reverse points in a curve
          points = curve.vertices.reverse.collect { |vertex| vertex.position }
          # (!) You want to delete the curve from the model at this point. How you do this depends if you need to consider attached faces.
          Sketchup.active_model.active_entities.add_curve(points)
          
          
          # Construction point at start
          Sketchup.active_model.active_entities.add_cpoint(curve.vertices[0].position)
          
          

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

          1 Reply Last reply Reply Quote 0
          • PixeroP Offline
            Pixero
            last edited by

            I've tried the construction point at start but that didnt work as expected. Sometimes puts it at first vertice but other times in the middle of a curve. Hmmmm. πŸ˜•

            Here is the code I used:

            Sketchup.active_model.active_entities.add_cpoint(Sketchup.active_model.selection.vertices[0].position)
            

            BugExample.skp

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

              Oh.
              I assumed that the vertices returned where in order. That means none of my examples works... 😞
              Maybe a sorting routine that starts with the starting edges and traverses the connected edges is required....

              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

                Or maybe not.
                That sample code line you used didn't work for me.

                Error is here:
                Sketchup.active_model.active_entities.add_cpoint(Sketchup.active_model.%(#FF8000)[**selection.vertices[0]**].position)

                corrected version that appear to work:
                Sketchup.active_model.active_entities.add_cpoint(Sketchup.active_model.selection[0].curve.vertices[0].position)

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

                1 Reply Last reply Reply Quote 0
                • PixeroP Offline
                  Pixero
                  last edited by

                  Yes thanks that seem to work.
                  Now if only I can reverse them...

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

                    My example doesn't work?

                    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

                      
                      # Get the Curve object from the selection
                      curve = Sketchup.active_model.selection[0].curve
                      
                      # Reverse points in a curve
                      points = curve.vertices.reverse.collect { |vertex| vertex.position }
                      # Erase the original curve
                      curve.parent.entities.erase_entities(curve.edges)
                      # Rebuild it
                      Sketchup.active_model.active_entities.add_curve(points)
                      
                      

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

                      1 Reply Last reply Reply Quote 0
                      • PixeroP Offline
                        Pixero
                        last edited by

                        Thanks, it works fine now.
                        I have attached the script if anyone else needs it.
                        Now off to fix those troublesome animation curves...


                        reverseCurve.rb

                        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