Get element coordinate system

Hello.
I would like to know if there is a way to retrieve the local coordinate system of a placed family in a model?

Something like this.

I tryed to get the coordinates of the element… but with element.GetLocation i can only get the x and Y coordinates of the family… Is there a way to find the Z ?

Here is a snippet from one of my graphs which may help you:

loc = element.Location

if isinstance(loc, LocationPoint):
	pt = loc.Point
	x = pt.X
	y = pt.Y
	z = pt.Z
	
elif isinstance(loc, LocationCurve):
	crv = loc.Curve
	pt1 = crv.GetEndPoint(0) # Start point
	pt2 = crv.GetEndPoint(1) # End point
	x1 = pt1.X
	y1 = pt1.Y
	z1 = pt1.Z
	x2 = pt2.X
	y2 = pt2.Y
	z2 = pt2.Z
2 Likes

Other than @cgartland’s answer, which is correct if you want to use python, Element.Location from the clockwork package should give you what you need. But just to confirm, it is a point you are after right? Not a coordinate system?

1 Like

I’m looking for both a coordinate system and the location point…
I think that a coordinate system would suffice… because the point i’m looking for would be it’s origin

Hi @ramoon.bandeira, thought as much. Here is how you can get the coordinate system using Python by getting the Elements Transform and using this to create the CS, I have added some visualisation geometry which you can remove from the code as it’s only for demonstration…

"""
Description: Returns the Coordinate System of the Element.
Author: Dan Woodcock
Website: https://danimosite.wordpress.com
Licence: N/A
"""

###### Imports ######

import clr

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript import Geometry as geom

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

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

###### Definitions ######

# Ensure object is a list and iterable...
def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

# Create a coordinate system from the Element Transform...
def CreateCoordinateSystem(t):
	return geom.CoordinateSystem.ByOriginVectors(t.Origin.ToPoint(),t.BasisX.ToVector(),t.BasisY.ToVector(),t.BasisZ.ToVector())

# Create graphical Axes for visualisation purposes...
def VisualiseAxes(t,l):
	o = t.Origin.ToPoint()
	
	xAxis = geom.Line.ByStartPointDirectionLength(o,t.BasisX.ToVector(),l)
	yAxis = geom.Line.ByStartPointDirectionLength(o,t.BasisY.ToVector(),l)
	zAxis = geom.Line.ByStartPointDirectionLength(o,t.BasisZ.ToVector(),l)
	
	return xAxis,yAxis,zAxis

###### Inputs ######

elems = tolist(UnwrapElement(IN[0])) # The Elements
l = tolist(IN[1])[0] # The length of the Axes for visualisation

###### Outputs ######

cSystems = []
vGeom = []

###### Main Script ######

for e in elems:
	t = e.GetTransform()
	cSystems.append(CreateCoordinateSystem(t))
	vGeom.append(VisualiseAxes(t,l))

# Return the results to the user...
OUT = cSystems,vGeom

Cheers,
Dan

5 Likes

Thanks for your support.
It creates the coordinate system pointing to the right directions and it’s origin is at the right coordinates of X and Y. But the Z value of the origin of the coordinate System is equal to 0… i would like to adjust it to the right position. Is there a way to do so?

Thank you Once again!

I’m not sure if I follow @ramoon.bandeira, the Transform gives you the placement point of the family and orientation. If it is saying the z value is zero, that is because it is placed at 0 (relative coordinates). Could you supply some more imagery or a file so I can understand where/what the problem is?

Cheers,
Dan

1 Like

The zero is aligned to the CAD file below those fixtures. It retrieves the x and y properties correctly. But when it comes to the Z coordinate it locates the fixture at coordinate 0.

I believe it is due to the fact that when we instanciate that family, we pick a point at the plane, and then we change (most times manually) the values of Z.

Is there a way to get this value of Z without Getting the parameter Offset?

Sometimes the family has a default vertical displacement, and it is not displayed at the offset parameter.

It shouldn’t matter, when you set the offset, the transform is updated (or should be). See below…

I don’t know much of fixtures as I have a structural background, so maybe there is something I am missing?

Indeed. I think the problem happens when you define the height of the element inside the family enviroment, before pushing it to the model. But i managed to find the solution i desired without that coordinate value.
Thank you very much!

Awesome! Yup, the Element Transform only gives you the placement point and orientation of the family instance, if you have shifted your geometry inside the family this will not account for that. Perhaps a better method would be to get the geometry bounding box and set the coordinate system origin to the bounding box centre (or whatever point).

Glad you found another way though! :smile:

Cheers,
Dan

2 Likes

Spot on @Daniel_Woodcock1 !
Great work.

1 Like