Hosting of elements

Hosting of elements

vesna_DIBS42
Participant Participant
718 Views
11 Replies
Message 1 of 12

Hosting of elements

vesna_DIBS42
Participant
Participant

Hello Autodesk community, I have a problem in my model that I will try to explain fully and I hope someone can help me. 

 

Software I'm using is Revit 2023 and families I'm working with are electrical. Families and they hosting work well in general, like when I'm placing them by hand:

 

vesna_DIBS42_1-1741970376614.png

 

 

Since I needed to add a lot of instances in this model according to some rule, I used dynamo script for that. That script worked in a way that it added elements from 00 floor up, like this:

 

vesna_DIBS42_2-1741970543369.png

So they are on the right spot... but all are assigned to 00 level.

 

When I added everything I needed, so a lot of elements of different electrical categories, I started checking them and assigning good level to them which normally works. 

But for some reason a lot of families didn't allow me to do that, they didn't even have Level parameter, like you can see on previous photo. 

 

Strangest thing is that some families worked, some not, like electrical fixtures, lighting fixtures, lighting devices, communication devices and fire alarm devices. Some families of those categories worked, but a lot didn't. 

 

I tried everything. Copying them, cutting them, changing work-plane based parameter, trying to change host...but nothing worked. They always stay the same, with this same problem, unless I add them from view again manually which is now not good solution having in mind how many elements I have.

 

What can be in these families that makes this weird problem, in families that always work good in other cases?

 

Any help would mean a lot!

 

 

0 Likes
719 Views
11 Replies
Replies (11)
Message 2 of 12

hmunsell
Mentor
Mentor

I'm not as familiar with Dynamo as I should be, but...

 


@vesna_DIBS42 wrote:

I tried everything: copying them, cutting them, changing work-plane-based parameters, and trying to change the host, but nothing worked.


if you copy, cut, etc... to the other level manually, do the levels change correctly? 

 

Howard Munsell
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.



EESignature


Message 3 of 12

vesna_DIBS42
Participant
Participant

No. It stays the same. Elevation from Level changes of course, but the Level not, still there is no 'Level' parameter in them and Elevation from Level is calculated from 00 level.

0 Likes
Message 4 of 12

hmunsell
Mentor
Mentor

I just played with it a little and don't have that issue in 2023 (or 2025). When I copy to the clipboard and then Past Aligned to the current view (on a different floor), It does keep the original level association.  When I select the device and change the Schedule Level, it reassociates. I can't get to do what you show, where the Schedule Level is not displayed at all. I know you're trying to do this with Dynamo, but when we figure out why it's doing it manually, you can hopefully fix the Dynamo script 😁

 

Would you be able to upload a small example? 

Howard Munsell
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.



EESignature


Message 5 of 12

L.Maas
Mentor
Mentor

Consider uploading the dynamo script and the relevant families. It might that modifying the Dynamo script the problem can be solved. The families are relevant to see what kind of category they are and how they should be hosted.

Louis

EESignature

Please mention Revit version, especially when uploading Revit files.

Message 6 of 12

koenJKUD8
Contributor
Contributor

If you are familiar with Pyrevit I can provide you with a script that may help you further.

Message 7 of 12

vesna_DIBS42
Participant
Participant

I placed Dynamo script and family.

0 Likes
Message 8 of 12

vesna_DIBS42
Participant
Participant

I placed Dynamo script and family. Let me know you thoughts.

0 Likes
Message 9 of 12

vesna_DIBS42
Participant
Participant

Yeah, sure. Can you send me the script?

0 Likes
Message 10 of 12

robert2JCCH
Advisor
Advisor

https://forum.dynamobim.com/t/creating-familyinstance-problem-with-setting-level-parameter/41397/10
This thread suggests that it could be a possible issue via the node, however the thread is fairly old and my attempts at a basic FamilyInstance.ByPointAndLevel in Revit2023.1/Dynamo 2.16.2 do not replicate this issue, so it seems like the API access method was corrected since then. This makes me doubt it's a Dynamo issue, since you're unlikely to have used a library node that predates this version far back enough for it to be relevant.

 

 

 

Are you doing any kind of Level manipulation in the project file? Are Levels created/destroyed? Copy/Monitored from a link?

 

On the family side, what version of Revit are the original family files? Do you have to go through an upgrade process when you load them into the project? I sort of recall that non-hosted families had a period of time in which they did not necessarily have a displayed Level, and one of the Revit versions standardized the Properties pane to show unhosted families as being hosted to a Level. Is it possible that your affected families go back to 2008/2011 era when manufacturers first started providing a significant amount of family files?

0 Likes
Message 11 of 12

koenJKUD8
Contributor
Contributor
# -*- coding: utf-8 -*-
import clr
clr.AddReference("RevitServices")
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")

from RevitServices.Persistence import DocumentManager
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, Transaction, Level, BuiltInParameter, ElementId
from System.Windows.Forms import Form, Label, Button, ListBox, MessageBox, MessageBoxButtons, MessageBoxIcon, SelectionMode
from System.Drawing import Point, Size
import System
import sys

doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument

if doc is None:
    raise Exception("Er is geen actief Revit-document geopend.")

# Laat de gebruiker elementen selecteren in de tekening
selected_ids = uidoc.Selection.GetElementIds()
if not selected_ids:
    MessageBox.Show("Geen elementen geselecteerd. Selecteer elementen en probeer opnieuw.", "Fout", MessageBoxButtons.OK, MessageBoxIcon.Error)
    sys.exit()

