How Can I set the system name for a Pipe?

How Can I set the system name for a Pipe?

Bruno_Neves_Pires_Silva
Advocate Advocate
2,918 Views
8 Replies
Message 1 of 9

How Can I set the system name for a Pipe?

Bruno_Neves_Pires_Silva
Advocate
Advocate

How Can I set the system name for a Pipe?

 

  The parameter is read-only. In the interface, I can change it selecting the pipe and then in the tab Piping System I can change:

 

//The parameter is read-only

Parameter prm =  _pipe.get_Parameter(BuiltInParameter.RBS_SYSTEM_NAME_PARAM);

0 Likes
Accepted solutions (1)
2,919 Views
8 Replies
Replies (8)
Message 2 of 9

Aaron.Lu
Autodesk
Autodesk
Dear Bruno,

It cannot be set system name directly, even in UI.
I think the right way should be: connect equipments/components in the system you want to change to with this pipe


Aaron Lu
Developer Technical Services
Autodesk Developer Network
Message 3 of 9

Bruno_Neves_Pires_Silva
Advocate
Advocate

Dear Aaron.

 

 

    Thank you for your reply. 

    But yes, it can be set in UI. See the attached image. Selecting the pipe, and selecting the Piping System tab, I can change the system name. But I can't do the same through API.

     But I didnt understand how connecting equipments/components can help.

 

Regards, 

Bruno Neves

0 Likes
Message 4 of 9

Bruno_Neves_Pires_Silva
Advocate
Advocate

In fact, is this same problem, that was not yet answered:

 

https://forums.autodesk.com/t5/revit-api/system-name-is-changing-after-new-pipe-is-created/td-p/5652...

 

Is there a solution ?

0 Likes
Message 5 of 9

Aaron.Lu
Autodesk
Autodesk
I see, you can do that in UI in the edit mode, however you can only change to a new name which does not exist.
There should be no API counterpart.

then is it feasible to change the name of the PipingSystem directly?
i.e. (Pipe.MEPSystem as PipingSystem).Name = "the new name"


Aaron Lu
Developer Technical Services
Autodesk Developer Network
Message 6 of 9

Bruno_Neves_Pires_Silva
Advocate
Advocate
Accepted solution

Hi, Aaron.

 

  Thank you for your reply.

 

   when I get the parameter from the MEPSsytem is not read only and I can change the name. The problem is that I coud not set the same name of the previous pipe.

Augusto Gonçalves helped me on this, the problem was thas I was not connecting properly the pipes in the previous pipe system. When I did, the pipes assumed the right name, and it was not necessary change the name.

 

 

 

Best Regards,

Bruno Neves.

Message 7 of 9

Aaron.Lu
Autodesk
Autodesk
cool, this is actually the solution I've provided in the first time, maybe I did not make it clear 🙂


Aaron Lu
Developer Technical Services
Autodesk Developer Network
Message 8 of 9

jeremytammik
Autodesk
Autodesk

Dear Bruno,

 

Thank you for confirming that this approach really does work.

 

Can you provide a code snippet to demonstrate the exact steps?

 

Then I can publish the full detailed solution on The Building Coder to make it easier to find and understand and preserve it for posteriority.

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 9

Bruno_Neves_Pires_Silva
Advocate
Advocate

Ok, Jeremy, here is what I did.

 

But I dont know how to format this thing properly:

 

double SplitSize = 3000,
SplitTol = 150;
private void SplitPipe(Pipe _pipe, Document doc, Transaction t)
{
if (_pipe == null)
return;

LocationCurve lc = _pipe.Location as LocationCurve;
Curve cv = lc.Curve;
ElementId _pipeMEP = new ElementId(_pipe.MEPSystem.GetTypeId().IntegerValue);
ElementId _pipeType = new ElementId(_pipe.PipeType.Id.IntegerValue);
ElementId _pipeLvl = new ElementId(_pipe.ReferenceLevel.Id.IntegerValue);
string diam_s = _pipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM).AsValueString();
int i;
double leng1 = Util.FootToMm(cv.Length);


