• Login
sketchucation logo sketchucation
  • Login
โš ๏ธ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Showing new geometry as its made?

Scheduled Pinned Locked Moved Developers' Forum
11 Posts 3 Posters 731 Views 3 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.
  • C Offline
    Chris Fullmer
    last edited by 16 Feb 2009, 06:27

    Hi, Ive written an incredible script (teeheehee) that makes groups of geometry. It makes a few hundred , but I'd like to be able to see them as they are made. IS there a way to refreshy the view or something after each one is made?

    Chris

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

    1 Reply Last reply Reply Quote 0
    • M Offline
      Matt666
      last edited by 16 Feb 2009, 07:36

      Sketchup.active_model.active_view.invalidate
      

      ??

      Frenglish at its best !
      My scripts

      1 Reply Last reply Reply Quote 0
      • C Offline
        Chris Fullmer
        last edited by 16 Feb 2009, 18:15

        I have a method that makes and randomly places a group and it has a small delay forced in their. So I have that method called in a loop for 100 times. In between calling that method I inserted your code. It didn't work for me. I still only see all the groups after the entire script is run. Did I put it in right?

        Chris

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

        1 Reply Last reply Reply Quote 0
        • C Offline
          Chris Fullmer
          last edited by 16 Feb 2009, 21:01

          Oh dear!, I'll look into the Tool class creation. I'm at school all day and I'm not supposed to be working on scripts because I have a big presentation on Wednesday ๐Ÿ˜ž So maybe if I get my work done for class I'll work on this, and possibly post my script for some pointers tonight or tomorrow. Thanks Matt and Todd,

          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 16 Feb 2009, 22:13

            Chris, you have to define a Tool class of tool. When you create a Tool, you have to create certain methods that will be called by SketchUp at the appropriate times. One of those is "draw".

            After you create a Tool, then you get access to methods like view.invalidate.

            Todd

            (edit: said simpler, your Tools' method "draw" will be called when one of your other methods issues view.invalidate)

            1 Reply Last reply Reply Quote 0
            • T Offline
              todd burch
              last edited by 16 Feb 2009, 23:30

              Chris, I was incorrect. It's not a Tool class you need, it's an Animation Class. However, you should be able to embed this functionality into your script, whether it is a Tool or not.

              I felt so bad about giving you wrong information, I wrote an example for you ๐Ÿ˜ฎ

              Todd

              
              require 'sketchup.rb' 
              
              class MiniTool 
              
              def initialize
              	@p1 = Geom;;Point3d.new ; 
              	@p2 = Geom;;Point3d.new ; 
              	@p3 = Geom;;Point3d.new ; 
              	@p4 = Geom;;Point3d.new ; 
              	@face = nil ; 
              	@count = 20 ; 
              end ; 
              
              def nextFrame(view)
              	if (@count==0) then 
              		@face.erase! ; 
              		Sketchup.active_model.active_view.animation = nil 
              		Sketchup.active_model.select_tool nil ; 
              		return ;
              	end; 
              	if (@count %2 ==0) then 
              		@face.erase! if @face ; 
              
              		x = rand(100) ; 
              		y = rand(100) ; 
              		x = -x if rand(10) > 5 ; 
              		y = -y if rand(10) > 5 ; 
              		z = 0 ; 
              		@p2.x = x ; 
              		@p3.x = x ; 
              		@p3.y = y ; 
              		@p4.y = y ; 
              		@face = Sketchup.active_model.entities.add_face(@p1,@p2,@p3,@p4) ; 
              		Sketchup.active_model.active_view.zoom_extents ; 
              	else 
              		@face.reverse! 
              		@face.material = 'red' 
              	end ; 
              	sleep(0.5) ; 
              	view.show_frame
              	@count -= 1 ; 
              end  # nextFrame 
              
              end ; # class MiniTool 
              
              
              class AnimatedToolExample 
              
              def initialize
              	Sketchup.active_model.active_view.animation = MiniTool.new
              	
              end 
              
              end # class AnimatedToolExample 
              
              
              if !file_loaded?(__FILE__) then 
              	UI.menu("Tools").add_item("Animated Tool") { Sketchup.active_model.select_tool AnimatedToolExample.new } 
              end
              
              file_loaded(__FILE__)
              
              
              
              1 Reply Last reply Reply Quote 0
              • C Offline
                Chris Fullmer
                last edited by 17 Feb 2009, 00:55

                Sweet!, Todd you rock. thanks for the example. I'll look it over and hopefully get it into my script soon (depending on class work). All this is for a Valentine's Ruby - I think I might not get it released by my target date..... lol

                Chris

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

                1 Reply Last reply Reply Quote 0
                • C Offline
                  Chris Fullmer
                  last edited by 17 Feb 2009, 01:00

                  Its like you can read my mind! That is frighteningly close to what I am trying to achieve, a huge thanks!

                  Chris

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

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    Chris Fullmer
                    last edited by 17 Feb 2009, 07:07

                    ok, lots of questions. Answer what you have time for ๐Ÿ˜„

                    So I've noticed from your example:

                    UI.menu("Tools").add_item("Animated Tool") { Sketchup.active_model.select_tool AnimatedToolExample.new }
                    

                    This selects a tool. And the AnimatedToolExample is considered a tool because it is defined as a class and it is actived with the "Sketchup.active_model.select_tool"? Is there anything else that makes it a tool? just that its a class and is called with the .select_tool method, right?

                    Also, inside the AnimatedToolExample class, there is a single method named "initialize". But there is nothing that calls the method. I expected to see a line like calling that method or else I thought it would not ever be invoked.

                    As I'm working through the example, I see that you don't call any of the methods the way I thought they had to be called. I thought you would need a line outside the method, but inside the class that would specify which method to initialize. I've never worked classes yet. If you call a class, does it automatically run through all the methods inside of it?

                    Also, the sleep method. I think that is what I was looking for. I made a way to "pause" the script using the system clock and a while statement. But Tavi pointed out that my method would freeze up Ruby entirely. So does sleep only freeze up this specific process then? Could I also run another ruby script without it being affected by the sleep in this script? That is what I think I understood in reading through the rDoc of the sleep method.

                    LASTLY. I ran it in SU6 at school just fine. But now in SU7 at home its splatting right after it makes the first face, but before it reverses the face. I'll see if I can degub it, but I wouldn't count on it ๐Ÿ˜„

                    Thanks Todd,

                    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 17 Feb 2009, 13:43

                      @chris fullmer said:

                      ok, lots of questions. Answer what you have time for ๐Ÿ˜„

                      So I've noticed from your example:

                      UI.menu("Tools").add_item("Animated Tool") { Sketchup.active_model.select_tool AnimatedToolExample.new }
                      

                      This selects a tool. And the AnimatedToolExample is considered a tool because it is defined as a class and it is actived with the "Sketchup.active_model.select_tool"?

                      Yes.

                      @chris fullmer said:

                      Is there anything else that makes it a tool? just that its a class and is called with the .select_tool method, right?

                      Anything else? No. Yes in that it's activated as you say. Tools have predefined methods that are called by SketchUp in a "callback" fashion if they are defined. Methods like "onLButtonDown" for on Left Mouse button down. So, if you want an interactive tool that is aware of mouse clicks, then you need a Tool. Note that the target of .select_tool doesn't have to be a class. It could be a class method too. (for example ....select_tool MyClass.mymethod )

                      @chris fullmer said:

                      Also, inside the AnimatedToolExample class, there is a single method named "initialize". But there is nothing that calls the method. I expected to see a line like calling that method or else I thought it would not ever be invoked.

                      Ruby Class Operation 101. Any class that gets instantiated, always get its "initialize" method called. In other Object Oriented programming terms, the "initialize" method is the class's "constructor".

                      @chris fullmer said:

                      As I'm working through the example, I see that you don't call any of the methods the way I thought they had to be called. I thought you would need a line outside the method, but inside the class that would specify which method to initialize. I've never worked classes yet.

                      You need to read up on classes. Programming with Ruby under SketchUp, with all the other scripters out there (here), you really need to encapsulate your scripts inside a class or module. Read the "warning to developers" sticky thread.

                      @chris fullmer said:

                      If you call a class, does it automatically run through all the methods inside of it?

                      No. You really don't ever "call a class". You instantiate a class and calls its methods on an instance of that class. As mentioned above, the initialize method of the class is called by Ruby for you when you instantiate a class.

                      @chris fullmer said:

                      Also, the sleep method. I think that is what I was looking for. I made a way to "pause" the script using the system clock and a while statement. But Tavi pointed out that my method would freeze up Ruby entirely.

                      Correct. You might be pausing the script, you are pegging the CPU @ 100% while you are doing it.

                      @chris fullmer said:

                      So does sleep only freeze up this specific process then?

                      Sleep blocks (block is the correct term, not "freezes") this thread. Sleeps causes the thread to go into a wait state until the sleep timer pops (expires).

                      @chris fullmer said:

                      Could I also run another ruby script without it being affected by the sleep in this script? That is what I think I understood in reading through the rDoc of the sleep method.

                      Theoretically, yes. However, the way Google implemented the Ruby API, it's all under a single thread, so once that thread is put to sleep, you can do nothing else. If there were multiple threads, then one could sleep while another continued to work.

                      @chris fullmer said:

                      LASTLY. I ran it in SU6 at school just fine. But now in SU7 at home its splatting right after it makes the first face, but before it reverses the face. I'll see if I can degub it, but I wouldn't count on it ๐Ÿ˜„

                      Sounds like a bug. I wrote this on SU 6.

                      @chris fullmer said:

                      Thanks Todd,

                      Chris

                      Welcome. ๐Ÿ˜„

                      1 Reply Last reply Reply Quote 0
                      • C Offline
                        Chris Fullmer
                        last edited by 17 Feb 2009, 18:04

                        Todd, thanks for the details! Very enlightening. And to put your mind at ease, I have been using modules to encapsulate my scripts. So there should be no namespace conflicts. I was unaware that any method defined as "initialize" will be called automatically. That is cool, and very good to know. And that exaplins how the methods were being called. All in all very informative and thanks for taking the time to respond to each question - there werew quite a few!

                        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
                        1 / 1
                        • First post
                          6/11
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement