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

    Using an observer to delete a screen note

    Scheduled Pinned Locked Moved Developers' Forum
    31 Posts 5 Posters 3.7k Views 5 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.
    • Chris FullmerC Offline
      Chris Fullmer
      last edited by

      I really don't blame you, that is a sensible way to do it I think.

      @Dan R., there is a free command line encoder called mencoder that will take a series of still images and turn it into any video format. It is Win, Mac, Linus capable too. I have thought to write a ruby to test out its capabilities half a dozeon times, and jhust never fully sat down and done it. If anyone ever does look at it, it would be awesomw if they posted their code snippet that interacts with that command line encoder.

      Chris

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

      1 Reply Last reply Reply Quote 0
      • P Offline
        pvbuero
        last edited by

        @danbig said:

        Call me unambitious, but I'm back to the strategy of placing the screen note on each scene, and hiding it on all the others. It would work for my workflow, and it seems digestible for me.
        I could then use the standard "export to animation" function to either jpg or avi, and (I think) it would come out as expected.

        I made it that way and it works:

         
        shadowtime_on_screen = [sunrise..sunset]
        
         for hour in sunrise..sunset
          time = Time.gm(2010,month,day,hour,minute,00)
          shadowinfo["ShadowTime"]= time
          shadowinfo["DisplayShadows"]= true 
          shadowtime_on_screen[hour] = Sketchup.active_model.add_note (shadInf.shadowtimetxt,0.1,0.2)
          shadowtime_on_screen[hour].hidden = true
         end
          for hour in sunrise..sunset
           time = Time.gm(2010,month,day,hour,minute,00)
           shadowinfo["ShadowTime"]= time
           shadowtime_on_screen[hour].hidden = false
           page = Sketchup.active_model.pages.add time.strftime("%d %b %H;%M Uhr")
           shadowtime_on_screen[hour].hidden = true
           page.delay_time= 0
           page.transition_time= 3
         end
        

        First I create all the notes on the screen and hide them, then I unhide one by one and create the corresponding pages.

        My next step will be to allow steps which are different from one hour... and as I learnd here I have to deal with jquery (sigh) to enter the start and the end time...

        Matthias

        1 Reply Last reply Reply Quote 0
        • D Offline
          danbig
          last edited by

          @unknownuser said:

          I made it that way and it works:

           
          shadowtime_on_screen = [sunrise..sunset]
          
           for hour in sunrise..sunset
            time = Time.gm(2010,month,day,hour,minute,00)
            shadowinfo["ShadowTime"]= time
            shadowinfo["DisplayShadows"]= true 
            shadowtime_on_screen[hour] = Sketchup.active_model.add_note (shadInf.shadowtimetxt,0.1,0.2)
            shadowtime_on_screen[hour].hidden = true
           end
            for hour in sunrise..sunset
             time = Time.gm(2010,month,day,hour,minute,00)
             shadowinfo["ShadowTime"]= time
             shadowtime_on_screen[hour].hidden = false
             page = Sketchup.active_model.pages.add time.strftime("%d %b %H;%M Uhr")
             shadowtime_on_screen[hour].hidden = true
             page.delay_time= 0
             page.transition_time= 3
           end
          

          Is this code ready to execute through the console or webconsole? I get an "undefined local variable" error for sunrise when I evaluate it.

          What I'd like to do is merge your code, above, with this script (Chris essentially wrote this, and I have simply tweeked it to suit my needs):
          I'm not as concerned with sunrise and sunset, if those values are used in your script. I prefer to set the start and stop times myself, and create the screen notes associated with the times and intervals I have chosen.

          model = Sketchup.active_model
          si = model.shadow_info
          ps = model.pages
          si["DisplayShadows"]= true
          #set the year, month, day, and time of first shading scene as follows; (year,month,day,hour,min,sec)
          t = Time.gm(2010,"dec",1,9,0,0).to_i
          
          
          #set number of days to repeat
          31.times do |day|
          si["ShadowTime_time_t"]=t
          page = ps.add
          #set scenes to save camera position (true or false)
          status = page.use_camera=false
          #set scene transition time to 0 from PM of previous day to AM of next day
          page.transition_time = 0.0
          #set hours from first scene for day until second scene for the same day (sec*min*hours)
          t= t+(60 * 60 * 6)
          si["ShadowTime_time_t"]=t
          page = ps.add
          status = page.use_camera=false
          page.transition_time = -1
          #set hours from second scene for day, until first scene of next day (sec*min*hours)
          t= t+(60 * 60 * 18)
          end
          
          
          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            @danbig said:

            Is this code ready to execute through the console or webconsole?
            NO.. because it is NOT wrapped in a module. When you run code like this in the console (or webconsole,) it runs INSIDE class Object. EVERYTHING in Ruby is a subclass of class Object, and inherits all of it's methods, constants and most important, it's local variables. (Say "Reference clashes, boys and girls!")
            When you declare a sunrise var (or any other var using a common word like start and stop,) in the console (ie, in Object,) you run the risk of clashing (overwriting,) a var of the same name, by another script (if it is also not module wrapped.)

            @danbig said:

            I get an "undefined local variable" error for sunrise when I evaluate it.
            You'd get the same for sunset.
            It's obviously a snippet from a larger script, where these local vars are predefined, most likely grabbing them from the model's ShadowInfo settings.

            Stay within YOUR namespace, YOUR namespace is your friend. It protects your code from the rest of the world, and visa versa.
            Don't have a namespace?
            Let's invent one, how about Danbig ?? (..you can chose another, but for example's sake..)

            In EACH and EVERYONE of your Ruby script files, all your code will be wrapped inside a Danbig module block, like:
            ` module Danbig

            code goes here.

            end # Danbig`
            Then for each separate plugin, you create a submodule inside YOUR Danbig namespace, so that YOUR plugins do not clash with each other. Like:

            module Danbig
              module ShadowAnim
                #
                # code goes here.
                #
              end # ShadowAnim
            end # Danbig
            

            The beauty is that module and class definitions can span across multiple files (but method defs cannot, a method def will totally redefine any method that is already defined***.)

            *** This is why you should NOT define methods in the console (inside Object,) as they will often end up redefining someone else's method, or worse (and it's happened,) one of the important Ruby methods of Object or Kernel [which is mixed-into Object,] causing problems for EVERYONE.)

            Anyhow.. you'd refer to your animation start method as:
            Danbig::ShadowAnim.start
            using the **::** scope operator.

            Now you don't need $global vars to share settings or info among your plugins. Just create either CONSTANTS, @@class vars or @attributes inside the Danbig module.
            Constants can be refered to (in individual plugin submodules,) as Danbig::CONSTANTNAME
            For @@ or @ vars you'd make getter and setter methods inside Danbig. It's easy to make @vars with the attr_accessor method.
            ` module Danbig

            setup common @vars for ALL my plugins

            attr_accessor(:time,:starttime,:endtime,:danbigmenu) #etc.
            endcreates attribute vars: @time @starttime @endtime @danbigmenuand methods: Danbig.time Danbig.starttime Danbig.endtime Danbig.danbigmenu Danbig.time= Danbig.starttime= Danbig.endtime= Danbig.danbigmenu=After attr_accessorthe @vars will all be nil, but you can (below that in code,) set them to an initial value inside the Danbig initialize` method.

            Oh! There I go again.. ranting on Namespaces. For more info from some of my other rants...
            http://forums.sketchucation.com/viewtopic.php?f=180&t=24356&p=255792#p254458
            and beginning post 4 at:
            http://groups.google.com/group/sketchupruby/browse_frm/thread/4f22a3ac2c3a8603/4d538051fc7cbf75?lnk=gst&q=File+spanning#4d538051fc7cbf75

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • P Offline
              pvbuero
              last edited by

              it 's just an extract of the script with the part where the notes are added and where the pages are added with the corresponding note unhidden...
              My script is far from perfect therefore I'didn't want to post it here.

              If you keep in mind, that it's the work of a beginner you can see it here complete:

              require 'sketchup'
              
              Sketchup.send_action "showRubyPanel;"
              
              class ShadowInformation
               @@shadowinfo = Sketchup.active_model.shadow_info
               def sunrisetxt
                 @sunrisetext = @@shadowinfo["SunRise"].gmtime.strftime("Sonnenaufgang;  %H;%M Uhr")
               end
              
               def sunsettxt
                 @sunsettext = @@shadowinfo["SunSet"].gmtime.strftime("Sonnenuntergang;  %H;%M Uhr")
               end
               def shadowdatetxt
                @shadowdatetxt = @@shadowinfo["ShadowTime"].gmtime.strftime("Tag des Jahres;  %d.%b")
               end
              
              def shadowtimetxt
                @shadowtimetxt = @@shadowinfo["ShadowTime"].gmtime.strftime("Uhrzeit;  %H;%M")
               end
              end
              
              
              UI.menu("Plugins").add_item("Shadowanimation"){create_scenes}
              
              def create_scenes
              
               shadInf = ShadowInformation.new
               #UI.messagebox shadInf.shadowtimetxt
               @xpos_shadowtime = 0.1
               @ypos_shadowtime = 0.2
              
               shadowinfo = Sketchup.active_model.shadow_info
               #Stunde des Sonnenauf- und Untergang ermitteln
               von_Stunde = (shadowinfo["SunRise"].gmtime.hour.to_s)
               bis_Stunde = ((shadowinfo["SunSet"].gmtime.hour + 1).to_s)
              
              
               # Hier werden die Parameter für die Verschattungsanimation abgefragt
               prompts = ["von-Stunde", "bis-Stunde"]
               defaults = [von_Stunde,bis_Stunde]
               list = ["1|2|3|4|5|6|7|8|9|10|11|12|","12|13|14|15|16|17|18|19|20|21|22|23|24"]
               input = UI.inputbox prompts, defaults, list, "Verschattungsanimation Voreinstellungen"
              
               sunrise = input[0].to_i
               sunset = input[1].to_i
               minute = 00
               day = shadowinfo["ShadowTime"].gmtime.day
               month = shadowinfo["ShadowTime"].gmtime.month
              
               shadowtime_on_screen = [sunrise..sunset]
              
               for hour in sunrise..sunset
                time = Time.gm(2010,month,day,hour,minute,00)
                shadowinfo["ShadowTime"]= time
                shadowinfo["DisplayShadows"]= true 
                shadowtime_on_screen[hour] = Sketchup.active_model.add_note (shadInf.shadowtimetxt,0.1,0.2)
                shadowtime_on_screen[hour].hidden = true
               end
                for hour in sunrise..sunset
                time = Time.gm(2010,month,day,hour,minute,00)
                shadowinfo["ShadowTime"]= time
                shadowtime_on_screen[hour].hidden = false
                page = Sketchup.active_model.pages.add time.strftime("%d %b %H;%M Uhr")
                shadowtime_on_screen[hour].hidden = true
                page.delay_time= 0
                page.transition_time= 3
               end
              Sketchup.active_model.add_note (shadInf.sunrisetxt,0.1,0.05)
              Sketchup.active_model.add_note (shadInf.sunsettxt,0.1,0.1)
              Sketchup.active_model.add_note (shadInf.shadowdatetxt,0.1,0.15)
              end
              

              The idea is, that you can choose the starting- and the end-hour and that sunrise-hour and sunset-hour are the default values...

              The next step would be the input of a start- and a end-time (instead of only the hour) and a that the time between the scenes could be choosen free. (instead of one hour steps).

              Matthias

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                @pvbuero said:

                If you keep in mind, that it's the work of a beginner you can see it here complete:

                A few issues I see at first glance:

                It's NOT wrapped in a module with YOUR namespace name.

                ONLY Ruby base classes should ever be defined at the top level. "Base class" means a generic global class used by the entire Ruby world (not just the Sketchup scripting realm.)

                If you only need one copy of the code, it should probably be a module.
                But if say (on a Mac where there can be more than 1 model open,) if each model needs it's own 'copy' (called an instance,) then a class is the thing to write (probably within a module that tracks and controls the instances of your class.)
                ie:

                
                module Pvbuero
                  module ShadowAnimManager
                    class ShadowInformation
                      # instance methods
                    end #class
                    # menu setup code
                    # other run once code
                    def create_scenes
                      # code here
                    end #def
                  end #mod
                end #mod
                
                

                call it as: Pvbuero::ShadowAnimManager.create_scenes
                (you can name your submodules whatever you wish, it's YOUR namespace.)

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • P Offline
                  pvbuero
                  last edited by

                  @unknownuser said:

                  Oh! There I go again.. ranting on Namespaces. For more info from some of my other rants...

                  that's not ranting. Thats most valuable information for beginners like me, who don't see the wood for the trees...

                  Great help.

                  Matthias

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @dan rathbun said:

                    call it as: Pvbuero::ShadowAnimManager.create_scenes

                    A little more on calling from scope to scope.

                    If your outside Pvbuero (in another module, or at the TOPLEVEL,) call it as:
                    Pvbuero::ShadowAnimManager.create_scenes

                    If your inside Pvbuero call it as:
                    ShadowAnimManager.create_scenes

                    If your inside ShadowAnimManager call it as:
                    create_scenes

                    Also there is the TOPLEVEL scope operator, that you can use so your nesting specification begins at the TOPLEVEL, no matter where your calling the code from, is called as:
                    ::Pvbuero::ShadowAnimManager.create_scenes

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      danbig
                      last edited by

                      Hi Dan -

                      Thank you for the rant; this is very helpful information for ruby explorers like myself.

                      Let me ask you a question about namespaces:

                      If I have two scripts in my plugin folder, which use the same namespace definition, they are essentially in the same "space," correct?

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        @danbig said:

                        If I have two scripts in my plugin folder, which use the same namespace definition, they are essentially in the same "space," correct?

                        YES because module (and class,) definitions can span more than one file.

                        BAD if everyone is trying to share the same namespace, such as Object (aka the TOPLEVEL namespace.)

                        GOOD because you can define your OWN namespace (as I showed,) and define ALL your plugins inside it, within submodules, or subclasses. Then your code can in no way clash with other people's code, and their code cannot clash with yours.
                        BUT, you can still cause your code to clash with itself. However, it's a lot easier to control and keep track of what YOU do, when you no longer have to worry about what the rest of the Sketchup Ruby coding realm is do wrong.

                        See my post at Google Groups on File Spanning:
                        File Spanning (start at post 4)

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • P Offline
                          pvbuero
                          last edited by

                          Hello,

                          I experimented a little with modules now and I think (hope) I now understand the use of them.

                          Despite all your great help it took me several hours till I found this:

                          @unknownuser said:

                          Like class methods, whenever you define a method in a module, you specify the module name followed by a dot and then the method name.

                          Before that I used the method name without the module name in front and nothing worked...

                          Matthias

                          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