CoordinateSystem

Hello

I have this code written with Python and DesignScript:

# creating local coordinare system
loc_cs = CoordinateSystem.ByOriginVectors(
	Point.ByCoordinates(2, 2, 2),
	CoordinateSystem.Identity().XAxis,
	CoordinateSystem.Identity().YAxis,
	CoordinateSystem.Identity().ZAxis)

# rotated local coordinate system
rot_cs = CoordinateSystem.Rotate(
	loc_cs, 
	loc_cs.Origin, 
	loc_cs.ZAxis, 
	20)

Would need to write this code using the Revit API.

Do any of you have any suggestions?

Best regards,
Mikael

Hello,

I think you need just a output

# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# creating local coordinare system
loc_cs = CoordinateSystem.ByOriginVectors(
	Point.ByCoordinates(2, 2, 2),
	CoordinateSystem.Identity().XAxis,
	CoordinateSystem.Identity().YAxis,
	CoordinateSystem.Identity().ZAxis)

# rotated local coordinate system
rot_cs = CoordinateSystem.Rotate(
	loc_cs, 
	loc_cs.Origin, 
	loc_cs.ZAxis, 
	20)
	
OUT = loc_cs,rot_cs

grafik

KR

Andreas

Hello @Draxl_Andreas ,

Thanks for the reply! Your solution works great :slight_smile:

I managed to solve this with the API. I am sure that there are more efficient algorithms to solve this problem, but feel free to take a look at this below :slight_smile:

#  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


# 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 coordsys_by_axis_rot_and_xyz(axis, rot, x, y, z):
	"""this function creates, rotates and moves a coordinate system"""
	return XYZ().ToPoint().ContextCoordinateSystem.ToTransform().CreateRotation(
		axis, degrees_to_radians(rot)).ToCoordinateSystem().Translate(x, y, z)


# MAIN
# create reference coordinate system
ref_cs = coordsys_by_axis_rot_and_xyz(XYZ(0, 0, 1), 0, 0, 0, 0)

# create local coordinate system
rot_cs = coordsys_by_axis_rot_and_xyz(XYZ(0, 0, 1), 45, 1000, 1000, 1000)

# create points in local coordinate system
p_0 = XYZ().ToPoint().ByCartesianCoordinates(rot_cs, 100 ,0, 0)
p_1 = XYZ().ToPoint().ByCartesianCoordinates(rot_cs, 200 ,0, 0)


#OUTPUT
OUT = ref_cs, rot_cs, p_0, p_1
3 Likes

@c.poupin any suggestions?

Hi,
I’m not with my PC but you can try this


# Create Transform (Coordinates System)
tf1 = Transform.CreateRotation(XYZ(0,0,1), 0.785) #radian
tf2 = Transform.CreateTranslation(XYZ(2,2,2))
tf3 = tf2 * tf1
# End Transform 
# Apply Transform to a point
oldpt = XYZ(2,0,0)
newtpt = tf3.OfPoint(oldpt)
2 Likes

Nice @c.poupin ! Thank you for taking the time to respond :slight_smile:

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

no, you just need to update your code for Revit 2021+ (ForgeTypeId)

2 Likes

This is new to me! What’s ForgeTypeId?

see here (paragraph 1.3)

Great man! Thank you :slight_smile:

A post was split to a new topic: Translate the LCS of analytical member