NewUnionFitting Allway return null In Dynamo Revit

I think Dynamo team need to be fix this, why it alway return null ?. Any have trick to quick by pass this return newUnionFitting ?

Example :

 /// <summary>
    /// create a union fitting from two pipe
    /// </summary>
    /// <param name="firstPipe">first pipe</param>
    /// <param name="secondPipe">second pipe</param>
    /// <returns name="family instance">union fitting</returns>
    public static Elements.Element? NewUnionFitting(Revit.Elements.Element firstPipe,
        Revit.Elements.Element secondPipe)
    {
        Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
        TransactionManager.Instance.EnsureInTransaction(doc);
        Connector? c1 = firstPipe.InternalElement.GetConnectorCloset(secondPipe.InternalElement);
        Connector? c2 = secondPipe.InternalElement.GetConnectorCloset(firstPipe.InternalElement);
        FamilyInstance newUnionFitting = doc.Create.NewUnionFitting(c2, c1);
        TransactionManager.Instance.TransactionTaskDone();
        if (newUnionFitting == null) return null;
        return newUnionFitting.ToDynamoType();
    }
1 Like

Works fine in Python. I don’t think it would be a Dynamo issue anyway since they don’t manage the API.

Are you sure each of the previous steps are returning the objects you want? Can you try with the connectors directly instead of pulling them from the pipe?

1 Like

Hi @Nick_Boyts , this is a case on my side :


import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
c1 = IN[0]
c2 = IN[1]
TransactionManager.Instance.EnsureInTransaction(doc)
fitting = doc.Create.NewUnionFitting(c1,c2)
TransactionManager.Instance.EnsureInTransaction(doc)
OUT = fitting

This can’t resolve and allway return null

I resolved by this way :

public static Elements.Element? NewUnionFitting(Autodesk.Revit.DB.Connector c1, Autodesk.Revit.DB.Connector c2)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            TransactionManager.Instance.ForceCloseTransaction();
            TransactionManager.Instance.EnsureInTransaction(doc);
            Autodesk.Revit.DB.FamilyInstance unionFitting = doc.Create.NewUnionFitting(c1, c2);
            TransactionManager.Instance.TransactionTaskDone();
            if (unionFitting == null)
            {
                ConnectorSet connectorSet = c1.AllRefs;
                IEnumerator enumerator = connectorSet.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    Connector? current = enumerator.Current as Autodesk.Revit.DB.Connector;
                    if(current == null) continue;
                    if(current.Owner is Autodesk.Revit.DB.Plumbing.Pipe) continue;
                    if(current.Owner is Autodesk.Revit.DB.Plumbing.PipingSystem) continue;
                    Elements.Element? dynamoType = current.Owner.ToDSType(true);
                    return dynamoType;
                }
            };
            if (unionFitting == null) return null;
            return unionFitting.ToDSType(true);
        }
3 Likes

You’re getting two connectors per pipe so you’re using NewUnionFittings() with lists instead of connectors. You have to be sure that the connectors you’re using are at the same location otherwise you won’t get a valid union.

@Nick_Boyts In my case, it created a union and place in project but it still return null value, may be need more people confirm.

Oh so it is creating the fitting it just doesn’t return the element in your code? Interesting. Have you tried returning just the unionFitting element without checking for a null?

@Nick_Boyts you can see gif detail, I tested in Revit 2022 and 2023 is same :

Revit_dYiH94LpJr

That is strange. @jacob.small, any ideas?

Offhand: localization, units, library causing confusion, Revit build, add-in conflict… basically something that is different between systems since it worked for one person but not another.

You could try getting the last element in the DB after creation as a work-around, but it’s an extra step that ought not be needed.

@chuongmep can you post the graph and sample file from your gif as a first step?

1 Like

Hi @jacob.small @Nick_Boyts this is sample file and script easy to get error :

Revit 2022 : DemoBugUnion.rvt
Script :
BugUnion.dyn (22.2 KB)

Your pipes aren’t the same size so you need to use NewTransitionFitting() rather than NewUnionFitting(). It seems like Revit still handles the auto-adjustment within the transaction so you still get a fitting, but the function itself is not returning a valid fitting so you get the null. That’s my guess anyway.

3 Likes

Thanks @Nick_Boyts, I just think that Revit API need to fix that because it is not clear now.If return null also should don’t create new transition in Revit, but I will accept your response like a final solution.

1 Like

Revit development team logged this 6 days back after it was discovered. My requested change was not that the behavior should remain (ensuring no one’s stuff breaks), but that there should be a remark in the documentation so that developers know of the behavior.

3 Likes