Message 1 of 5
Calling IExternalCommand from WPF button
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello. I have the class SaveSectionBoxInfo in the IExternalCommand interface. I want to call it through button in the WPF form. There is error CS1729 'ExternalCommandData' does not contain a constructor that takes 0 arguments (marked by comment). I can't find the right argument for 'ExternalCommandData'. How can I do it properly? And is it correct to use the IExternalCommand interface in this case? Thanks for your answers.
WPF:
public partial class BbWPF : Window
{
private readonly UIApplication _uiApp;
public BbWPF(UIApplication uiApp)
{
InitializeComponent();
_uiApp = uiApp;
}
public ExternalCommandData commandData { get; set; }
private void BbWPFsavePos_Click(object sender, RoutedEventArgs e)
{
SaveSectionBoxInfo command = new SaveSectionBoxInfo();
// here CS1729 'ExternalCommandData' does not contain a constructor that takes 0 arguments
ExternalCommandData commandData = new ExternalCommandData();
//
string message = string.Empty;
ElementSet elements = new ElementSet();
Result result = command.Execute(commandData, ref message, elements);
}
Class:
[Transaction(TransactionMode.Manual)]
public class BoxMenu : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
BbWPF window = new BbWPF(uiApp);
window.ShowDialog();
return Result.Succeeded;
}
}
public class SaveSectionBoxInfo : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
View3D view3D = doc.ActiveView as View3D;
if (view3D != null && view3D.IsSectionBoxActive)
{
BoundingBoxXYZ sectionBox = view3D.GetSectionBox();
XYZ min = sectionBox.Min;
XYZ max = sectionBox.Max;
XYZ center = (min + max) / 2;
XYZ size = max - min;
TaskDialog.Show("Coords:", $"Center: {center}\nSize: {size}");
}
else
{
TaskDialog.Show("Error", "Error");
}
return Result.Succeeded;
}
}