Python output in mm?

Hi all,

Found the Python-code below in this tread.
It checks a list of viewports, and returns the corresponding minpoint, maxpoint and longitudes.
Only downside is that it returns the output in feet, but i would like mm as output.
Is it possible to add some code to change the output units?

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
from Autodesk.DesignScript.Geometry import Point as ProtoPoint

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
from RevitServices.Transactions import TransactionManager
from RevitServices.Persistence import DocumentManager

# The inputs to this node will be stored as a list in the IN variables.
doc= DocumentManager.Instance.CurrentDBDocument
dataEnteringNode = IN

maxp = []
minp = []
longitudes = []
longitud = 0
if type(IN[0]) !=list:IN[0] = [IN[0]]

for i in IN[0]:
#	doc.Regenerate()
p = UnwrapElement(i).GetBoxOutline()
max = p.MaximumPoint
min = p.MinimumPoint
maxp.append(ProtoPoint.ByCoordinates(max.X,max.Y,0))
minp.append(ProtoPoint.ByCoordinates(min.X,min.Y,0))
longitudes.append(p.GetDiagonalLength())

TransactionManager.Instance.EnsureInTransaction(doc)

doc.Regenerate()

TransactionManager.Instance.TransactionTaskDone()

# Assign your output to the OUT variable.
OUT = [maxp,minp,longitudes]

Yep:

1 Like

Hi Thomas,

Thanks for the hint.
Unfortunately, I am not ready to write my own Python code yet. But I know about what’s going on inside the code. So I’ve used your clue, and parts from another Python script (“Replace viewports by center” Data-Shapes package), and put together the code below.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
from Autodesk.DesignScript.Geometry import Point as ProtoPoint

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitServices')
from RevitServices.Transactions import TransactionManager
from RevitServices.Persistence import DocumentManager

# The inputs to this node will be stored as a list in the IN variables.
doc= DocumentManager.Instance.CurrentDBDocument

UIunit = Document.GetUnits(doc).GetFormatOptions(UnitType.UT_Length).DisplayUnits
def convunit(x):
    return UnitUtils.ConvertFromInternalUnits(x,UIunit)

dataEnteringNode = IN

maxp = []
minp = []
longitudes = []
longitud = 0
if type(IN[0]) !=list:IN[0] = [IN[0]]

for i in IN[0]:
#	doc.Regenerate()
	p = UnwrapElement(i).GetBoxOutline()
	max = p.MaximumPoint
	min = p.MinimumPoint
	maxp.append(ProtoPoint.ByCoordinates(convunit(max.X),convunit(max.Y),0))
	minp.append(ProtoPoint.ByCoordinates(convunit(min.X),convunit(min.Y),0))
	longitudes.append(convunit (p.GetDiagonalLength()))

TransactionManager.Instance.EnsureInTransaction(doc)

doc.Regenerate()

TransactionManager.Instance.TransactionTaskDone()

# Assign your output to the OUT variable.
OUT = [maxp,minp,longitudes]

The code now works the way I would like it to, but if anyone has ideas for cleaning it up, I would love to learn from that.