Pipe duplicated when using Zerotouch library or python

Hi , I have a doubt when using Revit API and zero touzh

I have the following code to create for example a flexpipe in one of my custom libraries.

public static void makepipe(Autodesk.DesignScript.Geometry.Curve crv, double h)
    {
       UIApplication uiApplication = DocumentManager.Instance.CurrentUIApplication;
        UIDocument activeUiDocument = uiApplication.ActiveUIDocument;
        Document document = activeUiDocument.Document;

        FilteredElementCollector collector = new FilteredElementCollector(document);
        collector.OfClass(typeof(Autodesk.Revit.DB.Plumbing.FlexPipeType));
        ElementId pipeTypeId = collector.FirstElementId();

        FilteredElementCollector sysCollector = new FilteredElementCollector(document);
        sysCollector.OfClass(typeof(Autodesk.Revit.DB.Plumbing.PipingSystemType));
        ElementId pipeSysTypeId = sysCollector.FirstElementId();

        FilteredElementCollector coll = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.Level));
        Autodesk.Revit.DB.Level lvl = coll.ToElements()[0] as Autodesk.Revit.DB.Level;

        Autodesk.Revit.DB.Plumbing.FlexPipe pipe = null;
        if (pipeTypeId != ElementId.InvalidElementId && pipeSysTypeId != ElementId.InvalidElementId)
        {
            Autodesk.DesignScript.Geometry.Point stPt = crv.StartPoint;
            Autodesk.DesignScript.Geometry.Point midPt = crv.PointAtParameter(0.5);
            Autodesk.DesignScript.Geometry.Point endPt = crv.EndPoint;

            List<XYZ> points = new List<XYZ>();
            points.Add(new XYZ(stPt.X, stPt.Y, stPt.Z));
            points.Add(new XYZ(midPt.X, midPt.Y, midPt.Z+ h));
            points.Add(new XYZ(endPt.X,endPt.Y,endPt.Z));

            XYZ tan1 = new XYZ(0,0,1);
            XYZ tan2 = new XYZ(0,0,-1);

            using (Transaction trans = new Transaction(document, "wall"))

            {
                trans.Start();
                using (Autodesk.Revit.DB.Plumbing.FlexPipe.Create(document, pipeSysTypeId, pipeTypeId, lvl.Id, tan1,tan2, points)) ;
                trans.Commit();
            }
        }

       
    }

My problem is that every time I run the node, the pipes and change for example the lenght of the pipes, it doesnt modify them but creates new instances. I just want to modify the instances created.
The other problem is that it creates everything in what i guess is imperial system. (I work with meters but if i change to feet, it goes ok, how can i change this.

thansk for the help.

Hi,

I’ve got a few recommendations for you:

  1. You’ll need to return the pipe element to Dynamo and ideally wrap it so that the node can track it and not duplicate it. To do that, you’ll need to change your code a bit and use the “ToDSType” method on the flexpipe element.

  2. If your code will run from Dynamo, It’s strongly recommended to use Dynamo’s built in transaction manager.

    public static object makepipe(Autodesk.DesignScript.Geometry.Curve crv, double h)
    {
    Document doc = DocumentManager.Instance.CurrentDBDocument;

         FilteredElementCollector collector = new FilteredElementCollector(doc);
         collector.OfClass(typeof(FlexPipeType) );
         ElementId pipeTypeId = collector.FirstElementId();
    
         FilteredElementCollector sysCollector = new FilteredElementCollector(doc);
         sysCollector.OfClass(typeof(PipingSystemType) );
         ElementId pipeSysTypeId = sysCollector.FirstElementId();
    
         FilteredElementCollector coll = new FilteredElementCollector(doc)
             .OfClass(typeof(Autodesk.Revit.DB.Level) );
             Autodesk.Revit.DB.Level lvl = coll.ToElements()[0]
             as Autodesk.Revit.DB.Level;
    
         Autodesk.Revit.DB.Plumbing.FlexPipe pipe = null;
         if (pipeTypeId != ElementId.InvalidElementId
             && pipeSysTypeId != ElementId.InvalidElementId)
         {
             Autodesk.DesignScript.Geometry.Point stPt = crv.StartPoint;
             Autodesk.DesignScript.Geometry.Point midPt = crv.PointAtParameter(0.5);
             Autodesk.DesignScript.Geometry.Point endPt = crv.EndPoint;
    
             List<XYZ> points = new List<XYZ>();
             points.Add(new XYZ(stPt.X, stPt.Y, stPt.Z));
             points.Add(new XYZ(midPt.X, midPt.Y, midPt.Z+ h));
             points.Add(new XYZ(endPt.X,endPt.Y,endPt.Z));
    
             XYZ tan1 = new XYZ(0,0,1);
             XYZ tan2 = new XYZ(0,0,-1);
    
             TransactionManager.Instance.EnsureInTransaction(doc);
             FlexPipe new_pipe = Autodesk.Revit.DB.Plumbing.FlexPipe.Create
                 (doc, pipeSysTypeId, pipeTypeId, lvl.Id, tan1,tan2, points);
             TransactionManager.Instance.TransactionTaskDone();
             return new_pipe.ToDSType(false);
         }
         return null;
     }
    

    makepipe(crv, h) //not a standard CS call

Here’s an example of the above code running inside Dynamo’s CS interpreter ( you can find it on the package manager):

thanks for the help.

I was a little confused about using dynamo´s built in trasaction since in the wiki about zerotouch they don´t mention it and it says people should use using or dispose.

thanks!! works like a charm