多项功能优化
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Electrical;
|
||||
@@ -9,6 +10,8 @@ using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
|
||||
|
||||
using Sai.Toolkit.Revit.Helpers;
|
||||
|
||||
namespace Sai.RvKits.RvMEP;
|
||||
@@ -24,7 +27,11 @@ internal class BloomConnectorCmd : ExternalCommand //根据连接件创建一根
|
||||
var elemIds = UiDocument.Selection.GetElementIds();
|
||||
if (elemIds.Count == 0)
|
||||
{
|
||||
var reference = UiDocument.Selection.PickObject(ObjectType.Element, new FuncFilter(e => e is FamilyInstance ins && ins.MEPModel.ConnectorManager != null), "请选择族实例");
|
||||
var reference = UiDocument.Selection
|
||||
.PickObject(
|
||||
ObjectType.Element,
|
||||
new FuncFilter(e => e is FamilyInstance ins && ins.GetConnectors(true).Size > 0),
|
||||
"请选择族实例");
|
||||
elemIds.Add(Document.GetElement(reference).Id);
|
||||
}
|
||||
|
||||
@@ -34,15 +41,13 @@ internal class BloomConnectorCmd : ExternalCommand //根据连接件创建一根
|
||||
var cableTrayTypeId = Document.OfClass<CableTrayType>().FirstElementId();
|
||||
var conduitTypeId = Document.OfClass<ConduitType>().FirstElementId();
|
||||
|
||||
var filteredElementCollector = Document.OfClass<DuctType>();
|
||||
var ductTypeCollector = Document.OfClass<DuctType>().Cast<DuctType>();
|
||||
var roundDuctTypeId = ElementId.InvalidElementId;
|
||||
var rectangleDuctTypeId = ElementId.InvalidElementId;
|
||||
var ovalDuctTypeId = ElementId.InvalidElementId;
|
||||
|
||||
foreach (var element2 in filteredElementCollector)
|
||||
//设置默认的风管类型
|
||||
foreach (var ductType in ductTypeCollector)
|
||||
{
|
||||
var ductType = (DuctType)element2;
|
||||
|
||||
if (ductType.FamilyName == "圆形风管" || ductType.FamilyName.Contains("Round Duct"))
|
||||
{
|
||||
roundDuctTypeId = ductType.Id;
|
||||
@@ -65,7 +70,7 @@ internal class BloomConnectorCmd : ExternalCommand //根据连接件创建一根
|
||||
}
|
||||
CableTray referCabTray = null;
|
||||
Conduit referConduit = null;
|
||||
//拿到连接的管线的类型
|
||||
//根据连接件拿到连接的管线的类型
|
||||
foreach (Connector conn in elem.GetConnectors())
|
||||
{
|
||||
if (conn.IsConnected)
|
||||
@@ -117,8 +122,8 @@ internal class BloomConnectorCmd : ExternalCommand //根据连接件创建一根
|
||||
Document.Invoke(
|
||||
_ =>
|
||||
{
|
||||
var conns = elem.GetConnectors(true);
|
||||
foreach (Connector connector in conns)
|
||||
var connectors = elem.GetConnectors(true);
|
||||
foreach (Connector connector in connectors)
|
||||
{
|
||||
Element element = null;
|
||||
if (elem.Category.Id.IntegerValue == (int)BuiltInCategory.OST_FabricationPipework)
|
||||
@@ -166,6 +171,7 @@ internal class BloomConnectorCmd : ExternalCommand //根据连接件创建一根
|
||||
}
|
||||
var extensionLength = connector.GetExtensionLength();
|
||||
var origin = connector.Origin;
|
||||
//延伸后的点
|
||||
var xyz2 = origin + (extensionLength * connector.CoordinateSystem.BasisZ);
|
||||
var levelId = elem.LevelId;
|
||||
if (levelId == ElementId.InvalidElementId)
|
||||
@@ -193,43 +199,43 @@ internal class BloomConnectorCmd : ExternalCommand //根据连接件创建一根
|
||||
break;
|
||||
//风管
|
||||
case Domain.DomainHvac:
|
||||
var mechanicalSystemTypes = new FilteredElementCollector(Document)
|
||||
.OfClass(typeof(MechanicalSystemType))
|
||||
.Cast<MechanicalSystemType>();
|
||||
//风管系统类型
|
||||
var mechanicalSystem =
|
||||
connector.MEPSystem == null
|
||||
? connector.DuctSystemType switch
|
||||
{
|
||||
//送风
|
||||
DuctSystemType.SupplyAir
|
||||
=> mechanicalSystemTypes.FirstOrDefault(
|
||||
pst =>
|
||||
pst.SystemClassification
|
||||
== Autodesk.Revit.DB.MEPSystemClassification.SupplyAir
|
||||
),
|
||||
//回风
|
||||
DuctSystemType.ReturnAir
|
||||
=> mechanicalSystemTypes.FirstOrDefault(
|
||||
pst =>
|
||||
pst.SystemClassification
|
||||
== Autodesk.Revit.DB.MEPSystemClassification.ReturnAir
|
||||
),
|
||||
//排风
|
||||
DuctSystemType.ExhaustAir
|
||||
=> mechanicalSystemTypes.FirstOrDefault(
|
||||
pst =>
|
||||
pst.SystemClassification
|
||||
== Autodesk.Revit.DB.MEPSystemClassification.ExhaustAir
|
||||
),
|
||||
_
|
||||
=> mechanicalSystemTypes.FirstOrDefault(
|
||||
pst =>
|
||||
pst.SystemClassification
|
||||
== Autodesk.Revit.DB.MEPSystemClassification.OtherAir
|
||||
)
|
||||
}
|
||||
: Document.GetElement(connector.MEPSystem.GetTypeId()) as MechanicalSystemType;
|
||||
//var mechanicalSystemTypes = new FilteredElementCollector(Document)
|
||||
// .OfClass(typeof(MechanicalSystemType))
|
||||
// .Cast<MechanicalSystemType>();
|
||||
////风管系统类型
|
||||
//var mechanicalSystem =
|
||||
// connector.MEPSystem == null
|
||||
// ? connector.DuctSystemType switch
|
||||
// {
|
||||
// //送风
|
||||
// DuctSystemType.SupplyAir
|
||||
// => mechanicalSystemTypes.FirstOrDefault(
|
||||
// pst =>
|
||||
// pst.SystemClassification
|
||||
// == Autodesk.Revit.DB.MEPSystemClassification.SupplyAir
|
||||
// ),
|
||||
// //回风
|
||||
// DuctSystemType.ReturnAir
|
||||
// => mechanicalSystemTypes.FirstOrDefault(
|
||||
// pst =>
|
||||
// pst.SystemClassification
|
||||
// == Autodesk.Revit.DB.MEPSystemClassification.ReturnAir
|
||||
// ),
|
||||
// //排风
|
||||
// DuctSystemType.ExhaustAir
|
||||
// => mechanicalSystemTypes.FirstOrDefault(
|
||||
// pst =>
|
||||
// pst.SystemClassification
|
||||
// == Autodesk.Revit.DB.MEPSystemClassification.ExhaustAir
|
||||
// ),
|
||||
// _
|
||||
// => mechanicalSystemTypes.FirstOrDefault(
|
||||
// pst =>
|
||||
// pst.SystemClassification
|
||||
// == Autodesk.Revit.DB.MEPSystemClassification.OtherAir
|
||||
// )
|
||||
// }
|
||||
// : Document.GetElement(connector.MEPSystem.GetTypeId()) as MechanicalSystemType;
|
||||
|
||||
//if (new FilteredElementCollector(Document).OfClass(typeof(DuctType)).FirstElement() is not DuctType)
|
||||
//{
|
||||
@@ -242,10 +248,9 @@ internal class BloomConnectorCmd : ExternalCommand //根据连接件创建一根
|
||||
case ConnectorProfileType.Round:
|
||||
element = Duct.Create(
|
||||
Document,
|
||||
mechanicalSystem.Id,
|
||||
roundDuctTypeId,
|
||||
levelId,
|
||||
origin,
|
||||
connector,
|
||||
xyz2
|
||||
);
|
||||
|
||||
@@ -256,31 +261,33 @@ internal class BloomConnectorCmd : ExternalCommand //根据连接件创建一根
|
||||
case ConnectorProfileType.Rectangular:
|
||||
element = Duct.Create(
|
||||
Document,
|
||||
mechanicalSystem.Id,
|
||||
rectangleDuctTypeId,
|
||||
levelId,
|
||||
origin,
|
||||
connector,
|
||||
xyz2
|
||||
);
|
||||
Document.Regenerate();
|
||||
element.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM).Set(connector.Width);
|
||||
element.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM).Set(connector.Height);
|
||||
var width = Math.Max(connector.Width, connector.Height);
|
||||
var height = Math.Min(connector.Width, connector.Height);
|
||||
element.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM).Set(width);
|
||||
element.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM).Set(height);
|
||||
break;
|
||||
|
||||
case ConnectorProfileType.Oval:
|
||||
element = Duct.Create(Document, mechanicalSystem.Id, ovalDuctTypeId, levelId, origin, xyz2);
|
||||
element = Duct.Create(Document, ovalDuctTypeId, levelId, connector, xyz2);
|
||||
Document.Regenerate();
|
||||
element.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM).Set(connector.Width);
|
||||
element.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM).Set(connector.Height);
|
||||
var w = Math.Max(connector.Width, connector.Height);
|
||||
var h = Math.Min(connector.Width, connector.Height);
|
||||
element.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM).Set(w);
|
||||
element.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM).Set(h);
|
||||
break;
|
||||
|
||||
default:
|
||||
element = Duct.Create(
|
||||
Document,
|
||||
mechanicalSystem.Id,
|
||||
roundDuctTypeId,
|
||||
levelId,
|
||||
origin,
|
||||
connector,
|
||||
xyz2
|
||||
);
|
||||
break;
|
||||
@@ -297,7 +304,7 @@ internal class BloomConnectorCmd : ExternalCommand //根据连接件创建一根
|
||||
.Cast<PipingSystemType>();
|
||||
if (pipeTypeId == ElementId.InvalidElementId)
|
||||
{
|
||||
pipeTypeId = Document.OfClass<PipeType>().WhereElementIsElementType().FirstElementId();
|
||||
pipeTypeId = Document.OfClass<PipeType>().FirstElementId();
|
||||
}
|
||||
var system = connector.MEPSystem;
|
||||
var pipingSystemType =
|
||||
@@ -435,9 +442,11 @@ internal class BloomConnectorCmd : ExternalCommand //根据连接件创建一根
|
||||
break;
|
||||
|
||||
case ConnectorProfileType.Rectangular:
|
||||
var width = Math.Max(connector.Width, connector.Height);
|
||||
var height = Math.Min(connector.Width, connector.Height);
|
||||
element = CableTray.Create(Document, cableTrayTypeId, origin, xyz2, levelId);
|
||||
element.get_Parameter(BuiltInParameter.RBS_CABLETRAY_WIDTH_PARAM).Set(connector.Width);
|
||||
element.get_Parameter(BuiltInParameter.RBS_CABLETRAY_HEIGHT_PARAM).Set(connector.Height);
|
||||
element.get_Parameter(BuiltInParameter.RBS_CABLETRAY_WIDTH_PARAM).Set(width);
|
||||
element.get_Parameter(BuiltInParameter.RBS_CABLETRAY_HEIGHT_PARAM).Set(height);
|
||||
if (referCabTray != null)
|
||||
{
|
||||
var value = referCabTray.get_Parameter(
|
||||
@@ -460,15 +469,81 @@ internal class BloomConnectorCmd : ExternalCommand //根据连接件创建一根
|
||||
continue;
|
||||
}
|
||||
var curve = element as MEPCurve;
|
||||
var manager = curve.ConnectorManager;
|
||||
var lter = manager.UnusedConnectors.ForwardIterator();
|
||||
while (lter.MoveNext())
|
||||
var conns = curve.ConnectorManager.UnusedConnectors.Cast<Connector>();
|
||||
foreach (var connect in conns)
|
||||
{
|
||||
var connect = lter.Current as Connector;
|
||||
if (connect.Origin.IsAlmostEqualTo(connector.Origin))
|
||||
{
|
||||
Debug.WriteLine("新建管线:");
|
||||
Debug.WriteLine(connect.CoordinateSystem.BasisX);
|
||||
Debug.WriteLine(connect.CoordinateSystem.BasisY);
|
||||
Debug.WriteLine(connect.CoordinateSystem.BasisZ);
|
||||
Debug.WriteLine("管件:");
|
||||
Debug.WriteLine(connector.CoordinateSystem.BasisX);
|
||||
Debug.WriteLine(connector.CoordinateSystem.BasisY);
|
||||
Debug.WriteLine(connector.CoordinateSystem.BasisZ);
|
||||
var isStandMEPCurve = connect.CoordinateSystem.BasisZ.CrossProduct(XYZ.BasisZ).IsAlmostEqualTo(XYZ.Zero);
|
||||
|
||||
if (isStandMEPCurve)
|
||||
{
|
||||
var angleX = Math.Acos(connect.CoordinateSystem.BasisX.DotProduct(connector.CoordinateSystem.BasisX));
|
||||
Debug.WriteLine(angleX);
|
||||
var crossProduct = connect.CoordinateSystem.BasisX
|
||||
.CrossProduct(connector.CoordinateSystem.BasisX).Normalize();
|
||||
var angle = Math.Acos(connect.CoordinateSystem.BasisX.DotProduct(connector.CoordinateSystem.BasisX));
|
||||
if (crossProduct.IsAlmostEqualTo(XYZ.Zero))
|
||||
{
|
||||
if (connect.CoordinateSystem.BasisX
|
||||
.IsAlmostEqualTo(connector.CoordinateSystem.BasisX))
|
||||
{
|
||||
ElementTransformUtils.RotateElement(
|
||||
Document,
|
||||
element.Id,
|
||||
Line.CreateUnbound(origin, XYZ.BasisZ),
|
||||
Math.PI / 2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (angleX > Math.PI / 2)
|
||||
{
|
||||
ElementTransformUtils.RotateElement(
|
||||
Document,
|
||||
element.Id,
|
||||
Line.CreateUnbound(origin, XYZ.BasisZ),
|
||||
angleX - Math.PI / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
ElementTransformUtils.RotateElement(
|
||||
Document,
|
||||
element.Id,
|
||||
Line.CreateUnbound(origin, XYZ.BasisZ),
|
||||
Math.PI / 2 - angleX);
|
||||
}
|
||||
}
|
||||
//if (Math.Abs(angleX - Math.PI / 2) > 0.001)
|
||||
//{
|
||||
// ElementTransformUtils.RotateElement(
|
||||
// Document,
|
||||
// element.Id,
|
||||
// Line.CreateUnbound(origin, crossProduct),
|
||||
// angleX - Math.PI / 2
|
||||
// );
|
||||
// Debug.WriteLine("旋转后新建管线:");
|
||||
// Debug.WriteLine(connect.CoordinateSystem.BasisX);
|
||||
// Debug.WriteLine(connect.CoordinateSystem.BasisY);
|
||||
// Debug.WriteLine(connect.CoordinateSystem.BasisZ);
|
||||
// Document.Regenerate();
|
||||
// angle = Math.Acos(connect.CoordinateSystem.BasisX.DotProduct(connector.CoordinateSystem.BasisX));
|
||||
// Debug.WriteLine(nameof(angle) + angle);
|
||||
//}
|
||||
}
|
||||
var conn = elem.GetConnectors(true).GetNearestConnector(connector.Origin);
|
||||
conn.ConnectTo(connect);
|
||||
if (!connect.IsConnectedTo(connector))
|
||||
{
|
||||
connect.ConnectTo(connector);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user