dim_print() ( Parametric )

Do not use this function if you want Python to mathematically evaluate a value. Python evaluates values using floating point notation. Use this function for output of results only.

About this tool :

Also see :


Purpose :

Python evaluates numerical values with decimal points as floats (decimal numbers) and outputs its results in floating point notation. When Units("feet") or " Units("inch-fraction") or Units ("inch") are entered in the startup code, Python returns inches. The dim_print function can be used to convert that output into a 'dimensional string' that is a based on the startup code Units(' ... ') that are specified in the Python script.

Startup Code Units Output form with dim_print
Units("feet") ft-in fractions
Units("inch") inches-sixteenths
Units("inch-fractions") inches fractions
Units("inch-decimal") inch.decimal
Units("metric") mm.decimal
>>> from param import Units, dim_print
>>> Units("feet")
>>> Shape("WT12x81").NominalDepth
12.0
>>> from param import dim_print
>>> dim_print(Shape("WT12x81").NominalDepth)
'1-0'
>>> dim_print(13.625) # 1 foot 1 inch and five-eighths
'1-1 5/8'
>>> Units("metric")
>>> Shape("WT12x81").NominalDepth # a number, millimeters
304.0000800001
>>> Units("inch")
>>> dim_print(13.625) # 13 inches and ten-sixteenths
'13-10'
>>> Units("inch-fraction")
>>> dim_print(13.625) # 13 inches and five-eighths
'13 5/8'

You might want to perform such a conversion prior to print a value as shown in the example below.

# Prints the distance between two points the user locates.
from point import PointLocate
from param import Units, dim_print
Units("feet")
pt1 = PointLocate("Locate 1st point")
pt2 = PointLocate("Locate 2nd point")
dist = pt1.Distance(pt2)
print("Actual distance: ", dim_print(dist))

Examples :

Try these examples at the Python Prompt with the primary dimension " Units " in Drawing Presentation set to ' Imperial (ft-in fractions) ' or Imperial (inches.decimal) ' or ' Imperial (in fractions) ' or ' Metric ''. You'll get the same results regardless of your setup choice.

>>> from param import Units, dim_print
>>> Units("feet")
>>> dim_print(12.00)
1-0         # one foot, zero inches
>>> dim_print(1.625)
1 5/8       # one and five-eighths inch
>>> dim_print(14.25)
1-2 1/4     # 1 foot, 2 1/4 inches
>>> dim_print(1-2) # one minus two (subtraction)
-1          # negative 1 inch

The Python Prompt will give you these results regardless of whether the primary dimension " Units " in Drawing Presentation are ' Imperial (ft-in fractions) ' or Imperial (inches.decimal) ' or ' Imperial (in fractions) ' or ' Metric '.

SDS2 Python Prompt

>>> from param import Units, dim_print >>> Units("feet") >>> dim_print(12.00) 12-0 # twelve inches and zero sixteenths >>> dim_print(1.625) 1-10 # one inch and ten-sixteenths >>> dim_print(14.25) 14-4 # 14 inches and four-sixteenths >>> dim_print(1-2) # subtraction -1-0 # negative 1 inch and zero-sixteenths
# Converts an imperial dimension to mm.
from param import Units, Prompt, dim_print, ResponseNotOK
Units("feet")                   # startup code units
try:
    inches = Prompt("1-2 1/2", "Enter a dimension:")
    mm = inches * 25.4
    print("Dimension in the startup code units =", dim_print(inches))
    print("Dimension in decimal inches =", inches)
    print("Dimension in mm =", mm)
except ResponseNotOK:
    pass