多项功能优化
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Windows;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
@@ -22,7 +23,126 @@ public class TempCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
var elemIds = Document.OfClass<Pipe>().Cast<Pipe>().Where(p => p.Diameter == 50 / 304.8 && !(p.GetLocCurve() as Line).Direction.IsParallelTo(XYZ.BasisZ)).Select(p => p.Id).ToList();
|
||||
CreateWindow win = new CreateWindow();
|
||||
win.Show();
|
||||
//ConnectSprinklers();
|
||||
//var unUseSpk = Document.ActiveView.OfClass<FamilyInstance>().OfCategory(BuiltInCategory.OST_Sprinklers).Where(e => e.GetConnectors(true).Size == 1).Select(e => e.Id).ToList();
|
||||
//UiDocument.Selection.SetElementIds(unUseSpk);
|
||||
//ConnectToStandPipe();
|
||||
//var unUseSpk = Document.ActiveView.OfClass<FamilyInstance>().OfCategory(BuiltInCategory.OST_Sprinklers).Where(e => e.GetConnectors(true).Size == 1).ToList();
|
||||
//var spks = Document.ActiveView.OfClass<FamilyInstance>().OfCategory(BuiltInCategory.OST_Sprinklers).Where(e => e.GetConnectors(true).Size == 0).ToList();
|
||||
//List<Element> li = [];
|
||||
//foreach (var item in spks)
|
||||
//{
|
||||
// var conn = item.GetLocXYZ();
|
||||
// foreach (var spk in unUseSpk)
|
||||
// {
|
||||
// //var conn1 = spk.GetConnectors(true).OfType<Connector>().FirstOrDefault();
|
||||
|
||||
// if (item.GetLocXYZ().IsAlmostEqualTo(spk.GetLocXYZ()))
|
||||
// {
|
||||
// li.Add(spk);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//Document.Invoke(
|
||||
// ts =>
|
||||
// {
|
||||
// Document.Delete(li.Select(e => e.Id).ToList());
|
||||
// });
|
||||
//MessageBox.Show(sks.Count.ToString());
|
||||
|
||||
}
|
||||
|
||||
private void ConnectToStandPipe()
|
||||
{
|
||||
var pipes = Document.ActiveView.OfClass<Pipe>().Where(e => e.GetConnectors(true).Size == 1 && (e.GetCurve() as Line).Direction.IsParallelTo(XYZ.BasisZ));
|
||||
var spks = Document.ActiveView.OfClass<FamilyInstance>().OfCategory(BuiltInCategory.OST_Sprinklers).Where(e => e.GetConnectors(true).Size == 1);
|
||||
|
||||
Document.Invoke(
|
||||
ts =>
|
||||
{
|
||||
foreach (var ins in spks)
|
||||
{
|
||||
//Element instance = null;
|
||||
var conn1 = ins.GetConnectors(true).OfType<Connector>().FirstOrDefault();
|
||||
foreach (var p in pipes)
|
||||
{
|
||||
var conn = p.GetConnectors(true).OfType<Connector>().FirstOrDefault();
|
||||
if (conn.Origin.IsAlmostEqualTo(conn1.Origin))
|
||||
{
|
||||
conn.ConnectTo(conn1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//try
|
||||
//{
|
||||
// var connector = ins.GetConnectors(true).OfType<Connector>().FirstOrDefault();
|
||||
// var connector1 = instance.GetConnectors(true).OfType<Connector>().FirstOrDefault();
|
||||
// var id = ElementTransformUtils.CopyElement(Document, pipe.Id, XYZ.Zero).FirstOrDefault();
|
||||
// Document.Regenerate();
|
||||
// connector.ConnectTo(newPipe.ConnectorManager.Connectors.GetNearestConnector(connector.Origin));
|
||||
// connector1.ConnectTo(newPipe.ConnectorManager.Connectors.GetNearestConnector(connector1.Origin));
|
||||
//}
|
||||
//catch (Exception)
|
||||
//{
|
||||
// continue;
|
||||
//}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void ConnectSprinklers()
|
||||
{
|
||||
var fittings = Document.ActiveView.OfClass<FamilyInstance>().OfCategory(BuiltInCategory.OST_PipeFitting).Where(e => e.GetConnectors(true).Size == 1);
|
||||
var spks = Document.ActiveView.OfClass<FamilyInstance>().OfCategory(BuiltInCategory.OST_Sprinklers).Where(e => e.GetConnectors(true).Size == 1);
|
||||
var refer = UiDocument.Selection.PickObject(ObjectType.Element);
|
||||
var pipe = Document.GetElement(refer) as Pipe;
|
||||
Document.Invoke(
|
||||
ts =>
|
||||
{
|
||||
foreach (var ins in spks)
|
||||
{
|
||||
var temp = double.MaxValue;
|
||||
Element instance = null;
|
||||
foreach (var ins1 in fittings)
|
||||
{
|
||||
if (ins.Id == ins1.Id)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var current = ins.GetLocXYZ().DistanceTo(ins1.GetLocXYZ());
|
||||
if (current < temp && Math.Abs(current - Math.Abs(ins.GetLocXYZ().Z - ins1.GetLocXYZ().Z)) < 10E-5)
|
||||
{
|
||||
temp = current;
|
||||
instance = ins1;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
var connector = ins.GetConnectors(true).OfType<Connector>().FirstOrDefault();
|
||||
var connector1 = instance.GetConnectors(true).OfType<Connector>().FirstOrDefault();
|
||||
var id = ElementTransformUtils.CopyElement(Document, pipe.Id, XYZ.Zero).FirstOrDefault();
|
||||
var newPipe = Document.GetElement(id) as Pipe;
|
||||
newPipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM).SetValueString("15");
|
||||
(newPipe.Location as LocationCurve).Curve = Line.CreateBound(connector.Origin, connector1.Origin);
|
||||
Document.Regenerate();
|
||||
connector.ConnectTo(newPipe.ConnectorManager.Connectors.GetNearestConnector(connector.Origin));
|
||||
connector1.ConnectTo(newPipe.ConnectorManager.Connectors.GetNearestConnector(connector1.Origin));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void Method()
|
||||
{
|
||||
var elemIds = Document.OfClass<Pipe>().Cast<Pipe>().Where(p => p.Diameter == 50 / 304.8 && (p.GetCurve() as Line).Direction.IsParallelTo(XYZ.BasisZ)).Select(p => p.Id).ToList();
|
||||
//var elementIds = uidoc.Selection.GetElementIds();
|
||||
//var elementIds = new FilteredElementCollector(Document).OfClass(typeof(FamilyInstance)).Where(ins => ins.Name == "DN15").Select(ins => ins.Id).ToList();
|
||||
//using (var ts = new Transaction(Document, "Temp"))
|
||||
@@ -31,11 +151,11 @@ public class TempCmd : ExternalCommand
|
||||
//doc.Delete(elementIds);
|
||||
//foreach (var id in elementIds)
|
||||
//{
|
||||
// var elem = Document.GetElement(id) as FamilyInstance;
|
||||
// var p = elem.GetLocXYZ();
|
||||
// //ElementTransformUtils.MoveElement(Document,id,-elem.HandOrientation*125/304.8);
|
||||
// var unUseSpk = Document.GetElement(id) as FamilyInstance;
|
||||
// var p = unUseSpk.GetLocXYZ();
|
||||
// //ElementTransformUtils.MoveElement(Document,id,-unUseSpk.HandOrientation*125/304.8);
|
||||
// //Document.Regenerate();
|
||||
// //ElementTransformUtils.MoveElement(Document, id,-elem.FacingOrientation*95/304.8);
|
||||
// //ElementTransformUtils.MoveElement(Document, id,-unUseSpk.FacingOrientation*95/304.8);
|
||||
// ElementTransformUtils.RotateElement(
|
||||
// Document,
|
||||
// id,
|
||||
@@ -43,14 +163,14 @@ public class TempCmd : ExternalCommand
|
||||
// Math.PI / 2);
|
||||
//}
|
||||
//内衬
|
||||
//var e = InsulationLiningBase.GetLiningIds(doc, elem.Id);
|
||||
//var e = InsulationLiningBase.GetLiningIds(doc, unUseSpk.Id);
|
||||
//保温
|
||||
//var p = InsulationLiningBase.GetInsulationIds(doc, elem.Id);
|
||||
//var p = InsulationLiningBase.GetInsulationIds(doc, unUseSpk.Id);
|
||||
//var uidoc = UiApplication.ActiveUIDocument;
|
||||
//var doc = uidoc.Document;
|
||||
//var reference = uidoc.Selection.PickObject(ObjectType.Element);
|
||||
//var elem = doc.GetElement(reference);
|
||||
//var id = InsulationLiningBase.GetInsulationIds(Document, elem.Id).FirstOrDefault();
|
||||
//var unUseSpk = doc.GetElement(reference);
|
||||
//var id = InsulationLiningBase.GetInsulationIds(Document, unUseSpk.Id).FirstOrDefault();
|
||||
// ts.Commit();
|
||||
//}
|
||||
Document.Invoke(
|
||||
@@ -58,20 +178,33 @@ public class TempCmd : ExternalCommand
|
||||
{
|
||||
try
|
||||
{
|
||||
UiDocument.Selection.SetElementIds(elemIds);
|
||||
//UiDocument.Selection.SetElementIds(elemIds);
|
||||
|
||||
//ElementTransformUtils.MoveElements(Document, elemIds, XYZ.BasisZ * 200 / 304.8);
|
||||
|
||||
//foreach (var elem in elems)
|
||||
//{
|
||||
// elem.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM).Set(50 / 304.8);
|
||||
//}
|
||||
foreach (var id in elemIds)
|
||||
{
|
||||
var e = Document.GetElement(id) as Pipe;
|
||||
if (e != null)
|
||||
{
|
||||
var b = e.GetCurve().GetEndPoint(0);
|
||||
if (b.Z == 0)
|
||||
{
|
||||
e.GetLocationCurve().Curve = Line.CreateBound(
|
||||
b + XYZ.BasisZ * 1800 / 304.8,
|
||||
e.GetCurve().GetEndPoint(1));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//unUseSpk.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM).Set(50 / 304.8);
|
||||
}
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
||||
{
|
||||
}
|
||||
}, "CMD");
|
||||
}
|
||||
|
||||
public class ArrangeElement
|
||||
{
|
||||
public XYZ Translation { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user