- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
I want to use the Revit PostCommand through a button that is in a window (ShowDialog), because I want to keep Revit locked. But the problem is that the PostCommand only launches when my form is closed.
I had already done this using a While:
I create the form
I give him the datacontext
I am using a CommandToRun property on my ViewModel to determine what to do.
At the click of a button, I change my CommandToRun property and I close the form.
And then I determine whether or not to quit the while.
But the problem here is that the postcommand does not launch, because I open a form directly after clicking on the button.
public bool? ShowSeparationByZoneModalForm()
{
bool? res = null;
Boolean reallyExit = false;
while (!reallyExit)
{
// form.PopulateFormData();
if (viewModel.CommandToRun == RunCommand.None)
{
SeparationByZoneDialog form = new SeparationByZoneDialog();
form.Helper().Owner = RevitWindowHelper.GetRevitHandle();
form.DataContext = viewModel;
res = form.ShowDialog();
switch (viewModel.CommandToRun)
{
case RunCommand.DrawLines:
{
App.DocumentChanged += OnDocumentChanged;
UIApp.Idling += OnIdling;
RevitCommandId modelLineCmd = RevitCommandId.LookupPostableCommandId(PostableCommand.ModelLine);
UIApp.PostCommand(modelLineCmd);
}
break;
case RunCommand.SelectLines:
{
viewModel.CommandToRun = RunCommand.None;
var uidoc = new UIDocument(_doc);
Selection choices = uidoc.Selection;
try
{
Reference hasPickOne = choices.PickObject(ObjectType.Element);
if (hasPickOne != null)
viewModel.LineCounter += 1;
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException oce)
{ }
}
break;
case RunCommand.None:
reallyExit = true;
break;
default:
reallyExit = true;
break;
}
}
}
return res;
}
This method works great for making element selections in Revit keeping the window blocking but with postcommands it doesn't work.
Solved! Go to Solution.