Confusing result ElementTransformUtils API class

Hello,
One of you could test if you get the same result.
I can’t identify the cause

I am using Revit 2023.1
and under DynamoRevit 2.16.1.6510

I attached file + script
Fichier Test.rvt (2.4 MB)
test_to_see.dyn (23.0 KB)

Code Python
import clr
import sys
import math

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 
uidoc = uiapp.ActiveUIDocument

#######OK NOW YOU CAN CODE########
elt=UnwrapElement(IN[0])
ang=IN[1]
def r_cent_l(i,a):
    loc=i.Location.Point
    Line_axis=Line.CreateBound(loc,XYZ(loc.X,loc.Y,1))
    TransactionManager.Instance.EnsureInTransaction(doc)
    ElementTransformUtils.RotateElement(doc,i.Id,Line_axis,math.pi*a/180)
    TransactionManager.Instance.TransactionTaskDone()


z=[r_cent_l(e,ang) for e in elt]
OUT = z

I thank you in advance
Sincerely
christian.stan

What is the location point of the family in question?
Which way is ‘up’?
Note that wrapping a transaction in a definition may create some performance issues, though I haven’t tested myself.

1 Like

THANKS,
To answer you (5cm or 0.05m to the left)

this is the 1st element of the series which is placed in a disorderly manner
when it is part of a process.

if the elements are already in place I have no problem

Where is the drawing’s internal origin and X/Y axis? (Relative to the wall which is placing our of position)

Hoping not to go off topic in the answer

cordially
christian.stan

I have to add a transaction end before the Python node


to avoid this inconvenience (from the 1st object placed in a “strange” way)
but I get multiple routines launched in this case (weird)

I’m taking up a little too much of your time, thank you for trying to solve it.
cordially
christian.stan

Draw Dynamo point at the origin and display it in the Revit preview. My thought is that the family is rotating about the origin as this is kind of in one transaction…

Yes

1 Like

I tried to implement your idea
(I think I still have to work on the transactions side, I still have some gray areas)

THANKS
Have a good evening
Sincerely
christian.stan

Try this :slight_smile:

doc.Regenerate()
z=[r_cent_l(e,ang) for e in elt]
OUT = z

Had a similar problem not a long time ago.

2 Likes

Also works this way:

TransactionManager.Instance.ForceCloseTransaction()
z=[r_cent_l(e,ang) for e in elt]
OUT = z

I´m often having troubles with placing and rotating though, I sometimes have to place, rotate, translate back to make it work…

1 Like

Hi, This method no, but I will keep the doc.Regenerate()
THANKS

sincerely
christian.stan

Hey @christian.stan,

both methods work, because of this:

Note that when a transaction is committed there is an automatic call to regenerate the document.

So somehow the transaction from placing the families is still open and , as you also showed with nodes, you just have to close it.

1 Like

I did some trials - the first placed instance of the family appears to have the Location set to 0, 0, 0 while inside the transaction when using the dynamo Family Instance node or with doc.Create.NewFamilyInstance() in python

If you use the Dynamo points as the location for the rotation axis it works ¯\_(ツ)_/¯

And discovered the Element.Location.Rotate(axis, radians) method exists

1 Like