Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating Pipe Placeholder from line

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
h.f.h
518 Views, 8 Replies

Creating Pipe Placeholder from line

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;

8 REPLIES 8
Message 2 of 9
reylorente1
in reply to: h.f.h

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();

 

 

 

Message 3 of 9
h.f.h
in reply to: reylorente1

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

Message 4 of 9
reylorente1
in reply to: h.f.h

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.

Message 5 of 9
h.f.h
in reply to: reylorente1

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);

Message 6 of 9
reylorente1
in reply to: h.f.h

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.
Message 7 of 9
reylorente1
in reply to: reylorente1

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.
Message 8 of 9
h.f.h
in reply to: reylorente1

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.

Message 9 of 9
reylorente1
in reply to: h.f.h

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community