Programmable animation in Revit

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone :3
I'm searching way to animate family instance in 3d view by movement and rotation using revit api.
Movement and rotation along the z-axis work well, but the rotation along the x and y axes, as you probably have already guessed, does not work.
I tried to use ElementTransformUtils.RotateElement (doc, element.Id, axisX, angle); but got "Unable to rotate an item in this position".
In pop-up window of the rotation tool I read that in 3D view the axis of rotation is perpendicular to the work plane of the view. So if rotation happens relative to the work plane, it must be possible to change the work plane and using rotation relative to the new plane.
So I went to family properties and checked "Work plane based" and unchecked "Always vertical". After that, I changed the work plane, but the error appeared again.
Then I tried to change the orientation options, but it was not possible.
Soooo, is there some way to create reference plane and attach it to object, using revit api, and then rotate it in 3D view? (I guess during every iteration I will be creating 2 reference plane for X and Y axes)
Or should I create a new instance of an object every time, using transformation for a new location and orientation? (If it's my solution, please tell me how I can manipulate this process)
Revit 2017
Code:
using (TransactionGroup TransactionOfMovement = new TransactionGroup(doc))
{
using (Transaction movingTransaction = new Transaction(doc))
{
try { TransactionOfMovement.Start("Object movement"); int index = 0; foreach (XYZ newPosition in dotsForMoving) { movingTransaction.Start("New move for model"); ElementTransformUtils.MoveElement(doc, element.Id, newPosition); movingTransaction.Commit(); if (movingTransaction.GetStatus() != TransactionStatus.Committed) { TaskDialog.Show("Transaction Error", "Movement transaction isn't committed"); } startPoint += newPosition; Line axisX = Line.CreateBound(start, start + XYZ.BasisX); Line axisY = Line.CreateBound(start, start + XYZ.BasisY); Line axisZ = Line.CreateBound(start, start + XYZ.BasisZ); movingTransaction.Start("New rotate for model"); // Rotation error by X and Y axises ElementTransformUtils.RotateElement(doc, element.Id, axisX, dotsForRotating[index].X); ElementTransformUtils.RotateElement(doc, element.Id, axisY, dotsForRotating[index].Y); // Works fine ElementTransformUtils.RotateElement(doc, element.Id, axisZ, dotsForRotating[index].Z); // Also rotation error //element.Location.Rotate(axisX, dotsForRotating[index].X); movingTransaction.Commit(); uidoc.RefreshActiveView(); if (movingTransaction.GetStatus() != TransactionStatus.Committed) { TaskDialog.Show("Transaction Error", "Rotation transaction isn't committed"); } System.Threading.Thread.Sleep(50); index++; } TransactionOfMovement.Assimilate(); } catch (Exception ex) { TaskDialog.Show("Transaction Error", ex.Message); return Result.Failed; } return Result.Succeeded;
}}