In order to carry out certain geometric operations, it is essential to understand how the coordinate system is represented in Revit, e.g. represent points in a local XYZ axis instead of the global XYZ axis. The coordinate system is represented by the transform class with a 3×4 matrix as follows. Where, BasisX, BasisY and BasisZ are vectors pointing from the Origin.
The Dynamo graph below helps us to better visualize this, where the Transform of a selected wall in Revit was used for demonstration. As we would expect, the default coordinate system of any instance starts from the Origin (0, 0, 0), with XYZ unit vectors pointing in its respective direction, i.e. BasisX (1, 0, 0), BasisY (0, 1, 0) and BasisZ (0, 0, 1). *Lines representing axes were extended for visualization purposes.
The CreateTranslation Method translates the Transform or Coordinate System with a given vector and returns the translated Transform. In the example given below, the axes were translated to the Minimum point of the wall’s bounding box.
The CreateRotation and CreateRotationAtPoint methods rotates a given Transform, i.e. Coordinate System, with a given angle, axis of rotation and point of rotation.
The point of rotation is required for the CreateRotationAtPoint method, whereas CreateRotation will default the point of rotation as (0, 0, 0). In the given example below, the original axes was rotated by 45 degrees.
The python code used in the Dynamo graph is as shown below. Dynamo file can be downloaded here! Happy weekend ahead! 🙂
import clr clr.AddReference("RevitNodes") import Revit clr.ImportExtensions(Revit.Elements) clr.AddReference("RevitAPI") import Autodesk from Autodesk.Revit.DB import * clr.AddReference('DSCoreNodes') clr.AddReference('ProtoGeometry') clr.ImportExtensions(Revit.GeometryConversion) from DSCore import * clr.AddReference("RevitServices") from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instance.CurrentDBDocument uiapp = DocumentManager.Instance.CurrentUIApplication app = uiapp.Application def GetAxes(transform): axes =  axes.append(transform.Origin.ToPoint()) axes.append(transform.BasisX.ToVector()) axes.append(transform.BasisY.ToVector()) axes.append(transform.BasisZ.ToVector()) return axes wall = UnwrapElement(IN) output =  #Get wall bounding box wallBoundBox = wall.get_BoundingBox(doc.ActiveView) #Original originalTransform = wallBoundBox.Transform originalAxes = GetAxes(originalTransform) #Translated translatedTransform = originalTransform.CreateTranslation(wallBoundBox.Min) translatedAxes = GetAxes(translatedTransform) #Rotated angle = 0.785 rotatedTransform = originalTransform.CreateRotationAtPoint(originalTransform.BasisZ, angle, originalTransform.Origin) rotatedAxes = GetAxes(rotatedTransform) OUT = originalAxes, translatedAxes, rotatedAxes
Autodesk. Geometry Helper Classes.