Conversion with unit settings

Conversion with unit settings
 1ot = impact.gui.output_toolbox
 2
 3ot.clear()
 4
 5# define some string containing a length value, optionally with impact.units
 6val_str = "266.7mm"
 7
 8ot.add("Original Value: " + str(val_str))
 9
10# the Convertor object will be used to perform the unit conversions
11conv = impact.system.convertor
12
13# convert the string to a "double" value - this assumes current windows locale decimal separator is '.'
14value = conv.string_as_length(val_str)
15
16# output the value using the user's current unit settings and current locale
17ot.add("Converted Value (Current Locale): " + str(conv.length_as_string(value)))
18
19# retrieve the users current unit settings and locale
20unit_options = impact.active_database.unit_settings()
21
22ot.add("Users Locale: " + str(unit_options.locale))
23
24# set IConvertor to use these IUnitSettings
25conv.unit_settings = unit_options
26
27# define a length value using ',' decimal separator
28val_str = "266,7mm"
29
30ot.add("Original Value: " + str(val_str))
31
32# change the locale to german
33unit_options.locale = "de-DE"
34ot.add("New Locale: " + str(unit_options.locale))
35
36value = conv.string_as_length(val_str)
37
38ot.add("Converted Value (Specific Locale 'de-DE'): " + str(conv.length_as_string(value)))
39
40# now create some other unit settings from scratch
41unit_options = impact.creator.unit_settings()
42
43# With unit_options; unit_options .DistanceDecimals = 4; unit_options .DistanceType = ipDistanceFormat.dfInches; unit_options .DistanceSuffix = " inches"; unit_options .DistanceFractions = True; unit_options .DistanceDenominator = 16
44# End With
45
46# new IUnitSettings uses current Windows locale
47ot.add("New IUnitSettings Locale: " + str(unit_options.locale))
48
49# output the value using the alternative unit settings
50conv.unit_settings = unit_options
51
52ot.add("Converted Value (Imperial with fractions): " + str(conv.length_as_string(value)))
53
54# output the same value using a different locale
55unit_options.distance_fractions = False
56unit_options.locale = "es"
57
58ot.add("Locale: " + str(unit_options.locale))
59
60ot.add("Converted Value (Imperial Specific Locale 'es-ES'): " + str(conv.length_as_string(value)))
61
62# output again using the 'C' locale
63unit_options.locale = "C"
64
65ot.add("Locale: " + str(unit_options.locale))
66ot.add("Converted Value (Imperial Specific Locale 'C'): " + str(conv.length_as_string(value)))
67
68# output again using the current Windows locale
69unit_options.locale = ""
70ot.add("Locale: " + str(unit_options.locale))
71ot.add("Converted Value (Imperial Current Windows Locale): " + str(conv.length_as_string(value)))
72
73
74
75
76
77
78