Transform from instance Plane

Transform from instance Plane

george1985
Collaborator Collaborator
584 Views
5 Replies
Message 1 of 6

Transform from instance Plane

george1985
Collaborator
Collaborator

Hello,

In Revit API, how can I get Transform by knowing the final Plane of where the instance should be inserted?

Jeremy posted a solution which calculates Transform from normal of the final plane. But I would need to consider all three axes of the final plane, not only its normal.

Basically I created a DirectShapeType at 0,0,0 lying in the XY plane. And now I would like to instantiate it to some plane in 3D. I know this plane in 3D, but I do not know how to create Autodesk.Revit.DB.Transform for it:

george1985_0-1671294345433.png

 



george1985_1-1671294406442.png

 


Any help would be appreciated.


Accepted solutions (1)
585 Views
5 Replies
Replies (5)
Message 2 of 6

jeremy_tammik
Alumni
Alumni

You have two coordinate systems: the source coordinate system of the direct shape with origin point and X, Y, Z vectors  equal to (0,0,0), (1,0,0), (0,1,0), (0,0,1), respectively, and the target coordinate system. There are several ways to create the transform from one to the other. For instance, you can concatenate the three transformations to rotate appropriately around the Z axis, then tilt the Z axis to the required degree, and lastly translate from the origin to the destination point. Here are a number of other solutions:

   

     

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 6

mhannonQ65N2
Collaborator
Collaborator

First, you should create a translation using the plane's Origin. Then you can set your transform's BasisX, BasisY, and BasisZ to the plane's XVecYVec, and Normal respectively.

Message 4 of 6

george1985
Collaborator
Collaborator

Thank you @jeremy_tammik 

Thank you @mhannonQ65N2  as well. Should I then multiply those two transformations?

 

t1 = Transform.CreateTranslation(pln.Origin)


t2 = rdb.Transform.Identity  # instantiate transformation
t2.BasisX = XYZ(pln.XVec.X, pln.XVec.Y, pln.XVec.Z)  # assign Basis X vector
t2.BasisY = XYZ(pln.YVec.X, pln.YVec.Y, pln.YVec.Z)  # assign Basis Y vector
t2.BasisZ = XYZ(pln.Normal.X, pln.Normal.Y, pln.Normal.Z)  # assign Basis Z vector

t_final = t1.Multiply(t2)

 


Did I understand you correctly?

0 Likes
Message 5 of 6

mhannonQ65N2
Collaborator
Collaborator
Accepted solution

I think that should work but it would be a bit simpler to just modify the transform returned by CreateTranslation.

 

t1 = Transform.CreateTranslation(pln.Origin)

t1.BasisX = pln.XVec   # assign Basis X vector
t1.BasisY = pln.YVec   # assign Basis Y vector
t1.BasisZ = pln.Normal # assign Basis Z vector

 

Message 6 of 6

george1985
Collaborator
Collaborator

Works perfectly. Thank you for the help @mhannonQ65N2 !