Family instance creation with the ByPoint method assign same IntegerValue

Hello,
I have a weird situation sorry if this is not the place:

in the below code, it is creating a new family instance which is in a loop actually, the problem everytime the code creates a new instance it assigns the same integervalue to familyinstance, because of that the new instance replaces the previous instance in the model, so that the last instance created in the loop stays in the model. Revit API 2023

@solamour

 Utils.Log(string.Format("Creating new Family Instance...", ""));

 Autodesk.DesignScript.Geometry.Point point = Autodesk.DesignScript.Geometry.Point.Origin();

 fi = Revit.Elements.FamilyInstance.ByPoint(fs, point);

 Utils.Log(string.Format("Family Instance Created: {0}", fi.InternalElement.Id.IntegerValue));

the loop is something below:

Mass.ByShapesCreaseStations, that method creates inside family instances. I am using actaully CivilConnection packages codes.

foreach (BaselineRegion blr in baselineregions)
{
if(lbSelectedRegions.SelectedItem.ToString() == blr.Subassemblies[0].Name)
{
var shapes = blr.Shapes;

    shapesFinal = shapes.SelectMany(listOfLists => listOfLists.SelectMany(innerList => innerList)).ToList();

    stations = blr.Stations;

    subAssemblyNames = shapesFinal.GroupBy(s => s.Name).Select(g => g.First()).ToArray();

    for (int i = 0; i < subAssemblyNames.Length; i++)
    {
        sa.Clear();
        foreach (var shape in shapesFinal)
        {
            if (shape.Name == subAssemblyNames[i].Name)
            {
                sa.Add(shape);
            }
        }

        Mass.ByShapesCreaseStations(familyTemplate, subAssemblyNames[i].Name, sa.ToArray(), dm.CurrentUIApplication.Application, stations);
    }

    break;
}

}

Hi Yunis, welcome to the forum

This is the Dynamo forum, are you using C# with Dynamo?

That’s great if you are, please read How to get help on the Dynamo forums

Is it possible to add some more context about what you are trying to achieve with Dynamo or CivilConnection?

The most likely place to resolve C# issues with Revit is going to be here Revit API Forum on the Autodesk site where you get access to Jeremy Tammik who has an immense knowledge of the Revit API

Dear Mike

Thank you for the answer, actually i can ask the same question through the dynamo also because it is behaving the same.

As you see in the image i am trying to add a sample family to the model to the 0 coordinates, and without changing anything but changing only coordinates if i add another table to the model it deletes the first one because the new element does not get a new ID, what i mean both elements the script is trying to add gets the same ID and then it replaces the previous element. I have tried this script both in Revit 2022 and 2023, behaves the same, i am not sure if i am missing something while adding the family instance.

This is called Element Binding and is intentional. The idea is that while developing a script in the graph editor, you will constantly be updating and modifying your graph to function in the way that you like. While doing this, it would be pretty annoying if Dynamo created a brand new instance every time you updated your file. Typically once a graph is complete and being used for production, it’s run through Dynamo Player which does not use Element Binding (it’s just a whole new instance actually). There are also ways to avoid Element Binding with Python, which you can find here on the forums. All of this is better explained in the linked post by Jacob Small.

3 Likes