sketchucation logo sketchucation
    • 登入
    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!
    🔌 Smart Spline | Fluid way to handle splines for furniture design and complex structures. Download

    One-liners

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    22 貼文 6 Posters 1.1k 瀏覽 6 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • N 離線
      noelwarr
      最後由 noelwarr 編輯

      Here is a chance to show off your ruby skills. One line of code that does something cool that you can copy and paste into the console. I'll keep editing this post adding your contributions so you can find the one-liners easily. The first is mine (very simple I know).

      Reconstruct all possible faces from selected entities
      Sketchup::active_model.selection.each{|ent| ent.find_faces if ent.is_a?(Sketchup::Edge)}

      Run this befor printing
      (av = Sketchup.active_model.active_view).camera.perspective = false; av.zoom_extents.zoom(1.052)

      And here is a challenge: ArcCurves get lost on solid operations. Can you recreate them in one line of ruby? (Hint: If 3 or more edges are on the same plane and the angle between each is the same and less than or equal to 15, we can assume it is part of a lost ArcCurve)

      1 條回覆 最後回覆 回覆 引用 0
      • Dan RathbunD 離線
        Dan Rathbun
        最後由 編輯

        The each iterator returns the receiver (upon which it acts,) not the result of the block.

        Try using one of the iterators from the Enumerable mixin module (which is mixed into most of the API collection classes.)

        I might as well give it to you:

        find_faces_of_selected_entities = Sketchup.active_model.selection.find_all {|ent| ent.is_a?(Sketchup::Face)}

        I'm not here much anymore.

        1 條回覆 最後回覆 回覆 引用 0
        • Dan RathbunD 離線
          Dan Rathbun
          最後由 編輯

          Wouldn't it be cool if there was a Chrome plugin, where you could hilite a Ruby statement on SCF, right-click the mouse, and choose "Send to SketchUp Console" ??

          I'm not here much anymore.

          1 條回覆 最後回覆 回覆 引用 0
          • N 離線
            noelwarr
            最後由 編輯

            @dan rathbun said:

            The each iterator returns the receiver (upon which it acts,) not the result of the block.

            Try using one of the iterators from the Enumerable mixin module (which is mixed into most of the API collection classes.)

            I might as well give it to you:

            find_faces_of_selected_entities = Sketchup.active_model.selection.find_all {|ent| ent.is_a?(Sketchup::Face)}

            I was unaware of the find_all method. You live and learn. The one-liner you propose, however, does nothing. It would be useful in the context of more code. I think the problem is the variable name I chose. It is misleading. Here is the original code I posted

            find_faces_of_selected_entities = Sketchup::active_model.selection.each{|ent| ent.find_faces if ent.is_a?(Sketchup::Edge)}

            I say find_faces_of_selected_entities because the Edge class has the find_faces() method. I think both should be renamed to reconstruct_faces or something. In the hope everything is more clear we'll get rid of the variable alltogether. I'm changing my first post to...

            #Reconstruct all possible faces from selection
            Sketchup::active_model.selection.each{|ent| ent.find_faces if ent.is_a?(Sketchup::Edge)}

            Try it out. Draw something, delete a few faces, select everything and run the one-liner.

            1 條回覆 最後回覆 回覆 引用 0
            • Dan RathbunD 離線
              Dan Rathbun
              最後由 編輯

              @noelwarr said:

              Try it out. Draw something, delete a few faces, select everything and run the one-liner.

              YOUR CODE DOES NOT WORK ! .. as I had said.

              It returns nil

              I'm not here much anymore.

              1 條回覆 最後回覆 回覆 引用 0
              • N 離線
                noelwarr
                最後由 編輯

                What it returns is irrelevant. It's what it does that matters, Dan. Please see attatched video for proof (Sorry its in wmv). There was a moment of fear when the code did nothing. Then I realised I had nothing selected 😄

                I know it is bothersome when people post code that doesn't work. I'm sory if I didn't explain myself correctly giving the impression that that was the case. It is also, however bothersome when people say
                @dan rathbun said:

                YOUR CODE DOES NOT WORK !
                without considering the possibility that it might.

                Rest assured I shall be checking the oneliners people post before I include it in my first post.


                oneliner.wmv

                1 條回覆 最後回覆 回覆 引用 0
                • TIGT 離線
                  TIG Moderator
                  最後由 編輯

                  It does work, in that it adds faces to selected edges.
                  For me it works, then returns the selection, not the new faces or nil.
                  I think the initial confusion was that the code had something like "add_faces_to_selected_lines=..." to show what it did, and of course add_faces_to_selected_lines is set to be the selection, I assume this was used because of the arbitrary rule that you can't use a ';' - which makes it impossible to do a one-liner with its intent shown unless you add '#' and then the description at the end of the code line...

                  TIG

                  1 條回覆 最後回覆 回覆 引用 0
                  • N 離線
                    noelwarr
                    最後由 編輯

                    You got it TIG. Could you suggest a way to rephrase the whole "challenge" so it is readily apparent?

                    1 條回覆 最後回覆 回覆 引用 0
                    • Dan RathbunD 離線
                      Dan Rathbun
                      最後由 編輯

                      Yes I was confused by the original wording you chose.

                      I'm not here much anymore.

                      1 條回覆 最後回覆 回覆 引用 0
                      • daikuD 離線
                        daiku
                        最後由 編輯

                        OBFUSCATORS!

                        Your goal should be to write the most readable code possible. This is the opposite.

                        Clark Bremer
                        http://www.northernlightstimberframing.com

                        1 條回覆 最後回覆 回覆 引用 0
                        • N 離線
                          noelwarr
                          最後由 編輯

                          大工ですか。すごい。何年前日本に住んだけど。大阪に。それに、私も大工ですよ。面白い、なぁ。
                          Anyhow, I'm not advocating for this type of code, though I think it's cool that ruby allows for it. All I wanted was a list of cool lines that one might copy and paste into the console to do something useful. Instead it would seem I've started a flame war or something 😮

                          1 條回覆 最後回覆 回覆 引用 0
                          • daikuD 離線
                            daiku
                            最後由 編輯

                            Sorry, but I don't speak a lick of Japanese. I can tell from the first two characters that this was addressed to me, but the rest is lost on me. As a professional timber framer, the Daiku are my heroes. We had a group come to one of our conferences, and the level of skill and craftsmanship was amazing.

                            And of course I was only trying to be clever with my first post. Nothing personal 😄

                            Clark Bremer
                            http://www.northernlightstimberframing.com

                            1 條回覆 最後回覆 回覆 引用 0
                            • N 離線
                              noelwarr
                              最後由 編輯

                              No offence was taken! 😛 The japanese just says I'm a carpenter too and lived (a short period of time) in Osaka a few years back. I was also not left unmoved by Japanese craftmanship when it comes to woodworking. We even ended up selling one of their products a few years back, here in Europe. http://mitaka.eu/
                              It's still the traditional side that gets to the heart 😎

                              1 條回覆 最後回覆 回覆 引用 0
                              • thomthomT 離線
                                thomthom
                                最後由 編輯

                                Why no semi-colons? Seems that we're doing one-statements instead of one-liners then.

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

                                1 條回覆 最後回覆 回覆 引用 0
                                • jeff hammondJ 離線
                                  jeff hammond
                                  最後由 編輯

                                  @thomthom said:

                                  Why no semi-colons?

                                  meh..

                                  view = Sketchup.active_model.active_view ; view = view.zoom 1.052

                                  parallel projection -> zoom extents -> use the code for true zoom extents…
                                  i use it sometimes for printing.
                                  (also part of an applescript i use for easy printing to scale from sketchup)

                                  dotdotdot

                                  1 條回覆 最後回覆 回覆 引用 0
                                  • N 離線
                                    noelwarr
                                    最後由 編輯

                                    Why not...

                                    Sketchup.active_model.active_view.zoom(1.052)

                                    Or to include the zoom extents...

                                    Sketchup.active_model.active_view.zoom_extents.zoom(1.052)

                                    Don't know how to activate the parallel projection though. Anyone?

                                    1 條回覆 最後回覆 回覆 引用 0
                                    • Dan RathbunD 離線
                                      Dan Rathbun
                                      最後由 編輯

                                      Activate Parallel Projection for the current View's Camera:

                                      @noelwarr said:

                                      Don't know how to activate the parallel projection though. Anyone?

                                      Sketchup.active_model.active_view.camera.perspective = false

                                      I'm not here much anymore.

                                      1 條回覆 最後回覆 回覆 引用 0
                                      • thomthomT 離線
                                        thomthom
                                        最後由 編輯

                                        @unknownuser said:

                                        view.zoom 1.052

                                        Where does this magic number come from?

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

                                        1 條回覆 最後回覆 回覆 引用 0
                                        • Dan RathbunD 離線
                                          Dan Rathbun
                                          最後由 編輯

                                          @thomthom said:

                                          @unknownuser said:

                                          view.zoom 1.052

                                          Where does this magic number come from?

                                          .. and it seems to work in Parallel Projection mode, but not in Perspective mode.

                                          I'm not here much anymore.

                                          1 條回覆 最後回覆 回覆 引用 0
                                          • jeff hammondJ 離線
                                            jeff hammond
                                            最後由 編輯

                                            @noelwarr said:

                                            Why not...

                                            Sketchup.active_model.active_view.zoom(1.052)

                                            Because I don't know ruby 😉
                                            I just found something that worked for what I needed.
                                            but your version doesn't use a semicolon so I'll make that my thread entry 😄

                                            dotdotdot

                                            1 條回覆 最後回覆 回覆 引用 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • 第一個貼文
                                              最後的貼文
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement