# Strange movements of elements during performing Elements.Rotate (modified)

**URL:** <https://forum.dynamobim.com/t/strange-movements-of-elements-during-performing-elements-rotate-modified/14687>\
**Category:** Revit\
**Tags:** revit, python, dynamo\
**Created:** [September 9, 2017, 2:04pm UTC](https://forum.dynamobim.com/t/strange-movements-of-elements-during-performing-elements-rotate-modified/14687 "2017-09-09T14:04:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wrobel.joachim](https://avatars.discourse-cdn.com/v4/letter/w/6de8d8/32.png) [@wrobel.joachim](https://forum.dynamobim.com/u/wrobel.joachim)\
**Post date:** [September 9, 2017, 2:04pm UTC](https://forum.dynamobim.com/t/strange-movements-of-elements-during-performing-elements-rotate-modified/14687/1 "2017-09-09T14:04:48Z")

</div>

Welcome everyone for the first time! 🙂

I am struggling some weird movements of elements during performing modified custom node Elements.Rotate.

So, here is the general idea of Dynamo script:

1)Create pipework divided by 6m pipelength along tunnel 3D curve (works fine).  
2)Insert grooved couplings between pipes and rotate them horizontaly to match pipework layout (works fine).  
**3)Rotate mentioned above couplings verticaly (arround their local X-axis) (does not work).**

I tried many nodes to achieve that, (FamilyInstance.SetRotation, Elements.Rotate, Elements.RotateByAxisByAngle etc…) - I failed every time.

So I decided to modify Elements.Rotate to adjust that node to my need which is: rotate LIST of elements by LIST of angles by LIST of axis created by LIST of start and end points, but I am not sure if I did sth wrong. Script performs rotation of family instances but, simultaneously moves them to strange places in space. I am dealing with it for now by bringing them back on place after performed rotation, but I am aware that this is not a solution.. FYI: I don’t know Python at all.

See screenshot belows:

 ![Dynamo](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/b/1bc6f420855ccc955face67aa67132a52db40158.png)

**Modified Script:**

> import clr
> # Import RevitAPI
> 
> clr.AddReference(“RevitAPI”)  
> import Autodesk  
> #from Autodesk.Revit.DB import ReferencePointArray  
> from Autodesk.Revit.DB import ElementTransformUtils  
> from Autodesk.Revit.DB import Line  
> from Autodesk.Revit.DB import Transaction  
> from Autodesk.Revit.DB import ElementId  
> from Autodesk.Revit.DB import XYZ  
> #from Autodesk.Revit import \*
> 
> # Import DocumentManager and TransactionManager
> 
> clr.AddReference(“RevitServices”)  
> import RevitServices  
> from RevitServices import \*  
> from RevitServices.Persistence import DocumentManager  
> from RevitServices.Transactions import TransactionManager
> 
> # Import ToDSType(bool) extension method
> 
> clr.AddReference(“RevitNodes”)  
> import Revit  
> clr.ImportExtensions(Revit.Elements)
> 
> angle = IN[1]  
> axisX1 = IN[2]  
> axisY1 = IN[3]  
> axisZ1 = IN[4]  
> axisX2 = IN[5]  
> axisY2 = IN[6]  
> axisZ2 = IN[7]
> 
> changelist =
> 
> # Unwrap
> 
> elem = UnwrapElement( IN[0] )
> 
> for item in IN[0]:  
> nr = IN[0].index(item)
> 
> # Start Transaction
> 
> ```
> doc = DocumentManager.Instance.CurrentDBDocument
> TransactionManager.Instance.EnsureInTransaction(doc)
> 
> ```
> 
> # Make changes in model
> 
> #axis = NewLineBound(point (0, 0, 0), point (0, 0, 1))
> 
> ```
> #for elem_, angle_, axisX_, axisY_, axisZ_ in zip(elem, angle, axisX, axisY, axisZ):
> axisX1_ = axisX1[nr]
> axisY1_ = axisY1[nr]
> axisZ1_ = axisZ1[nr]
> axisX2_ = axisX2[nr]
> axisY2_ = axisY2[nr]
> axisZ2_ = axisZ2[nr]
> elem_ = elem[nr]
> angle_ = angle[nr]
> 
> axis = Line.CreateBound( XYZ(axisX1_, axisY1_, axisZ1_), XYZ(axisX2_, axisY2_, axisZ2_))
> changelist.append(ElementTransformUtils.RotateElement(doc, elem_.Id, axis, angle_))
> 
> ```
> 
> # End Transaction
> 
> ```
> TransactionManager.Instance.TransactionTaskDone()
> 
> ```
> 
> # exit
> 
> OUT = IN[0]

Any ideas? 🙂

Joachim.

---

<div class="post-metadata">

**Author:** ![Yna\_Db](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/yna_db/32/30641_2.png) [@Yna\_Db](https://forum.dynamobim.com/u/Yna_Db)\
**Post date:** [September 9, 2017, 2:55pm UTC](https://forum.dynamobim.com/t/strange-movements-of-elements-during-performing-elements-rotate-modified/14687/2 "2017-09-09T14:55:37Z")

</div>

I don’t have much time to dig into python at this moment (the package called _Basic\_Python\_Template_ could help), but we have struggled many times with family instances rotation on the forum. I ended up using _FamilyInstance.ByFace_ and it could worth a try. See here:

> [@Automatic road creation: How to generate solid between section profiles?](https://forum.dynamobim.com/t/automatic-road-creation-how-to-generate-solid-between-section-profiles/8779/40):
>
> I built up a solution to solve instances orientation problem based on what I previously did here: Thanks for giving me a serious opportunity to develop this idea. To sum up, the idea is to place family instances with the node FamilyInstance.ByFace because it gives more predictable results. To do so, I place tiny circles that creates the needed faces on the selected normals of the curve. I used a profile drawn on the XY plane of the mass family but it could be re-oriented with the Vector.Rotate …

---

<div class="post-metadata">

**Author:** ![wrobel.joachim](https://avatars.discourse-cdn.com/v4/letter/w/6de8d8/32.png) [@wrobel.joachim](https://forum.dynamobim.com/u/wrobel.joachim)\
**Post date:** [September 9, 2017, 10:59pm UTC](https://forum.dynamobim.com/t/strange-movements-of-elements-during-performing-elements-rotate-modified/14687/3 "2017-09-09T22:59:08Z")

</div>

Hi Yna\_Db!

I tried what you suggested, but it appears that Dynamo struggles with reading faces of auxiliary elements (see screenshot below). Did you ever get such error dialog box?

![DYNAMO2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/9/29a52dacc06d3bdb552275b3745553dcb46009d0.png)

Regards, Joachim

---

<div class="post-metadata">

**Author:** ![Yna\_Db](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/yna_db/32/30641_2.png) [@Yna\_Db](https://forum.dynamobim.com/u/Yna_Db)\
**Post date:** [September 9, 2017, 11:26pm UTC](https://forum.dynamobim.com/t/strange-movements-of-elements-during-performing-elements-rotate-modified/14687/4 "2017-09-09T23:26:13Z")

</div>

It didn’t happen at that time but I can see that increasing the diameter of the circles to 16 minimum is now necessary, don’t ask me why today… 🙂
