添加项目文件。
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WPFMonitorProgress.Models
|
||||
{
|
||||
class ChangeParameterModeless
|
||||
{
|
||||
Wall CurrentWall { get; set; }
|
||||
ExternalEvent ExternalEvent { get; set; }
|
||||
|
||||
public ChangeParameterModeless(Element wallElement)
|
||||
{
|
||||
CurrentWall = wallElement as Wall;
|
||||
}
|
||||
|
||||
internal void ProgressModeless()
|
||||
{
|
||||
|
||||
if (CurrentWall == null)
|
||||
throw new Exception("Selected Element is not a wall");
|
||||
|
||||
Views.ProgressMonitorView currentUI = new Views.ProgressMonitorView();
|
||||
|
||||
Events.ProcessEventHandler progressEventHandler = new Events.ProcessEventHandler();
|
||||
progressEventHandler.CurrentWall = CurrentWall;
|
||||
progressEventHandler.CurrentUI = currentUI;
|
||||
Controls.ProgressMonitorControl currentControl = new Controls.ProgressMonitorControl();
|
||||
currentControl.MaxValue = 200;
|
||||
progressEventHandler.CurrentControl = currentControl;
|
||||
|
||||
ExternalEvent = ExternalEvent.Create(progressEventHandler);
|
||||
|
||||
currentUI.DataContext = currentControl;
|
||||
currentUI.ContentRendered += CurrentUI_ContentRendered;
|
||||
currentUI.Topmost = true;
|
||||
currentUI.Show();
|
||||
}
|
||||
|
||||
private void CurrentUI_ContentRendered(object sender, EventArgs e)
|
||||
{
|
||||
ExternalEvent.Raise();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using Autodesk.Revit.UI;
|
||||
using System;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
namespace WPFMonitorProgress.Commands
|
||||
{
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
class ExternalEventMode : IExternalCommand
|
||||
{
|
||||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
||||
{
|
||||
UIDocument uidoc = commandData.Application.ActiveUIDocument;
|
||||
Selection sel = uidoc.Selection;
|
||||
|
||||
try
|
||||
{
|
||||
Reference refer = sel.PickObject(ObjectType.Element, "Select a Wall");
|
||||
Models.ChangeParameterModeless model = new Models.ChangeParameterModeless(uidoc.Document.GetElement(refer));
|
||||
|
||||
model.ProgressModeless();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (!(e is Autodesk.Revit.Exceptions.OperationCanceledException))
|
||||
{
|
||||
message = e.Message;
|
||||
return Result.Failed;
|
||||
}
|
||||
}
|
||||
return Result.Succeeded;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace WPFMonitorProgress.Events
|
||||
{
|
||||
class ProcessEventHandler : IExternalEventHandler
|
||||
{
|
||||
public Views.ProgressMonitorView CurrentUI { get; set; }
|
||||
public Controls.ProgressMonitorControl CurrentControl { get; set; }
|
||||
public Wall CurrentWall { get; set; }
|
||||
bool Cancel = false;
|
||||
|
||||
private delegate void ProgressBarDelegate();
|
||||
|
||||
public void Execute(UIApplication app)
|
||||
{
|
||||
if (app == null)
|
||||
{
|
||||
CloseWindow();
|
||||
return;
|
||||
}
|
||||
|
||||
if (app.ActiveUIDocument == null)
|
||||
return;
|
||||
|
||||
if (app.ActiveUIDocument.Document == null)
|
||||
return;
|
||||
|
||||
if (CurrentWall == null)
|
||||
return;
|
||||
|
||||
if (CurrentUI == null)
|
||||
return;
|
||||
|
||||
if (CurrentControl == null)
|
||||
return;
|
||||
|
||||
Parameter parameter = CurrentWall.get_Parameter(BuiltInParameter.DOOR_NUMBER);
|
||||
if (parameter.IsReadOnly)
|
||||
{
|
||||
CloseWindow();
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentUI.btnCancel.Click += CurrentUI_Closed;
|
||||
|
||||
using (Transaction t = new Transaction(CurrentWall.Document, "Process"))
|
||||
{
|
||||
t.Start();
|
||||
for (CurrentControl.CurrentValue = 0; CurrentControl.CurrentValue <= CurrentControl.MaxValue; ++CurrentControl.CurrentValue)
|
||||
{
|
||||
if (Cancel)
|
||||
break;
|
||||
|
||||
System.Threading.Thread.Sleep(50);
|
||||
|
||||
try
|
||||
{
|
||||
parameter.Set(CurrentControl.CurrentValue.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
CloseWindow();
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentControl.CurrentContext = string.Format("progress {0} of {1} done", CurrentControl.CurrentValue, CurrentControl.MaxValue);
|
||||
CurrentUI.Dispatcher.Invoke(new ProgressBarDelegate(CurrentControl.NotifyUI), System.Windows.Threading.DispatcherPriority.Background);
|
||||
|
||||
}
|
||||
t.Commit();
|
||||
|
||||
CloseWindow();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void CloseWindow()
|
||||
{
|
||||
CurrentUI.Closed -= CurrentUI_Closed;
|
||||
CurrentUI.Close();
|
||||
}
|
||||
|
||||
private void CurrentUI_Closed(object sender, EventArgs e)
|
||||
{
|
||||
Cancel = true;
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return "ProgressMonitor";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user