How to get correct rotation from Transforms of (Nested) Families

How to get correct rotation from Transforms of (Nested) Families

Anonymous
Not applicable
1,377 Views
8 Replies
Message 1 of 9

How to get correct rotation from Transforms of (Nested) Families

Anonymous
Not applicable

Hey, I can't figure out how to get the same rotation value (as XYZ) from a Transform when using Transform.OfPoint(XYZ).

 

I'll try to explain, for example I'm exporting a family that has nested family placed on the Center Left/Right plane (see blow):

G0fG7Bh

 

When I export its geometry by using Transform.OfPoint(XYZ) of each of its vertices, the position & rotation is correctly retrieved (the pyramid is pointing in the positive X direction, so west to east).

I got the origin of the transform as the local position of the nested family, but how do I get the rotation value from the Transform as a XYZ?

 

I tried to calculate it from the Transform using the following method:

public static XYZ getRotationFromTransform(Transform transform) {
    double x = Math.Atan2(transform.BasisZ.Y, transform.BasisZ.Z) * (180 / Math.PI);
    double y = Math.Atan2(transform.Inverse.BasisZ.X, Math.Sqrt((transform.BasisZ.Y * transform.BasisZ.Y) + (transform.BasisZ.Z * transform.BasisZ.Z))) * (180 / Math.PI);
    double z = Math.Atan2(transform.BasisY.X, transform.BasisX.X) * (180 / Math.PI);

    return new XYZ(x, y, z);
}

But that seems to be wrong for nested family transforms.

The same seems to be true for the LocationPoint.Rotation value for nested families (or at least it is view based) as discussed here: http://thebuildingcoder.typepad.com/blog/2013/06/correct-detail-component-rotation-in-elevation-view... And that value is just a double, without any reference to what axis the rotation is happing on.

 

So how come the export result is good when using Transform.OfPoint(XYZ), but I can't get the XYZ rotation from the same Transform? In other words: How do I get the rotation from a FamilyInstance Transform?

 

If you have any questions, just ask and I'll try my best to give an answer or more information.

0 Likes
1,378 Views
8 Replies
Replies (8)
Message 2 of 9

aignatovich
Advisor
Advisor

Hi!

 

Your x, y, z looks as Euler angles (but, i am not sure, that formulas are correct), not as an rotation axis.

 

You may try to get nestedFamily.GetTotalTransform() and calculate x, y, z and angle from this equations:
https://wikimedia.org/api/rest_v1/media/math/render/svg/7dc67eaa6d74f6629767726f854a5ff8bf7e5477

 

See also https://en.wikipedia.org/wiki/Euler_angles

 

this (X, Y, Z) will be axis direction, don't forget about origin...

 

However, what is your purpose to find such information? The totalTransform contains BasisZ, that is also family.FacingOrientation and BasisX, that is also family.HandOrientation if you need this

0 Likes
Message 3 of 9

Anonymous
Not applicable

Hey thanks for your reply.

 

You were indeed correct; my math to calculate rotations from a Transform was incorrect, I revised the method and now it works.

0 Likes
Message 4 of 9

aignatovich
Advisor
Advisor

Show us the code for future references and search ))

0 Likes
Message 5 of 9

btmsoftware
Advocate
Advocate

Would be nice if you could share with us. I need to do the same.... Smiley Wink

0 Likes
Message 6 of 9

ennio
Explorer
Explorer

Hi! Sorry for reviving an old thread but I'm struggling with the same problem, can someone point me to some resource to solve this?

I'm trying to optimize an exporter and everytime I export a family element I get strange results.

 

Thank you in advance! 

0 Likes
Message 7 of 9

jeremytammik
Autodesk
Autodesk

I have two resources for you that show perfect nested transformation handling:

 

First, very basic, the ElementViewer included in the Revit SDK:

 

https://thebuildingcoder.typepad.com/blog/2008/09/geometry-viewer.html

 

Secondly, the custom exporter to XML by Arnost:

 

https://thebuildingcoder.typepad.com/blog/2013/07/graphics-pipeline-custom-exporter.html

 

I often resort to those when starting a new project from scratch that requires handling of nested transforms.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 8 of 9

ennio
Explorer
Explorer

Hi Jeremy thank you very much!

 

Unfortunately I've seen those resource.

Actually, the current published version of the software I'm working on is based on the JSON Exporter that is on the second link.

Unfortunately that method seams to not manage relative transforms for geometries and every element exported has vertex coords relative to (0,0,0) so while the export is almost perfect, there are a lot of repetitive information that are a problem with realtime engines (the target for the exporter).

 

I've already rewrote everything from the ground up as I finally had the chance to study the API but now I'm struggling to solve this last problem, I'm sure there's something that I'm not aware of that is causing random rotations..

 

 

0 Likes
Message 9 of 9

jeremytammik
Autodesk
Autodesk

That is good news.

 

If all the vertices are close to the origin, they represent the original family definition coordinates.

 

All you need to do is concatenate the list of instance transforms in the correct order and you will obtain perfect project coordinates.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes