更新
This commit is contained in:
@@ -1,22 +1,68 @@
|
||||
using Autodesk.Revit.Attributes;
|
||||
using System.Windows;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Plumbing;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
using ShrlAlgoToolkit.Revit.Assists;
|
||||
using ShrlAlgoToolkit.Revit.Extensions;
|
||||
|
||||
|
||||
namespace ShrlAlgo.Addin.Test;
|
||||
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
public class TempCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
CreateWindow win = new CreateWindow();
|
||||
win.Show();
|
||||
var refer = UiDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
|
||||
var element = Document.GetElement(refer);
|
||||
Document.Invoke(
|
||||
_ =>
|
||||
{
|
||||
ElementTransformUtils.MoveElement(Document, element.Id, XYZ.BasisY * 200 / 304.8);
|
||||
});
|
||||
#if false
|
||||
var geo = element.get_Geometry(new Options() { ComputeReferences = true, DetailLevel = ViewDetailLevel.Fine });
|
||||
if (Document.IsFamilyDocument)
|
||||
{
|
||||
Solid solid = null;
|
||||
var f = Document.OwnerFamily;
|
||||
foreach (var item in geo)
|
||||
{
|
||||
if (item is GeometryInstance instance)
|
||||
{
|
||||
foreach (var obj in instance.GetInstanceGeometry())
|
||||
{
|
||||
if (obj is Solid s)
|
||||
{
|
||||
if (solid == null)
|
||||
{
|
||||
solid = s;
|
||||
}
|
||||
if (s.Volume > solid.Volume)
|
||||
{
|
||||
solid = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Document.Invoke(
|
||||
ts =>
|
||||
{
|
||||
DirectShape directShape = DirectShape.CreateElement(Document, f.FamilyCategory.Id);
|
||||
directShape.SetShape(new GeometryObject[] { solid });
|
||||
});
|
||||
//MessageBox.Show(solid.Volume.ToString());
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
|
||||
//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);
|
||||
@@ -43,98 +89,113 @@ public class TempCmd : ExternalCommand
|
||||
// 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);
|
||||
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;
|
||||
//}
|
||||
|
||||
}
|
||||
});
|
||||
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 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;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
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 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"))
|
||||
@@ -194,6 +255,7 @@ public class TempCmd : ExternalCommand
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
||||
{
|
||||
}
|
||||
}, "CMD");
|
||||
},
|
||||
"CMD");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user