I was trying to get some of the examples from the Revit API Help to work with the Sharp Development version included with Revit 2015.
I got the "hello world" message box to work, but I got stuck after that.
If I go to the Macros in Revit, and create a new module, and create a new Macro under that, I can't figure out how to add the code from the "Retrieve Selected Elements" example.
Can anyone offer some insight into what I need to do to make these examples work? The examples all seem to make a IExternalCommand or IExternalApplication interface. That doesn't seem to work with Sharp. And I'm not sure what to do with the extra code Sharp creates.
For example, I was trying to get this to work:
Code:
[Autodesk.Revit.Attributes.Transaction(TransactionMode.ReadOnly)]
public class Document_Selection : IExternalCommand
{
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
ref string message, ElementSet elements)
{
try
{
// Select some elements in Revit before invoking this command
// Get the handle of current document.
UIDocument uidoc = commandData.Application.ActiveUIDocument;
// Get the element selection of current document.
Selection selection = uidoc.Selection;
ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
if (0 == selectedIds.Count)
{
// If no elements selected.
TaskDialog.Show("Revit","You haven't selected any elements.");
}
else
{
String info = "Ids of selected elements in the document are: ";
foreach (ElementId id in selectedIds)
{
info += "\n\t" + id.IntegerValue;
}
TaskDialog.Show("Revit",info);
}
}
catch (Exception e)
{
message = e.Message;
return Autodesk.Revit.UI.Result.Failed;
}
return Autodesk.Revit.UI.Result.Succeeded;
}
/// </ExampleMethod>
}
But sharp already has a class definition that looks like this:
Code:
public partial class ThisApplication
and another that looks like this:
Code:
public void Document_Selection()
My application fails when I try to build it with the error "The name commanddata does not exist in the current context (CS103)"