Coordinate and size values in the Electronics API are stored as signed integers in internal editor units. This is the same convention as User Language Programs (ULP). The resolution is 1/320000 mm per count (0.003125 µm per count). Any property in the class reference that says “internal units” uses this representation.
Static methods on adsk.electron.Units convert from those integers to millimeters, inches, mils, or microns for display, reporting, or math in physical units.
All listed methods are static. In Python they take a single int and return a float.
| Method | Argument | Returns |
|---|---|---|
Units.u2mm(n) |
Value in internal units | Millimeters |
Units.u2inch(n) |
Value in internal units | Inches |
Units.u2mil(n) |
Value in internal units | Mils (1/1000 inch) |
Units.u2mic(n) |
Value in internal units | Microns (1/1000 mm) |
The example below assumes the active product is a Board, as described in Introduction to the Electronics API. It iterates elements (placed components), converts x and y from internal units to millimeters, and writes a short line to the log for each one.
# Get the application and cast the active product to a board.
import adsk.core
import adsk.electron
app = adsk.core.Application.get()
board = adsk.electron.Board.cast(app.activeProduct)
if board is None:
app.log("Active product is not a board.")
return
# Walk all placed elements and print origin in mm.
for i in range(int(board.elements.count)):
el = board.elements.item(i)
x_mm = adsk.electron.Units.u2mm(el.x)
y_mm = adsk.electron.Units.u2mm(el.y)
app.log("{0}: ({1:.3f}, {2:.3f}) mm".format(el.name, x_mm, y_mm))
The example below reads the first sheet’s bounding area and converts all four corners to millimeters.
# Cast to a schematic and read the first sheet's area box.
import adsk.core
import adsk.electron
app = adsk.core.Application.get()
schematic = adsk.electron.Schematic.cast(app.activeProduct)
if schematic is None or int(schematic.sheets.count) < 1:
return
sheet = schematic.sheets.item(0)
a = sheet.area
x1 = adsk.electron.Units.u2mm(a.x1)
y1 = adsk.electron.Units.u2mm(a.y1)
x2 = adsk.electron.Units.u2mm(a.x2)
y2 = adsk.electron.Units.u2mm(a.y2)
app.log(
"Sheet {0} mm bounds: ({1:.3f}, {2:.3f}) – ({3:.3f}, {4:.3f})".format(
sheet.name, x1, y1, x2, y2
)
)