if (leng1 < (SplitSize + SplitTol))
return;

XYZ sp = cv.GetEndPoint(0), ep = cv.GetEndPoint(1);

Connector c4, conStart = null, conEnd = null;
foreach (Connector cn in _pipe.ConnectorManager.Connectors)
if (cn.IsConnected)
foreach (Connector c2 in cn.AllRefs)
if (c2.Owner.Id != _pipe.Id)
{
double d1 = c2.Origin.DistanceTo(sp);
double d2 = c2.Origin.DistanceTo(ep);

if (d1 < d2)
conStart = c2;
else
conEnd = c2;
}


doc.Delete(_pipe.Id);

List<XYZ> pts = SplitLine(cv.GetEndPoint(0), cv.GetEndPoint(1), SplitSize);
Pipe pp1 = null, pp2 = null;

for (i = 1; i < pts.Count; i += 2)
{
pp2 = Pipe.Create(doc, _pipeMEP, _pipeType, _pipeLvl, pts[i - 1], pts[i]);
pp2.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM).SetValueString(diam_s);

if (pp1 != null)
{
Connector c1 = GetConnectorClosestTo(pp1, pts[i - 1]),
c2 = GetConnectorClosestTo(pp2, pts[i - 1]);
FamilyInstance luva = doc.Create.NewUnionFitting(c1, c2);


}
else if (conStart != null)
{
c4 = GetConnectorClosestTo(pp2, pts[i - 1]);
conStart.ConnectTo(c4);
}

if ((conEnd != null) && (i == (pts.Count - 1)))
{
c4 = GetConnectorClosestTo(pp2, pts[i]);
conEnd.ConnectTo(c4);
}
pp1 = pp2;
}
}
//-------------------------------------------------------------------------
List<XYZ> SplitLine(XYZ sp, XYZ ep, double leng_mm)
{
List<XYZ> rval = new List<XYZ>();
double dist = sp.DistanceTo(ep),
leng_foot = Util.MmToFoot(leng_mm),
tol = Util.MmToFoot(SplitTol);

if (dist == 0)
return rval;

rval.Add(sp);

if (dist <= leng_foot + tol)
{
rval.Add(ep);
return rval;
}

double prop = dist / leng_foot;
int n = (int)Math.Floor(prop);

XYZ gap, step, mid2, mid1 = sp;

step = ((ep - sp) / prop);
gap = 0.01 * (ep - sp) / dist;
for (int i = 0; i < n; i++)
{
mid1 = mid1 + step;

if (mid1.DistanceTo(ep) < tol)
break;
mid2 = mid1 + gap;

rval.Add(mid1);
rval.Add(mid2);
}

rval.Add(ep);

return rval;
}
//-------------------------------------------------------------------------
Connector GetConnectorClosestTo(Element e, XYZ p)
{
ConnectorManager cm = GetConnectorManager(e);
return null == cm ? null : GetConnectorClosestTo(cm.Connectors, p);
}
//-------------------------------------------------------------------------------
Connector GetConnectorClosestTo(ConnectorSet connectors, XYZ p)
{
Connector targetConnector = null;
double minDist = double.MaxValue;

foreach (Connector c in connectors)
{
double d = c.Origin.DistanceTo(p);

if (d < minDist)
{
targetConnector = c;
minDist = d;
}
}
return targetConnector;
}
//-------------------------------------------------------------------------------
ConnectorManager GetConnectorManager(Element e)
{
MEPCurve mc = e as MEPCurve;
FamilyInstance fi = e as FamilyInstance;

if (null == mc && null == fi)
throw new ArgumentException("Element is neither an MEP curve nor a fitting.");

return null == mc ? fi.MEPModel.ConnectorManager : mc.ConnectorManager;
}

0 Likes