Moving element with Python

Hi everyone,

In the code below, I am trying to move an element by a user defined amount. It is moving the item but it seems to be doubling the distance. instead of moving the element 550mm it is moving it 1100mm, can anyone tell me why?? I cant see the reason here…

element = UnwrapElement(IN[0])

output =

plinthHeight = IN[1]

HeightValueConvert = UnitUtils.Convert(plinthHeight, DisplayUnitType.DUT_MILLIMETERS, DisplayUnitType.DUT_DECIMAL_FEET)

Z = XYZ(0,0,HeightValueConvert)

TransactionManager.Instance.EnsureInTransaction(doc)

newLocation = ElementTransformUtils.MoveElement(doc, element.Id, Z)
output.append(newLocation)

TransactionManager.Instance.TransactionTaskDone()

OUT = output

Hey,

It isn’t obvious, I think your code is ok… Can we see the graph?

Cheers,

Mark

Hi Mark,

Sure, here is the graph.
Section Steel tank.dyn (146.7 KB)

I haven’t uploaded the family file, but the point of the script is to place plinths underneath a tank, and have the tank move up by the same value as the height of the plinths.
Thank you!

Some face based families can not be moved. Can you check if you can edit the elevation?

Hi Deniz,

You are right, it is a face based element and I do not have the parameter to adjust it’s offset by default.
However, the element is moving when the script executes… Just not by the correct amount?

I can also move the element freely by using the “move” command in Revit, isn’t this move command through the API essentially doing the same thing?

Maybe is your conversion is not right. Can you please as output
OUT= output, HeightValueConvert

and share the result?

Here is the result.


I converted to Decimal Feet because it seems like the XYZ class takes feet as it’s inputs?

The value of 1.8044 equates to 550mm which is correct, but it is still doubling the distance.

Have you gone to the view and moved it manually to see what it does? I am assuming it’s at the level to begin with and not already elevated from the Offset From Level parameter?

Hi Sean,

This item does not have any way of inputting an elevation. So there is no “Offset” or “Offset from Level” or “Reference Level” or anything like that. It is a generic model which has been constructed using a repeater.
It is sitting level with L0 at the moment yes, no pre-existing offset. I can manually move it up and down no problem using the move command. This is why I am using the MoveElement method from the API, I thought it would accomplish the same task as the move command.

1 Like

Thanks @Sigma, does it always exactly double the number? It would be helpful to share the family if you could so we could test as well.

Hi Sean,

Yes, It always exactly doubles the number.
Thanks a lot, here is a stripped down version of the family.Tank.rfa (876 KB)

When you enter 225 mm, does it place correctly?

Hi Deniz,

No, when I enter 225mm it doubles it again.

It appears to be working fine for me. What is the Plinth made from? Is it a floor, or another family? Just wondering if something is moving the reference to the plinth and therefore doubling the offset.

1 Like

Hi Sean,

Thanks for testing this, then I really don’t understand why this isn’t working for me.

The plinth is a “Mechanical Equipment” family, for internal reasons. That wouldn’t make a difference would it??

Only other thing may be something else in your graph. Can you try just a stripped down version like what I used and see if it still does it?

1 Like

I’m guessing its caused by your python node being called twice by Dynamo’s VM, so your element gets translated twice. Its most likely your plinthHeight; it updates after the element is translated and expires your graph so Dynamo’s VM re-executes your graph again. I would expect it to get into a never-ending loop if this is the case? …so maybe Dynamo’s VM has something which handles possible recursive results which terminates subsequent re-evaluation. One way to check is hard code your value temporarily and even get the element temporarily using its hard coded ID in your python script so you are completely divorced from Dynamos VM until you get to a point where its working consistently, then re-insert your inputs to isolate the cause of the problem.

3 Likes

@SeanP it does work when I hard code it, which is how I had it originally, then it needed to be user defined so I started to accept an input which is when things started going a bit south. Thank you for this suggestion though, that really helped.

@Thomas_Mahon, I did not even think of this… Thank you, I will make some adjustments and come back with (Hopefully) a working result.
Thank you for all the suggestions!

Transaction.End and Transaction.Start nodes may be something to look at if you modifying the plinth in the same run. Extract the height after the Transaction.End to use for the Offset to avoid the doubling up.

1 Like