# Verzamel de geselecteerde elementen
elements = [doc.GetElement(id) for id in selected_ids]

def find_level_and_elevation(elem😞
    """Zoekt de Level en Elevation from Level parameters en controleert Reference Level voor MEP-elementen."""
    possible_params = ["Level", "Base Level", "Reference Level", "Host Level", "Associated Level", "Work Plane"]
    level_param = None
    elevation_param = elem.LookupParameter("Elevation from Level")

    for name in possible_params:
        param = elem.LookupParameter(name)
        if param and not param.IsReadOnly:
            level_param = param
            break

    if not level_param:
        level_param = elem.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM)

    level = doc.GetElement(level_param.AsElementId()) if level_param else None
    elevation = elevation_param.AsDouble() if elevation_param else None
   
    return level, level_param, elevation, elevation_param

# Zoek naar wijzigbare niveau- en hoogteparameters
elements_with_levels = []
for elem in elements:
    level, level_param, elevation, elevation_param = find_level_and_elevation(elem)
    if level_param and not level_param.IsReadOnly:
        elements_with_levels.append((elem, level, level_param, elevation, elevation_param))

if not elements_with_levels:
    MessageBox.Show("Geen van de geselecteerde elementen heeft een wijzigbare Level- of Reference Level-parameter.", "Fout", MessageBoxButtons.OK, MessageBoxIcon.Error)
    sys.exit()

# Verzamel alle beschikbare levels
levels = FilteredElementCollector(doc).OfClass(Level).ToElements()
levels_sorted = sorted(levels, key=lambda l: l.Name)
level_names = [l.Name for l in levels_sorted]
level_names_net = System.Array[System.Object](level_names)

class SelectionForm(Form😞
    def __init__(self😞
        self.Text = "Selecteer een nieuw referentieniveau"
        self.Size = Size(400, 300)
        self.MinimumSize = Size(300, 250)
        self.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen

        self.label_levels = Label()
        self.label_levels.Text = "Selecteer een nieuw referentieniveau:"
        self.label_levels.Location = Point(10, 10)
        self.label_levels.Width = 350
        self.Controls.Add(self.label_levels)

        self.listbox_levels = ListBox()
        self.listbox_levels.Location = Point(10, 40)
        self.listbox_levels.Width = 350
        self.listbox_levels.Height = 150
        self.listbox_levels.SelectionMode = SelectionMode.One
        self.listbox_levels.Items.AddRange(level_names_net)
        self.Controls.Add(self.listbox_levels)

        self.ok_button = Button()
        self.ok_button.Text = "OK"
        self.ok_button.Location = Point(self.ClientSize.Width // 2 - 40, self.ClientSize.Height - 50)
        self.ok_button.Click += self.ok_click
        self.Controls.Add(self.ok_button)

        self.selected_level = None
        self.Resize += self.on_resize

    def on_resize(self, sender, event😞
        self.listbox_levels.Size = Size(self.ClientSize.Width - 20, self.ClientSize.Height - 100)
        self.ok_button.Location = Point(self.ClientSize.Width // 2 - 40, self.ClientSize.Height - 50)

    def ok_click(self, sender, event😞
        if self.listbox_levels.SelectedIndex != -1:
            self.selected_level = levels_sorted[self.listbox_levels.SelectedIndex]
            self.DialogResult = System.Windows.Forms.DialogResult.OK
            self.Close()
        else:
            MessageBox.Show("Selecteer een referentieniveau.", "Fout", MessageBoxButtons.OK, MessageBoxIcon.Error)

form = SelectionForm()
form.ShowDialog()

if form.selected_level is None:
    sys.exit()

# Start een transactie om de niveau- en elevatieparameter aan te passen
t = Transaction(doc, "Wijzig referentieniveau en Elevation from Level van geselecteerde elementen")
t.Start()

try:
    for elem, old_level, level_param, elevation, elevation_param in elements_with_levels:
        old_level_elevation = old_level.Elevation if old_level else 0
        new_level_elevation = form.selected_level.Elevation

        # Bereken het nieuwe elevation-from-level
        new_elevation_value = (elevation or 0) + (old_level_elevation - new_level_elevation)

        # Stel het nieuwe niveau in
        if level_param:
            level_param.Set(form.selected_level.Id)
       
        # Stel de nieuwe elevatie in
        if elevation_param and not elevation_param.IsReadOnly:
            elevation_param.Set(new_elevation_value)

    t.Commit()
    MessageBox.Show("Niveau en hoogte succesvol gewijzigd.", "Succes", MessageBoxButtons.OK, MessageBoxIcon.Information)
except Exception as e:
    t.RollBack()
    MessageBox.Show("Fout bij het wijzigen van het niveau: {}".format(e), "Fout", MessageBoxButtons.OK, MessageBoxIcon.Error)
0 Likes
Message 12 of 12

L.Maas
Mentor
Mentor

I would change the script to something like this (no fixed level 0 like in your script).

LMaas_0-1742325806811.png

 

Basically what I am doing is:

-Get the levels from the elements in the linked files.

-Find the same levels names in the project file (Thus levels in linked files should have same name in linked file and project file)

-Get the Elevation of the levels

-The location from the elements is based from 0. Therefore we need to subtract the height of level.

-Place the family instance on the right location at the height in relation to the level

 

Result like this.

LMaas_1-1742326109798.png

 

If the names of the levels in the project and the linked file are not the same you would need to modify the script in such a way that you can relate the level in the linked file to the corresponding level in the project.

 

Louis

EESignature

Please mention Revit version, especially when uploading Revit files.

0 Likes