调整代码
This commit is contained in:
45
ShrlAlgoToolkit.RevitAddins/Mep/DisconnectCmd.cs
Normal file
45
ShrlAlgoToolkit.RevitAddins/Mep/DisconnectCmd.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.RvMEP;
|
||||
using ShrlAlgoToolkit;
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Mep;
|
||||
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
public class DisconnectCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
try
|
||||
{
|
||||
var filter = new FuncFilter(e => e is MEPCurve || (e is FamilyInstance instance && instance.MEPModel.ConnectorManager != null));
|
||||
|
||||
var reference1 = UiDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, filter, "请选择需要断开连接的第一个设备或管线");
|
||||
var reference2 = UiDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, filter, "请选择需要断开连接的第二个设备或管线");
|
||||
var element1 = Document.GetElement(reference1);
|
||||
var element2 = Document.GetElement(reference2);
|
||||
Document.Invoke(
|
||||
_ =>
|
||||
{
|
||||
if (element1.Id == element2.Id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (Connector conn in element1.GetConnectors(false))
|
||||
{
|
||||
var connectedConn = conn.GetConnectedConnector();
|
||||
if (connectedConn != null && connectedConn.Owner.Id == element2.Id)
|
||||
{
|
||||
conn.DisconnectFrom(connectedConn);
|
||||
}
|
||||
}
|
||||
},
|
||||
"取消连接"
|
||||
);
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException) { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user