C# Zero Touch: List of Elements All Have the Same Unique ID

The Zero Touch node that I’m developing has an interesting problem that I can’t find a solution for…
Basically I’m creating a list of furniture elements. It seems to be working, except every element I create has the exact same unique ID. Unfortunately there’s no method I’ve found of changing that ID either. Here is the code:

public static List<Element> CreateElementsList (List<Point> Pts, List<string> Fam, List<string> Type)
{
    List<Element> E = new List<Element>();
    for (int i = 0; i < Pts.Count; i++)
    {
        double X = Pts[i].X;
        double Y = Pts[i].Y;
        double Z = Pts[i].Z;
        FamilyType type = FamilyType.ByFamilyNameAndTypeName(Fam[i], Type[i]);
        FamilyInstance inst = FamilyInstance.ByCoordinates(type, X, Y, Z);
        E.Add(inst);
    }
    return E;
}

Hopefully there’s somebody here who can offer a solution. Thanks!

I have also tried not using the Element class at all, and returning a list of FamilyInstances instead. Same result.

Have you tried using the RevitAPI classes instead of RevitNode classes? The problem with using classes and method calls from the RevitNode library in C# is element binding; ultimately, you need to control it to perform actions such as the one you are attempting and currently there is no way to override or control it. @Michael_Kirschner explains this concisely here. I would stick with classes and calls from the RevitAPI in C#… or switch to Python.

1 Like

Hi Thomas, thanks for the reply, but this opened up an insane can of worms.
I’m pretty shocked that there’s no method to call a family type by its name. That’s a real problem for me since I’m using a data table with strings for the family name and type. Am I wrong or is there really nothing that will behave similarly to the Revit Node FamilyType.ByFamilyNameAndTypeName?
The closest I’ve found is the LoadFamilySymbol method, but for thousands of data entries I can’t very well search and load families every single iteration. Any pointers would be much appreciated.

There is, look at the ItemFactoryBase class in the RevitAPI. There are numerous methods for placing Family instances (which should answer your other question too):

Ok, so thank you for replying again. I looked at the class, and I’m quite certain that doesn’t answer my question, and I don’t think I’m being thick.

So let me rephrase… I want to execute a code that will run in the following steps:

  1. Retrieve data from a csv table (string:family and string:type).
  2. Use that data to return a FamilySymbol (this is where I’m stuck).
  3. Create an instance of the family (pretty certain I can do this - if I get the family symbol).

The reason I can’t use the FilteredElementCollector method detailed here is that I will need to access one of a handful of different types within the family for each instance. Same reason why I can’t use the batch creation method detailed here.

For example:
Instance     Family    Type
inst1            Table       Small
inst2            Table       Medium
inst3            Table       Large

FYI the family is already loaded into the document. Really hoping this task is possible. Can’t see why it wouldn’t be…

One method you can explore is the FilteredElementCollector with filter rules. Also, another great (and probably underused) resource is the DynamoRevit git. Dynamo is open-source, so a good start point is to check how the Dynamo node has actually be written. Here’s a snippet from FamilyType.ByFamilyAndName. You could adapt this code to achieve what you need.

Yesterday I ended up going with the FilteredElementCollector because I wanted it to work, and figured I would just take the performance hit. Turns out that’s the same method used in the source.
Still, excellent suggestion to just use the source code, that’s not something I had thought of checking.