年关将至,小编在这里提前祝福所有粉丝新春快乐。
疫情依旧,做好防护。
期待春风拂去一切阴霾,还我山河澄澈,岁月静好。
这是2021年的第一篇文章,又懒了很久,没有更新,今天来更新一下。
最近小编做管综的时候面对三通翻弯很麻烦,所以就想着写个插件来解决吧。这些思路想法给大家一些启发,有用就看看,没用大家还是一起去吃瓜吧。
看一下效果:
实现这一功能的思路和代码:
获得管道
Reference eleref = sel.PickObject(ObjectType.Element, pipeFilter, "选择要抬高的管道");
Pipe pp = doc.GetElement(eleref) as Pipe;//获得管道
获取翻弯点
Reference refPoint = sel.PickObject(ObjectType.PointOnElement, "选择翻弯点,按ESC则整根管道抬高");
pointXYZ = refPoint.GlobalPoint;//翻弯点
获得管道的连接件
ConnectorSetIterator connectorSet1 = pp.ConnectorManager.Connectors.ForwardIterator();
找到所有连接器连接的连接器
while (connectorSet1.MoveNext())
{
Connector conn = connectorSet1.Current as Connector;//管道的连接件
if (conn.IsConnected == true)//是否有连接
{
ConnectorSet connectorSet = conn.AllRefs;//找到所有连接器连接的连接器
ConnectorSetIterator csiChild = connectorSet.ForwardIterator();
}
5.将连接断开
connected.DisconnectFrom(conn);
6.旋转管件
/// <summary>
/// 旋转管件
/// </summary>
/// <param name="doc"></param>
/// <param name="connected"></param>
/// <param name="jd"></param>
public void ConnRotateElements(Document doc, Connector connected, double jd)
{
XYZ coxyz = ((connected.Owner) as FamilyInstance).HandOrientation;
var location = (((connected.Owner) as FamilyInstance).Location as LocationPoint).Point;//管件坐标点
var anxisline = Line.CreateUnbound(location, coxyz);//管件坐标点和管线方向画轴线
ElementTransformUtils.RotateElement(doc, connected.Owner.Id, anxisline, Math.PI / jd);
doc.Regenerate();//更新revit文档
}
7.创建竖直管道
/// <summary>
/// 创建竖直管道
/// </summary>
/// <param name="doc"></param>
/// <param name="pp"></param>
/// <param name="conn"></param>
/// <param name="value"></param>
/// <returns></returns>
public Pipe CreateVerticalPipe(Document doc, Pipe pp, Connector conn, double value, bool connTrue)
{
//pp.GetParameters("偏移量")[0].Set(pp.GetParameters("偏移量")[0].AsDouble() + value);
XYZ xYznewpp = null;
Curve newcurve = null;
//获取原管线的坐标
Curve curvepp = ((pp.Location) as LocationCurve).Curve;
XYZ xYZpp0 = curvepp.GetEndPoint(0);
XYZ xYZpp1 = curvepp.GetEndPoint(1);
Pipe pi = doc.GetElement(ElementTransformUtils.CopyElement(doc, pp.Id, xYZpp0).ElementAt(0)) as Pipe;//复制管道
ConnectorManager connp = pi.ConnectorManager;
ConnectorSetIterator connpse = connp.Connectors.ForwardIterator();
XYZ xYZ0 = conn.Origin;//连接件原点
while (connpse.MoveNext())
{
Connector connpipe = connpse.Current as Connector;
XYZ xYZp = connpipe.Origin;
//XYZ connxyz = ((conn.Owner.Location) as LocationPoint).Point;
XYZ xyznew = new XYZ(xYZ0.X, xYZ0.Y, xYZ0.Z);
xYznewpp = new XYZ(xYZ0.X, xYZ0.Y, xYZ0.Z + value);
newcurve = Line.CreateBound(xYznewpp, xyznew);
((pi.Location) as LocationCurve).Curve = newcurve;//管道替代
if (connTrue)//是否要穿连接
{
if ((xYZp.DistanceTo(xYZ0) * 304.8) == 0)
{
conn.ConnectTo(connpipe);
}
}
}
return pi;
}
8.原来的管道复制缩短替换
Pipe ppNew2 = doc.GetElement(ElementTransformUtils.CopyElement(doc, pp.Id, xYZpp0).ElementAt(0)) as Pipe;//复制管道
Line newcurve2 = Line.CreateBound(new XYZ(xYZLg2.X, xYZLg2.Y, xYZpp0.Z), lineXYZ);
((ppNew2.Location) as LocationCurve).Curve = newcurve2;//管道替代
ppNew2.GetParameters("偏移量")[0].Set(pp.GetParameters("偏移量")[0].AsDouble() + value);
9.创建弯头
/// <summary>
/// 创建两个管道的弯头
/// </summary>
/// <param name="doc"></param>
/// <param name="pipe1"></param>
/// <param name="pipe2"></param>
public void CreatElbowFittingPipe(Document doc, Pipe pipe1, Pipe pipe2)
{
ConnectorManager connm1 = pipe1.ConnectorManager;//管道1的连接件
ConnectorSetIterator connse = connm1.Connectors.ForwardIterator();
List<Connector> connlist = new List<Connector>();
while (connse.MoveNext())
{
Connector conn1 = connse.Current as Connector;
connlist.Add(conn1);
}
try
{
ConnectorManager manager = pipe2.ConnectorManager;//管道2的连接件
ConnectorSetIterator setIterator = manager.Connectors.ForwardIterator();
while (setIterator.MoveNext())
{
Connector conn2 = setIterator.Current as Connector;
connlist.Add(conn2);
}
for (int i = 0; i < connlist.Count; i++)
{
for (int j = 0; j < connlist.Count; j++)
{
try
{
// MessageBox.Show((connlist[i].Origin.DistanceTo(connlist[j].Origin)*304.8).ToString());
if (connlist[i].Origin.DistanceTo(connlist[j].Origin) < 100 / 304.8 && connlist[i].IsConnected == false)
{
doc.Create.NewElbowFitting(connlist[i], connlist[j]);
}
}
catch
{
}
}
}
}
catch
{
}
}
基本上就是这么一个过程。有问题可以留言,小编看见会解答。平时没有放出留言的习惯,所以留言就小编可见,哈哈哈哈哈哈哈。。。。。