Nice @c.poupin ! Thank you for taking the time to respond
I solved it like this:
# IMPORT
import sys
import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import UnitUtils, DisplayUnitType, XYZ, Transform
# DEFINITION
def mm_to_feet(val):
"""this function converts mm to foot"""
return UnitUtils.Convert(
val,
DisplayUnitType.DUT_MILLIMETERS,
DisplayUnitType.DUT_DECIMAL_FEET)
def degrees_to_radians(val):
"""this function converts degrees to radian"""
return UnitUtils.Convert(
val,
DisplayUnitType.DUT_DECIMAL_DEGREES,
DisplayUnitType.DUT_RADIANS)
def cs_by_axis_rot_xyz(a=XYZ(0,0,1), r=0, x=0, y=0, z=0):
"""this function creates, rotates and moves a coordinate system"""
return Transform.CreateRotation(
a, degrees_to_radians(r)).ToCoordinateSystem().Translate(x,y,z)
def point_by_cartesian_cs(cs, x=0, y=0, z=0):
"""this function creates a point in a specific coordinate system"""
return XYZ().ToPoint().ByCartesianCoordinates(cs, x, y, z)
def create_line(p0, p1):
"""this function creates a line between two points"""
return Autodesk.Revit.DB.Line.CreateBound(
p0.ToXyz(), p1.ToXyz()).ToProtoType()
# MAIN
# create local coordinate system
cs = cs_by_axis_rot_xyz(x=100, y=100, z=100)
# create points in local coordinate system
p0 = point_by_cartesian_cs(cs, x=10)
p1 = point_by_cartesian_cs(cs, x=20)
p2 = point_by_cartesian_cs(cs, x=10, y=5)
p3 = point_by_cartesian_cs(cs, x=20, y=5)
# create lines
l0 = create_line(p0, p1)
l1 = create_line(p2, p3)
#OUTPUT
OUT = cs, p0, p1, p2, p3, l0, l1
Do you have any objections to the code?
Best regards,
Mikael