To obtain the reference of the curve of the pipe and set its dimensions accordingly, you need to access the linked document containing the pipe. it would be good to read a bit of explanation and a practical demonstration over this post and this post. This involves working with linked references. The following steps will guide you through the process:
- Retrieve the linked pipe element.
- Obtain the RevitLinkInstance.
- Extract the geometry of the pipe.
- Access the first element, which typically represents the location curve reference. Note that this behavior is based on experience and may change in future Revit versions, so thorough testing is recommended.
see this example that demonstrate the above steps:
var linkedPipeReference = UiDoc.Selection.PickObject(ObjectType.PointOnElement);
var revitLinkInstance =
Doc.GetElement(linkedPipeReference.ElementId) as RevitLinkInstance;
var linkedPipe = revitLinkInstance
.GetLinkDocument()
.GetElement(linkedPipeReference.LinkedElementId);
var op = new Options()
{
DetailLevel = ViewDetailLevel.Undefined,
IncludeNonVisibleObjects = true,
ComputeReferences = true
};
var geo = linkedPipe.get_Geometry(op);
if (geo is null)
{
// element Geometry can't be extracted
return null;
}
List<Line> geoObjects = geo.OfType<Line>().ToList();
var instances = geo.OfType<GeometryInstance>();
foreach (var ins in instances)
{
var geoIns = ins.GetSymbolGeometry();
geoObjects.AddRange(geoIns.OfType<Line>());
}
var pipeCurveReference = geoObjects.FirstOrDefault()?.Reference;
if (pipeCurveReference != null && revitLinkInstance != null)
{
pipeCurveReference = pipeCurve.CreateLinkReference(revitLinkInstance);
}
// now you can play with pipeCurveReference
see if this helps, and let us know your findings
Moustafa Khalil