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

    Checking Template Units

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 551 Views 2 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.
    • medeekM Offline
      medeek
      last edited by

      I'm sure this has been asked before but I'm not seeming to find it so I will ask again. I want to be able to detect whether the user is using a metric or imperial template so I can customize my plugin user interface to the correct units. What is the suggested way to check for metric vs. imperial units of the template being used?

      Nathaniel P. Wilkerson PE
      Medeek Engineering Inc
      design.medeek.com

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        Btw, I wrote a general article on how to deal with units in SketchUp: http://www.thomthom.net/thoughts/2012/08/dealing-with-units-in-sketchup/

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

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          You don't really check the templates - you just ask the current model the user is using. The current model might be of a different unit than their selected template.
          At my previous job we switched a lot between mm and m in our project files.

          You use model.options to inspect the current model's options:

          
          options_manager = Sketchup.active_model.options
          options_manager.keys.each { |options_provider_name|
            puts options_provider_name
            options_provider = options_manager[options_provider_name]
            options_provider.each { |key, value|
              puts "> #{key} - #{value}"
            }
          }
          
          

          Output from that snippet:

          
          PageOptions
          > ShowTransition - false
          > TransitionTime - 2.0
          UnitsOptions
          > LengthPrecision - 0
          > LengthFormat - 0
          > LengthUnit - 2
          > LengthSnapEnabled - false
          > LengthSnapLength - 0.03937007874015748
          > AnglePrecision - 1
          > AngleSnapEnabled - true
          > SnapAngle - 15.0
          > SuppressUnitsDisplay - false
          > ForceInchDisplay - false
          SlideshowOptions
          > LoopSlideshow - true
          > SlideTime - 1.0
          NamedOptions
          PrintOptions
          > PrintWidth - 8.5
          > PrintHeight - 11.0
          > ComputeSizeFromScale - false
          > SizeInPrint - 1.0
          > SizeInModel - 1.0
          > VectorMode - false
          > FitToPage - true
          > NumberOfPages - 1
          > LineWeight - 0.5
          > PixelsPerInch - 150.0
          > SectionSlice - false
          > ModelExtents - true
          > PrintQuality - 0
          > ScaleAdjustment - 1.0
          > QualityAdjustment - 1.0
          
          

          So in this case you want to inspect UnitOptions:

          
          model = Sketchup.active_model
          model.options["UnitsOptions"]["LengthUnit"]
          
          

          Note that you want to use the constants in the class Length against the values returned here.

          
          Length;;Decimal
          Length;;Architectural
          Length;;Engineering
          Length;;Fractional
          Length;;Inches
          Length;;Feet
          Length;;Millimeter
          Length;;Centimeter
          Length;;Meter
          
          

          So something like this:

          
          model = Sketchup.active_model
          unit_type = model.options["UnitsOptions"]["LengthUnit"]
          metric = case unit_type
          when Length;;Millimeter, Length;;Centimeter, Length;;Meter
            true
          else
            false
          end
          
          

          I'm doing this check because LengthFormat got options that can be used with both imperial and metric units.

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

          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