- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone!
I wrote an ExternalCommand that inserts components using the PostRequestForElementTypePlacement () method and I would like to get a list of the last components inserted.
Searching in the API documentation I checked that the method in question does not return the control to the API after the command is canceled by the user. Only the PromptForFamilyInstancePlacement () method runs within the context of the API, but it does not solve my problem because I need to adjust the insert options before inserting the component into the project.
The PromptForFamilyInstancePlacement () method has an overload where it allows you to use an object of class PromptForFamilyInstancePlacementOptions but, unfortunately, this class has no member that allows us to adjust the insert options.
In summary, the PostRequestForElementTypePlacement () method is the most appropriate method for my application and is only missing a way to get a list of the last components inserted.
I thought about implementing the DocumentChanged event as shown in the code below, but it is not working. See the comments bellow in red. What can you suggest me in this case?
I also saw in the documentation a method called PostCommand (). This method allows, if I understood correctly, to call a command from Revit and after the command is terminated by the user to return the process control to the application. Can I use this method together with PostRequestForElementTypePlacement () in some way to solve my problem?
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class DharmaCmdInserirComponente : IExternalCommand
{
List<ElementId> _added_element_ids = new List<ElementId>();
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
Document doc = uidoc.Document;
FilteredElementCollector collector
= new FilteredElementCollector(doc);
collector.OfCategory(BuiltInCategory.OST_Doors);
collector.OfClass(typeof(FamilySymbol));
FamilySymbol symbol = collector.FirstElement() as FamilySymbol;
_added_element_ids.Clear();
app.DocumentChanged += new EventHandler<DocumentChangedEventArgs>(myDocumentChanged);
//IN THIS POINT THE API PASSES THE CONTROL TO THE REVIT FOR THE USER INSERT THE COMPONENTS
//BUT WHEN THE USER PRESSES ESC TWICE, THE CONTROL DOES NOT RETURN TO APPLICATION
uidoc.PostRequestForElementTypePlacement(symbol);
//IN PRACTICE, THIS CODE IS EXECUTED. BUT BEFORE THE METHOD PostRequestForElementTypePlacement
app.DocumentChanged -= new EventHandler<DocumentChangedEventArgs>(myDocumentChanged);
int n = _added_element_ids.Count;
//Contagem dos últimos components inseridos
TaskDialog.Show( "Número de componentes inseridos",
string.Format( "{0} components {1} adicionados.", n, ((1 == n) ? "" : "s")));
return Result.Succeeded;
}
void myDocumentChanged(object sender, DocumentChangedEventArgs e)
{
added_element_ids.AddRange(e.GetAddedElementIds());
}
}
Solved! Go to Solution.