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

    Drawing with GL

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

      isn't this supposed to work? ( knowing my coding genius probably not.. 😒 )

      i thought i cracked it but i get: #Sketchup::View:0x00000007665b00 and nothing drawn

      @p1=200,200,0
      @p2=600,600,0
      model=Sketchup.active_model
      view=model.active_view
      view.line_width=10
      view.draw2d GL_LINES, [@p1, @p2]
      

      Thanks

      1 條回覆 最後回覆 回覆 引用 0
      • D 離線
        driven
        最後由 編輯

        @unknownuser said:

        This method can only be called from within the draw method of a tool that you implement in Ruby.

        the bolding is mine, the rest from the API...

        well known gotcha, so don't fell too bad...

        there is a simple tool with the method, somewhere [here] >> http://sketchucation.com/forums/viewtopic.php?p=245880#p245880

        john

        learn from the mistakes of others, you may not live long enough to make them all yourself...

        1 條回覆 最後回覆 回覆 引用 0
        • CadFatherC 離線
          CadFather
          最後由 編輯

          John, Thanks for this.

          i actually did try it wrapped up in a class method, and called it from the
          Sketchup.active_model.select_tool Gridz.new

          still had no result. at least i now know where not to look! 👍

          1 條回覆 最後回覆 回覆 引用 0
          • CadFatherC 離線
            CadFather
            最後由 編輯

            that was good (if only from a neurological perspective), seems like what i missed was 'onMouseMove invalidate' (thanks to the Chris F example you linked). however the line disappears when orbiting - even if i use the invalidate on onMButtonDown. 😒

            require 'sketchup.rb'
            
            class Layz
            
            	def activate
            			@p1=200,200,0
            			@p2=600,600,0
            	end
            	 
            	 
            	def onMouseMove(flags, x, y, view)
            			view.invalidate
            	end
            
            
            	def draw(view)
            			model = Sketchup.active_model
            			view = model.active_view
            			view.line_width = 10
            			view.drawing_color = "red"   
            			view.draw2d GL_LINES, [@p1, @p2]
            	end   #def
            
            end # class
            
            if !file_loaded?(File.basename(__FILE__))
            UI.menu("Plugins").add_item('Layz'){ Sketchup.active_model.select_tool Layz.new }
            end  
            
            1 條回覆 最後回覆 回覆 引用 0
            • D 離線
              driven
              最後由 編輯

              @cadfather said:

              ...however the line disappears when orbiting -

              even fredo's toolbars disappear when you orbit...
              I think SU suspends the GL drawn elements to help cope with showing the model...
              john

              learn from the mistakes of others, you may not live long enough to make them all yourself...

              1 條回覆 最後回覆 回覆 引用 0
              • CadFatherC 離線
                CadFather
                最後由 編輯

                ..makes sense, though when i look at those aspect ratio bars on the sides (like advanced camera tools), they do stay on screen.

                1 條回覆 最後回覆 回覆 引用 0
                • D 離線
                  driven
                  最後由 編輯

                  they are completely controlled by SU so I guess they has that option...

                  but not us...

                  EDIT: watermarks will also stay put, they may be using those...
                  john

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 條回覆 最後回覆 回覆 引用 0
                  • CadFatherC 離線
                    CadFather
                    最後由 編輯

                    mmm maybe so, advanced camera tools is a ruby script though.

                    unfortunately it's flipping scrambled 😒

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

                      When you orbit the Orbit tool is pushed into the tool stack - suspending your tool. So you have to invalidate the view in the resume event. You also want to invalidate the view on deactivate as otherwise your drawing might stick around after your tool is not active any more.

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

                      1 條回覆 最後回覆 回覆 引用 0
                      • CadFatherC 離線
                        CadFather
                        最後由 編輯

                        not sure, even with the invalidate on resume, no joy. though i could be doing it wrong.

                        def resume(view)
                        view.invalidate
                        end

                        1 條回覆 最後回覆 回覆 引用 0
                        • D 離線
                          driven
                          最後由 編輯

                          what are you aiming to achieve?

                          there may be other ways...

                          john

                          learn from the mistakes of others, you may not live long enough to make them all yourself...

                          1 條回覆 最後回覆 回覆 引用 0
                          • CadFatherC 離線
                            CadFather
                            最後由 編輯

                            well, first of all i'm trying to avoid going to bed! 😆

                            i wanted to make a plugin that would show aspect ratio bars and even a grid system, it's almost there, but for the orbit bit(!)

                            this is the beast i'm working with:

                            class Gridz
                            
                             def activate
                             		@width3 = Sketchup.active_model.active_view.vpwidth/3
                            		@height3 = Sketchup.active_model.active_view.vpheight/3
                            
                            		@p1 = @width3, 0, 0
                            		@p6 = @width3, @height3*3, 0
                            		@p2 = @width3*2, 0, 0
                            		@p5 = @width3*2, @height3*3, 0
                            		@p8 = 0, @height3, 0
                            		@p3 = @width3*3, @height3, 0
                            		@p7 = 0, @height3*2, 0
                            		@p4 = @width3*3, @height3*2, 0
                             end
                             
                            def onMouseMove(flags, x, y, view)
                            		view.invalidate
                            end
                            
                             def resume(view)
                            		view.invalidate
                             end 
                               
                             def suspend(view)
                            		view.invalidate
                             end    
                               
                            def draw(view)
                            		model = Sketchup.active_model
                            		view = model.active_view
                            		view.line_width = 1
                            		view.drawing_color = "red"   
                            
                            		view.draw2d GL_LINES, [@p1, @p6]
                            		view.draw2d GL_LINES, [@p2, @p5]	  
                            		view.draw2d GL_LINES, [@p8, @p3]	  
                            		view.draw2d GL_LINES, [@p7, @p4]	  
                            end   #def
                            
                            def deactivate(view)
                            		view.invalidate
                            end
                            
                            end # class
                            
                            if !file_loaded?(File.basename(__FILE__))
                            UI.menu("Plugins").add_item('Grid'){ Sketchup.active_model.select_tool Gridz.new }
                            end  
                            
                            file_loaded(File.basename(__FILE__))
                            
                            1 條回覆 最後回覆 回覆 引用 0
                            • D 離線
                              driven
                              最後由 編輯

                              have you ever read 'Automatic Sketchup'?
                              btw: I win the insomniac award...

                              # Create a 4x4 cube
                              square = Sketchup.active_model.entities.add_face [-2,2,0],
                                 [2,2,0], [2,-2,0], [-2,-2,0]
                              square.pushpull -4
                              #Chapter 11; The SketchUp User Interface Part 2; Views, Cameras, Tools, and Pages 251
                              # Access the Pages container and get the time
                              pages = Sketchup.active_model.pages
                              now = Time.now
                              # Create the first page
                              pg1 = pages.add "Pg1"
                              pg1.camera.aspect_ratio = 2
                              pg1.shadow_info["DisplayShadows"] = true
                              pg1.shadow_info["ShadowTime"] = now
                              # Create the second page
                              pg2 = pages.add "Pg2"
                              pg2.camera.aspect_ratio = 1.5
                              pg2.shadow_info["DisplayShadows"] = true
                              pg2.shadow_info["ShadowTime"] =
                                 now + (60 * 60 * 6)
                              # Create the third page
                              pg3 = pages.add "Pg3"
                              pg3.camera.aspect_ratio = 1
                              pg3.shadow_info["DisplayShadows"] = true
                              pg3.shadow_info["ShadowTime"] =
                                 now + (60 * 60 * 12)
                              # Select the first page
                              pages.selected_page = pg1
                              

                              learn from the mistakes of others, you may not live long enough to make them all yourself...

                              1 條回覆 最後回覆 回覆 引用 0
                              • CadFatherC 離線
                                CadFather
                                最後由 編輯

                                John...looking at that code looks like you do need the rest! 😄

                                is that a taster of what's inside the book? i'll check it out. 👍

                                1 條回覆 最後回覆 回覆 引用 0
                                • D 離線
                                  driven
                                  最後由 編輯

                                  yes it's straight out of the book, did you run it?
                                  it does change the aspect ratio bars when you play the animation...
                                  and they don't disappear when orbiting...

                                  john

                                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                                  1 條回覆 最後回覆 回覆 引用 0
                                  • jiminy-billy-bobJ 離線
                                    jiminy-billy-bob
                                    最後由 編輯

                                    @cadfather said:

                                    mmm maybe so, advanced camera tools is a ruby script though.
                                    unfortunately it's flipping scrambled 😒

                                    It's not specific to the Advanced Camera Tools. You can set the camera's aspect ratio yourself, and you'll get the same gray bars on the sides.

                                    25% off Skatter for SketchUcation Premium Members

                                    1 條回覆 最後回覆 回覆 引用 0
                                    • D 離線
                                      driven
                                      最後由 編輯

                                      @jiminy-billy-bob said:

                                      ...You can set the camera's aspect ratio ourself, and you'll get the same gray bars on the sides.

                                      but, like a lot of examples in the API, it won't just 'work'...
                                      attach it to the view...

                                      Sketchup.active_model.active_view.camera.aspect_ratio = 1.414
                                      

                                      that will give you Landscape A4 paper size margins, 1/1.414 will be Portrait...

                                      john

                                      learn from the mistakes of others, you may not live long enough to make them all yourself...

                                      1 條回覆 最後回覆 回覆 引用 0
                                      • CadFatherC 離線
                                        CadFather
                                        最後由 編輯

                                        that's the thing, often i try things out from the api docs and when it doesn't work, i'm not sure if it's me (my preferred choice) or the doc itself (...)!

                                        John, i hadn't even notice it was relevant... will look it up.

                                        JJB, the aspect ratio bars seem to be governed differently, when you try with lines it doesn't stay on screen (on orbit)

                                        going to 'try' and take a break this evening... my skull hurts! 😲

                                        1 條回覆 最後回覆 回覆 引用 0
                                        • CadFatherC 離線
                                          CadFather
                                          最後由 編輯

                                          ok, i came to the conclusion that this is impossible. the orbit tool does not allow for anything else to be active. (and the draw method can't be called outside of a 'tool'). 👿

                                          1 條回覆 最後回覆 回覆 引用 0
                                          • D 離線
                                            driven
                                            最後由 編輯

                                            why do you want the grid lines?

                                            there may be other ways...

                                            john

                                            learn from the mistakes of others, you may not live long enough to make them all yourself...

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

                                            Advertisement