lib/su_info/Template_Code.rb
# Loads RenderingOptions constants, dumps value and name to the console,
# then hooks up an observer and outputs info about the callback and what
# ro's have changes
#
Loads RenderingOptions constants, dumps value and name to the console,
then hooks up an observer and outputs info about the callback and what
ro's have changes
Loads RenderingOptions constants dumps value and name to the console then hooks up an observer and outputs info about the callback and what ro ' s have changes
def ro_1
    am = Sketchup.active_model
    cns = Sketchup::RenderingOptions
    @@h_ro = {}
    am.rendering_options.each { |k,v|
      val = v.kind_of?(Sketchup::Color) ? v.to_s.slice(-20,20) : v
      @@h_ro[k] = val
    }
    @@roc = Hash.new("** No Constant! **")
    cns.constants.each { |c|
      text = c.to_s.dup
      if    ( text =~ /^ROPSet/ ) ; text.sub!(/^ROPSet/, 'ROPSet  ')
      elsif ( text =~ /^ROP/    ) ; text.sub!(/^ROP/   , 'ROP     ')
      end
      @@roc[cns.const_get(c)] = text
    }
    cnsl = '-----------------------------------------'
    puts cnsl + '  ro_1()'
    prev = -1
    @@roc.sort.each { |r|
      num = r[0].to_s.rjust(3) + ((prev + 1 != r[0]) ? "*" : " ")
      puts "#{num} #{r[1]}"
      prev = r[0]
    }
    puts cnsl
    @obs_ro1 = Sketchup::RenderingOptionsObserver.new
    @obs_ro1.instance_eval {
      @tmr_stopped = true
      def onRenderingOptionsChanged(ro, type)
        if (@tmr_stopped)
          @tmr_stopped = false
          UI.start_timer(0.100) { @tmr_stopped = true ; puts }
        end
        s_val = ''
        ro.each { |k,v|
          val =  v.kind_of?(Sketchup::Color) ? v.to_s.slice(-20,20) : v
          if (@@h_ro[k] != val)
            @@h_ro[k] = val
            val = "%e" % v if (v.class == Float)
            s_val << "#{val.to_s.rjust(20)} #{k}"
          end
        }
        puts "#{type.to_s.rjust(2)} #{@@roc[type].ljust(32)}  #{s_val}"
      end
    }
    am.rendering_options.add_observer(@obs_ro1)
  end
def ro_1 am = Sketchup . active_model cns = Sketchup :: RenderingOptions @@h_ro = { } am . rendering_options . each { | k , v | val = v . kind_of? ( Sketchup :: Color ) ? v . to_s . slice ( - 20 , 20 ) : v @@h_ro [ k ] = val } @@roc = Hash . new ( "** No Constant! **" ) cns . constants . each { | c | text = c . to_s . dup if ( text =~ / ^ROPSet / ) ; text . sub! ( / ^ROPSet / , 'ROPSet  ' ) elsif ( text =~ / ^ROP / ) ; text . sub! ( / ^ROP / , 'ROP     ' ) end @@roc [ cns . const_get ( c ) ] = text } cnsl = '-----------------------------------------' puts cnsl + '  ro_1()' prev = - 1 @@roc . sort . each { | r | num = r [ 0 ] . to_s . rjust ( 3 ) + ( ( prev + 1 != r [ 0 ] ) ? "*" : " " ) puts "#{num} #{r[1]}" prev = r [ 0 ] } puts cnsl @obs_ro1 = Sketchup :: RenderingOptionsObserver . new @obs_ro1 . instance_eval { @tmr_stopped = true def onRenderingOptionsChanged ( ro , type ) if ( @tmr_stopped ) @tmr_stopped = false UI . start_timer ( 0.100 ) { @tmr_stopped = true ; puts } end s_val = '' ro . each { | k , v | val = v . kind_of? ( Sketchup :: Color ) ? v . to_s . slice ( - 20 , 20 ) : v if ( @@h_ro [ k ] != val ) @@h_ro [ k ] = val val = "%e" % v if ( v . class == Float ) s_val << "#{val.to_s.rjust(20)} #{k}" end } puts "#{type.to_s.rjust(2)} #{@@roc[type].ljust(32)}  #{s_val}" end } am . rendering_options . add_observer ( @obs_ro1 ) end
Loads RenderingOptions constants, dumps value and name to the console,
then hooks up an observer and outputs info about the callback and what
ro's have changes
Loads RenderingOptions constants dumps value and name to the console then hooks up an observer and outputs info about the callback and what ro ' s have changes
# create a hash of ro keys # hash @@roc = RenderingOptions constants #   key   is constant value #   value is constant name, with some spacing added by RegEx # get all the constants, parse names, add to hash # dump hash to console # create a RenderingOptionsObserver instance & add callback method # timer puts line breaks between ro changes when multiple ocurr # Loop thru ro's and find changes, load into s_val # finally put info to console # attach the observer