160 lines
5.7 KiB
C#
160 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Autodesk.Revit;
|
|
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.UI;
|
|
using KMBIM.Revit.Tools;
|
|
using Autodesk.Revit.UI.Selection;
|
|
using System.Windows.Forms;
|
|
using Autodesk.Revit.DB.Mechanical;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using KMBIM.Revit.Tools.Utils;
|
|
using Autodesk.Revit.DB.Plumbing;
|
|
using KMBIM.Utils;
|
|
|
|
namespace KMBIM
|
|
{
|
|
/// <summary>
|
|
/// Implements interface IExternalCommand of Revit API.
|
|
/// </summary>
|
|
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
|
|
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
|
|
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
|
|
public class PipeConnectionCmd : IExternalCommand
|
|
{
|
|
UIApplication m_pUIApp;
|
|
System.Drawing.Point m_pt1, m_pt2 = System.Drawing.Point.Empty;
|
|
|
|
void DrawTask(System.Threading.CancellationToken ct)
|
|
{
|
|
while (!ct.IsCancellationRequested)
|
|
{
|
|
m_pt2 = Cursor.Position;
|
|
if (m_pt2.X < m_pUIApp.DrawingAreaExtents.Left + 2 ||
|
|
m_pt2.X > m_pUIApp.DrawingAreaExtents.Right - 20 ||
|
|
m_pt2.Y > m_pUIApp.DrawingAreaExtents.Bottom - 20 ||
|
|
m_pt2.Y < m_pUIApp.DrawingAreaExtents.Top + 2)
|
|
{
|
|
System.Threading.Thread.Sleep(20);
|
|
continue;
|
|
}
|
|
if (m_pt1 != System.Drawing.Point.Empty)
|
|
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
|
|
{
|
|
g.DrawLine(Pens.Black, m_pt1, m_pt2);
|
|
}
|
|
System.Threading.Thread.Sleep(20);
|
|
}
|
|
}
|
|
|
|
|
|
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
|
|
{
|
|
try
|
|
{
|
|
if (!WorkMain.GetInstance().IsValid) return Autodesk.Revit.UI.Result.Succeeded;
|
|
m_pUIApp = commandData.Application;
|
|
UIDocument uidoc = m_pUIApp.ActiveUIDocument;
|
|
Document doc = uidoc.Document;
|
|
|
|
Selection sel1 = uidoc.Selection;
|
|
List<XYZ> tempXYZ = new List<XYZ>(1);
|
|
|
|
|
|
Element baseElement = null;
|
|
Reference refPipe1 = null;
|
|
try
|
|
{
|
|
refPipe1 = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "기준 커넥터 선택 :");
|
|
if (refPipe1 == null) return Result.Cancelled;
|
|
baseElement = uidoc.Document.GetElement(refPipe1);
|
|
}
|
|
catch (Exception) { }
|
|
|
|
if (baseElement == null) return Result.Failed;
|
|
|
|
Element targetElement = null;
|
|
Reference refPipe2 = null;
|
|
try
|
|
{
|
|
refPipe2 = m_pUIApp.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "대상 커넥터 선택 :");
|
|
if (refPipe2 == null) return Result.Cancelled;
|
|
targetElement = m_pUIApp.ActiveUIDocument.Document.GetElement(refPipe2);
|
|
}
|
|
catch (Exception) { }
|
|
|
|
if (targetElement == null) return Result.Failed;
|
|
|
|
XYZ pick1 = refPipe1.GlobalPoint;
|
|
XYZ pick2 = refPipe2.GlobalPoint;
|
|
|
|
App.thisApp.OpenFormPipeConnector(m_pUIApp);
|
|
var wfPipeConnector = App.thisApp.m_wfPipeConnector;
|
|
wfPipeConnector.uidoc = m_pUIApp.ActiveUIDocument;
|
|
App.thisApp.ShowFormPipeConnector(m_pUIApp, baseElement, pick1, targetElement, pick2);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
return Result.Succeeded;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//선택한 개체를 필터링할 수 있는 인터페이스 구현(= An interface that provides the ability to filter objects during a selection operation)
|
|
public class PlanarFacesSelectionFilter : ISelectionFilter
|
|
{
|
|
Document doc = null;
|
|
public PlanarFacesSelectionFilter(Document document)
|
|
{
|
|
doc = document;
|
|
}
|
|
|
|
public bool AllowElement(Element elem)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public bool AllowReference(Reference reference, XYZ position)
|
|
{
|
|
if (doc.GetElement(reference).GetGeometryObjectFromReference(reference) is PlanarFace)
|
|
{ return true; }
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public List<Element> GetDuctLine(UIDocument uidoc, Document document)
|
|
{
|
|
ISelectionFilter selectionFilter = new PlanarFacesSelectionFilter(document);
|
|
List<Element> elementList = new List<Element>();
|
|
if (MessageBox.Show("Duct 생성하시려면 line 을 선택 후 \n좌측 하단의 Finsh 버튼을 클릭해주세요", "Duct 생성확인", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|
{
|
|
IList<Reference> references = uidoc.Selection.PickObjects(ObjectType.Element, selectionFilter, "Select Multiple planar faces");
|
|
foreach (Reference reference in references)
|
|
{
|
|
Element element = uidoc.Document.GetElement(reference);
|
|
elementList.Add(element);
|
|
}
|
|
}
|
|
|
|
return elementList;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
} |