Hello,
I am new to Python script for Dynamo.
I try to import Vector from Dynamo to Python script, but it seems Dynamo’s Geometry Conversion .ToXyz() could not convert the displacement vector’s units? I had to add the Unit Conversion in the script to adjust the displacement.
If I added the units conversion the element move the distance as I expected. I attached the Python script, please let me know if I understand something wrong? Revit 2018 Version 20170927_1515(x64) Dynamo Version 1.3.2.2480
#clr Common Language Runtime
import clr
#Import DocumentManager and TransactionManager
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#Import RevitAPI Classes
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
#Import geometry conversion extension methods
clr.AddReference(“RevitNodes”)
import Revit
#Adds ToDSType (bool) extension method to Wrapped elements
clr.ImportExtensions(Revit.Elements)
#Adds ToProtoType, ToRevitType geometry conversion extension methods to objects
clr.ImportExtensions(Revit.GeometryConversion)
ele = UnwrapElement(IN[0])
vectorTransform = IN[1].ToXyz()
OUT =
doc = DocumentManager.Instance.CurrentDBDocument
#Modify Units
getDocUnits = doc.GetUnits()
getDisplayUnits = getDocUnits.GetFormatOptions(UnitType.UT_Length).DisplayUnits
unitConversion = UnitUtils.ConvertFromInternalUnits(1, getDisplayUnits )
TransactionManager.Instance.EnsureInTransaction(doc)
vectorTransformUnits = vectorTransform/unitConversion
#Move Elementhttp://www.revitapidocs.com/2018.1/781ad017-5ee5-f44b-5db2-e8e1f883ae5d.htm
moveElement = ElementTransformUtils.MoveElement(doc, ele.Id, vectorTransformUnits)
TransactionManager.Instance.TransactionTaskDone()
OUT = moveElement