How to find parameter 'Top Level'?

I have 3 piles (two-level based) in my model and i have a Levels placed at the bottom at each Structural Foundation. (no duplicates)
I want to find the correct Level and change parameter Top Level of each pile (= equal to bottom Structural Foundation), with Top Offset=0
I’m trying for days to get this working but I can’t.

I’m talking about the first item in the list. It can’t find the correct Level(elementId). Top Level must be changed from Level “ok=-1000”, Top Offset=200 to Top Level “ok=-800”, Top Offset=0

Can anybody help me out?



Here is my Dynamo-script & Revit-model (R22).
test-plaats-palen-onder-poer_script.dyn (24.5 KB)
test palenplan R22 - kopie.rvt (1,5 MB)

Hello @mrl,

You just have to set the paramter value by name, what exactly is the problem? Do you want to do it with python or nodes?

Please post the python code.

Sorry…

My problem is that my script does work 100%.
beneath are my screenshots to explain what I have/got/want.
All the neccesary files (python code included) are in the first post to test it for yourself.



Can you help me?
It doesn’t matter if the solution is with Nodes or in Python. :slight_smile:

Thank you. But you’ve given the answer (= correct Level) to set parameter Top Level.
I can do that also with python, but the trick is how to find this correct Level belonging to Top Level with Top Offset=0
The problem is not how to set parameter. My problem is how to find the correct Level.

Important: Elevation Top Level pile (Structural Foundation) must be equal with Elevation at Bottom beam (Structural Framing) = Level

Sorry I also didn´t understand correct what you wanted to do. You don`t want to find the parameter “Top Level” like you wrote in the title?!

You just want to find the right level, why not find the level by the desired elevation :slight_smile:

Yes, that is what I want. :+1:
I thought everything was clear with the screenshots and red rectangles, but it was clearly not enough.
My Python-script should be the same as your script, but mine doesn’t work 100%.

Edit: screenshot added

Hello @mrl

If you want to get help, please post your code in the future. It is good to add a .dyn file but the code should be available in your post, a screenshot of the code is not so good.

Your code is really hard to read, there is so much unnecessary stuff in there, please clean it up a little next time.

You can set your levels like this:

elements = IN[0]
levels = IN[1]
outlist = []

TransactionManager.Instance.EnsureInTransaction(doc)

for element in elements:
    parameter_value = element.GetParameterValueByName('Elevation at Top')
    for level in levels:
        if abs(parameter_value - level.Elevation) < 0.1:
            element.SetParameterByName('Top Level', level)
            element.SetParameterByName('Top Offset', 0)
            outlist.append(element)

TransactionManager.Instance.TransactionTaskDone()

OUT = outlist

Sorry for that. The python-code (with unneccecary stuff) was available inside the Dynamo-script (see First Post). The next time I will add it seperate from the script.

I will test/look at your python-code.

1 Like

Better to add a line to only set the level if it is not correct already:

elements = IN[0]
levels = IN[1]
outlist = []

TransactionManager.Instance.EnsureInTransaction(doc)

for element in elements:
    parameter_value = element.GetParameterValueByName('Elevation at Top')
    for level in levels:
        if abs(parameter_value - level.Elevation) < 0.1: # do something only if a level is found
            if element.GetParameterValueByName('Top Level') != level: # do something only if level is not set already
                element.SetParameterByName('Top Level', level)
                element.SetParameterByName('Top Offset', 0)
                outlist.append(element)

TransactionManager.Instance.TransactionTaskDone()

OUT = outlist

It worked !

Thank you very much !!! :+1: