Revit二次开发Selection.Elements报错
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
namespace NoteUser
{
public class NoteUser : IExternalCommand
{
public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
try
{
Document doc = commandData.Application.ActiveUIDocument.Document;
UIDocument uidoc = commandData.Application.ActiveUIDocument;
ICollection<Autodesk.Revit.DB.ElementId> ids = doc.Delete(uidoc.Selection.GetElementIds());
TaskDialog taskDialog = new TaskDialog("Revit");
taskDialog.MainContent = (
"点击是将返回成功,所选择的对象将被删除!\n" +
"点击否将返回失败,所选对象不会被删除!\n" +
"点击取消将返回取消,所选对象不会被删除!");
TaskDialogCommonButtons buttons = TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No | TaskDialogCommonButtons.Cancel;
taskDialog.CommonButtons = buttons;
TaskDialogResult taskDialogResult = taskDialog.Show();
if(taskDialogResult == TaskDialogResult.Yes)
{
return Autodesk.Revit.UI.Result.Succeeded;
}
else if(taskDialogResult == TaskDialogResult.No)
{
elements = uidoc.Selection.Elements; //此处报错,求解答???
message = "删除所选对象失败!";
return Autodesk.Revit.UI.Result.Failed;
}
else
{
return Autodesk.Revit.UI.Result.Cancelled;
}
}
catch
{
message = "Unexpected Exception thrown!";
return Autodesk.Revit.UI.Result.Failed;
}
}
}
}
页:
[1]