Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Creating Pipe Placeholder from line

h.f.h
Contributor

Creating Pipe Placeholder from line

h.f.h
Contributor
Contributor

Hello,

 

I'm having trouble creating pipe placeholders in Revit. The function always returns an error stating 'The systemTypeId is not a valid piping system type.' I've tried using all possible system types, but the issue persists. Can someone assist me?

 

 

My code so far:

// 
ElementId levelId = view.LevelId as ElementId;

//
FilteredElementCollector collector = new FilteredElementCollector(document)
.OfClass(typeof(MEPSystem));

ElementId sysId = null;


foreach (MEPSystem syselement in collector)
{
ElementId sysId1 = syselement.Id as ElementId;
Boolean teste = Pipe.IsPipingSystemTypeId(document, sysId1);
if (teste == true)
{
sysId = sysId1;
}

}


//MEPSystem systemType = collector.FirstElement() as MEPSystem;
//SEGMENT TYPE
FilteredElementCollector collector2 = new FilteredElementCollector(document)
.OfClass(typeof(PipeSegment));

PipeSegment pipeType = collector2.FirstElement() as PipeSegment;

// 
LocationCurve c = element.Location as LocationCurve;
XYZ start = c.Curve.GetEndPoint(0);
XYZ end = c.Curve.GetEndPoint(1);
Curve beamLine = Line.CreateBound(start, end);

// 
Pipe placeholder = Pipe.CreatePlaceholder(doc, sysId, pipeType.Id, levelId, start, end);


return placeholder;

0 Likes
Reply
Accepted solutions (1)
654 Views
8 Replies
Replies (8)

reylorente1
Advocate
Advocate

Error :FilteredElementCollector collector2 = new FilteredElementCollector(document) .OfClass(typeof(Pipe)).OfCategory(BuiltInCategory.OST_PipeSegments);

You don't get the PipeType,

you must use:

 

FilteredElementCollector collector2 = new FilteredElementCollector(document)
.OfClass(typeof(PipeType));

 

Or you can use directly:

//Get PipeType
var pipeType = new FilteredElementCollector(document).OfClass(typeof(PipeType)).FirstElementId();

 

 

 

0 Likes

h.f.h
Contributor
Contributor

Sorry, I've posted an early version of the code. Just updated. Thank you, by the way.

0 Likes

reylorente1
Advocate
Advocate
Accepted solution
public void CreatePipe(UIDocument uidoc)
{
    Document doc = uidoc.Document;

    ElementId getElementId = uidoc.Selection.GetElementIds().FirstOrDefault();

    XYZ starPoint = null;
    XYZ endPoint = null;

    CurveElement curveElement = null;

    if (doc.GetElement(getElementId) is CurveElement)
    {
        curveElement = doc.GetElement(getElementId) as CurveElement;

       Curve curve = curveElement.GeometryCurve;

         starPoint = curve.GetEndPoint(0);
         endPoint = curve.GetEndPoint(1);
    } 


    //Get Level
    var level = uidoc.ActiveView.GenLevel;

    //Get PipingSystemType
    PipingSystemType systemType = (from PipingSystemType x in new FilteredElementCollector(doc).OfClass(typeof(PipingSystemType))
                                   where x.SystemClassification == MEPSystemClassification.DomesticColdWater
                                   select x).First();


    //Get PipeType
    var pipeType = new FilteredElementCollector(doc).OfClass(typeof(PipeType)).FirstElementId();

    using (Transaction curves = new Transaction(doc, "Create P1pe"))
    {
        curves.Start();
        //doc.Regenerate();
        Pipe pipeHolder = Pipe.CreatePlaceholder(doc, systemType.Id, pipeType, level.Id, starPoint, endPoint);
        //Adicionar Diametro
        Parameter param = pipeHolder.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
        double valor = 0.4921259842519685;// 150 mm
        param.Set(valor);
        
        doc.Regenerate();
        doc.Delete(curveElement.Id);

        curves.Commit();
    }
}

