79 lines
2.5 KiB
C#
79 lines
2.5 KiB
C#
|
|
using Autodesk.Revit.Attributes;
|
|
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.UI;
|
|
|
|
using HYJig.Jig;
|
|
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Windows.Forms;
|
|
|
|
namespace HYJig
|
|
{
|
|
public class WindowHandle : IWin32Window
|
|
{
|
|
public WindowHandle(IntPtr h)
|
|
{
|
|
Handle = h;
|
|
}
|
|
|
|
public IntPtr Handle { get; }
|
|
|
|
}
|
|
[Regeneration(0)]
|
|
[Transaction(TransactionMode.Manual)]
|
|
public class JigLine : IExternalCommand
|
|
{
|
|
public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
|
|
{
|
|
UIDocument activeUIDocument = cmdData.Application.ActiveUIDocument;
|
|
ViewAssist.ViewValidating(activeUIDocument.Document, activeUIDocument.ActiveView);
|
|
Process currentProcess = Process.GetCurrentProcess();
|
|
IntPtr mainWindowHandle = currentProcess.MainWindowHandle;
|
|
WindowHandle windowHandle = new WindowHandle(mainWindowHandle);
|
|
LineJigForm lineJigForm = new LineJigForm();
|
|
lineJigForm.Show(windowHandle);
|
|
XLineJig xlineJig = new XLineJig(activeUIDocument, lineJigForm);
|
|
XYZ xyz = xlineJig.PickStartPoint("请确定直线起点:");
|
|
Result result;
|
|
if (xyz == null)
|
|
{
|
|
xlineJig.Dispose();
|
|
lineJigForm.Close();
|
|
result = 0;
|
|
}
|
|
else
|
|
{
|
|
xlineJig.SetPromptState(string.Empty, false, "3000", true);
|
|
xlineJig.DrawSize = true;
|
|
for (; ; )
|
|
{
|
|
XYZ xyz2 = xlineJig.PickEndPoint(xyz, "请确定风管终点:");
|
|
if (xyz2 == null)
|
|
{
|
|
break;
|
|
}
|
|
Transaction transaction = new Transaction(activeUIDocument.Document);
|
|
try
|
|
{
|
|
transaction.Start("CreateCurve");
|
|
Line line = Line.CreateBound(xyz, xyz2);
|
|
activeUIDocument.Document.Create.NewDetailCurve(activeUIDocument.ActiveView, line);
|
|
transaction.Commit();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
transaction.RollBack();
|
|
}
|
|
xyz = xyz2;
|
|
}
|
|
xlineJig.Dispose();
|
|
lineJigForm.Close();
|
|
result = 0;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|