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

    [Code] GE "GeoLocation" AttributeDictionary v1.1.0

    Scheduled Pinned Locked Moved Developers' Forum
    1 Posts 1 Posters 840 Views 1 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by


      [ Code ] GoogleEarth "GeoLocation" AttributeDictionary


      module Author
      
        #  georeference_dictionary()
        #  georeference_dictionary( [output=false [, popup=false]] )
        #  georeference_dictionary( ;output => true )
        #  georeference_dictionary( ;popup => true  )
        #
        #  Returns the dictionary object if defined, or nil if not.
        #
        #  Args; (all defaults are false.)
        #
        #  [output]   (boolean) If true, outputs to STDOUT.
        #  [popup]    (boolean) If true, shows info in messagebox.
        #
        def self.georeference_dictionary( *args )
          #--
          #  Method Version;  1.1.0
          #++
          geodict = Sketchup.active_model.attribute_dictionary("GeoReference")
          return geodict if args.empty?
          if args[0].is_a?(Hash)
            args[0].keys.each{|k| args[0][k.to_sym]= args[0][k] if k.is_a?(String) }
            output =( args[0][;output] ? true ; false )
            popup  =( args[0][;popup]  ? true ; false )
          else
            output =( args[0] ? true ; false )
            popup  =( args.length>1 ? ( args[1] ? true ; false ) ; false )
          end
          return geodict unless output || popup
          #
          unless geodict
            msg = %[Dictionary;  "GeoReference" not defined.      \n]
            puts( "\n"<<msg ) if output
            UI.messagebox(msg,MB_OK) if popup
          else
            msg = %[Dictionary;  "GeoReference" (keys; #{geodict.length})]
            if geodict.length==0
              msg<< "      \n"
            else
              msg<< "\n"
              keywid = geodict.keys.max{|a,b| a.length <=> b.length }.length
              geodict.each {|k,v| msg<< %[  "#{k}"].ljust(keywid+7,'.')<<%[; "#{v}"\n] }
              msg<<"\n" 
            end
            puts( "\n"<<msg ) if output
            if popup
              if geodict.length==0
                UI.messagebox(msg,MB_OK|64)
              else
                UI.messagebox(msg,MB_MULTILINE,%q[  AttributeDictionary; "GeoReference"])
              end
            end
          end
          #
          return geodict
          #
        end # def
      
      end # your module
      
      

      EDIT:

      • shortened method name to " georeference_dictionary"

      You can always alias it or change the name in your module:

      • added two optional arguments to control output.
        EDIT: v1.1.0

      • can now take Hash arguments* refined formatting of output

      Screen shots:

      STDOUT shown in the Console.

      Popup when GeoReference dictionary is not defined.

      Popup when GeoReference dictionary is defined, but empty.

      Popup when GeoReference dictionary has attributes. (Those shown were purely for testing purposes.)

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Buy SketchPlus
      Buy SUbD
      Buy WrapR
      Buy eBook
      Buy Modelur
      Buy Vertex Tools
      Buy SketchCuisine
      Buy FormFonts

      Advertisement