Elements moved to wrong location

Hi, I need help using the ElementTransformUtils.MoveElement method. For some reason the XYZ coordinates doubled once they go through that one line of code? Does anyone know why?

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument 
text = UnwrapElement(IN[0])

TransactionManager.Instance.EnsureInTransaction(doc)

newheight = []
newtext = []
ids = []
for t in text:
	newheight.append(t.Height)
	newtext.append(t.Coord)
	ids.append(t.Id)
	itemlist = List[ElementId](ids)

c = newtext[0].Y
p = []
for r in range(0,len(newheight)):
	if newheight [r-1] < 0.015:
		c -= 0.020
	if newheight [r-1] > 0.015:
		c -= 0.030
	p.append(c)
	
xyz = []
for h in p:
	xyz.append(XYZ(newtext[0].X, h, newtext[0].Z))

u = []
for d,s in zip(itemlist,xyz):
	u.append(s)
	ElementTransformUtils.MoveElement(doc, d, s)

out = []
for o in text:
	out.append(o.Coord)

TransactionManager.Instance.TransactionTaskDone()

OUT = xyz, out

image

What is your input unit? Revit API works in feet, so the XYZ in ElementTransformUtils must be in feet.

My input unit is millimetre but does that matter? The coordinates (labelled as ‘xyz’) being fed into the MoveElement line are in XYZ which is what is expected.

My bad, jumped the gun too early haha.

ElementTransformUtils returns void, also it shouldn’t change anything from your input besides the elements to move. I have run a quick test and it works well:

If it is not confidential, can you strip the Revit file and upload it with the script you are working on?

1 Like

Attached is the Revit file and dynamo script. The testing view is on sheet S00.001.

Essentially I wanted to move a bunch of text in the same position down in Y-direction accordingly.

Project1.rvt (2.3 MB)
GEN NOTES TEST.dyn (5.2 KB)

Ok, nothing to do with units, sorry you added that bunch of converters thanks to my comment :cold_sweat:

The problem with the coordinates doubling is because you are using the modified text position in the end. Let me explain it:

  1. First you retrieve the current coordinates of the texts and store them in newtext
  2. You move the text
  3. Now you retrieve the coordinates of the moved texts (which keep the same Ids even you may think they are different elements), stored in out, and compare them to newtext

See the problem? Those two lists have to be different as you compared texts in different positions

Important to show the context of the script, we may have deducted the problem if we have seen the Select Model Elements node:

1 Like

Hello

According to the API doc ElementTransformUtils.MoveElement takes as argument a translation vector and not a position.

To set directly the location, it must be possible to do it from the Coord property (setter)

1 Like

@architectcoding @c.poupin

Ahh yes I have found the problem. I provided the coordinates of where I want them to be rather than how much I want them to move/translate by. The script is now working as it should - thank you for your help!

1 Like