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;
Solved! Go to Solution.
Solved by reylorente1. Go to Solution.
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();
Sorry, I've posted an early version of the code. Just updated. Thank you, by the way.
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.
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);
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.
Can't find what you're looking for? Ask the community or share your knowledge.