I hope it helps you.

h.f.h
Contributor
Contributor

Thank you, your old post helped me a lot. I don't understand why I needed to declare the variables as 'var' and not as 'PipeSystems' or 'PipeSegments', but it just works fine.

 

Here is the final version so far.

 

// get the given view's level for beam creation
Level level = uiDoc.ActiveView.GenLevel;

//SYSTEM TYPE
var systemType = new FilteredElementCollector(doc).OfClass(typeof(PipingSystemType)).FirstElementId();
//FilteredElementCollector collector = new FilteredElementCollector(document).OfClass(typeof(MEPSystem));

ElementId sysId = systemType;
Boolean teste = Pipe.IsPipingSystemTypeId(document, sysId);

//foreach (MEPSystem syselement in collector)
//{
// ElementId sysId1 = syselement.Id as ElementId;
// Boolean teste = Pipe.IsPipingSystemTypeId(document, sysId1);
// if (teste == true)
// {
// sysId = sysId1;
// }

//}


//MEPSystem systemType = collector.FirstElement() as MEPSystem;
//SEGMENT TYPE
//FilteredElementCollector collector2 = new FilteredElementCollector(document)
// .OfClass(typeof(PipeSegment));

//PipeSegment pipeType = collector2.FirstElement() as PipeSegment;
var pipeTypeId = new FilteredElementCollector(document).OfClass(typeof(PipeType)).FirstElementId();
// need this part to return some value
LocationCurve c = element.Location as LocationCurve;
XYZ start = c.Curve.GetEndPoint(0);
XYZ end = c.Curve.GetEndPoint(1);
Curve beamLine = Line.CreateBound(start, end);

// create a new beam
Pipe placeholder = Pipe.CreatePlaceholder(doc, sysId, pipeTypeId, level.Id, start, end);

0 Likes

reylorente1
Advocate
Advocate
It seems to me that you should see the API Documentation, so you can see how a PlaceHolder is created
https://www.revitapidocs.com/2024/f291f914-aa0c-f6b0-c824-3fffe0191aba.htm.
0 Likes

reylorente1
Advocate
Advocate
I think you should see the API Documentation, so you can see how to create a PlaceHolder.
But the interesting thing would be how to add the elbows and the tee, since, if you are looking for PlumbingUtils, there are two methods, to make these additions, that is, select, when it is a tee and when it is an elbow, in the same path where these lines meet.
0 Likes

h.f.h
Contributor
Contributor

I know that and I also checked the project browser in visual studio. But for exemple:

 

FilteredElementCollector collector2 = new FilteredElementCollector(document).OfClass(typeof(PipeSegment));

PipeSegment pipeType = collector2.FirstElement() as PipeSegment;  ----> than ---> pipeType.Id at the createplaceholder method (GOT AN ERROR)

 

And for this it works : 

var pipeTypeId = new FilteredElementCollector(document).OfClass(typeof(PipeType)).FirstElementId(); 

Can't see why. Missing something here.

0 Likes

reylorente1
Advocate
Advocate
To create the PlaceHolder, you need the PipeType and not the pipeSegment.See the documentation:
CreatePlaceholder Method:
Creates a new placeholder pipe.
C#
public static Pipe CreatePlaceholder(
Document document,
ElementId systemTypeId,
ElementId pipeTypeId,
ElementId levelId,
XYZ startPoint,
XYZ endPoint
)
Parameters
document
Type: Autodesk.Revit.DB Document
The document.
systemTypeId
Type: Autodesk.Revit.DB ElementId
The ElementId of the piping system type.
pipeTypeId
Type: Autodesk.Revit.DB ElementId
The ElementId of the pipe type.
levelId
Type: Autodesk.Revit.DB ElementId
The level id for the pipe.
startPoint
Type: Autodesk.Revit.DB XYZ
The first point of the placeholder line.
endPoint
Type: Autodesk.Revit.DB XYZ
The second point of the placeholder line.