public void Execute(UIApplication uiapp) { Document doc = uiapp.ActiveUIDocument.Document; Application app = uiapp.Application; UIDocument uidoc = uiapp.ActiveUIDocument; // Determine elements to export FilteredElementCollector collector = null; // Access current selection ICollection <ElementId> selectedIds = uidoc.Selection.GetElementIds(); if (0 < selectedIds.Count) { // If any elements were preselected, // export those to OBJ collector = new FilteredElementCollector(doc, selectedIds); } else { // If nothing was preselected, export // all model elements to OBJ collector = new FilteredElementCollector(doc); } collector.WhereElementIsNotElementType() .WhereElementIsViewIndependent(); if (null == _export_folder_name) { _export_folder_name = Path.GetTempPath(); } string filename = null; if (!FileSelect(_export_folder_name, out filename)) { return; } _export_folder_name = Path.GetDirectoryName(filename); ObjExporter exporter = new ObjExporter(); Options opt = app.Create.NewGeometryOptions(); ExportElements(exporter, collector, opt); exporter.ExportTo(filename); return; }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements ) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; // Determine elements to export FilteredElementCollector collector = null; // Access current selection SelElementSet set = uidoc.Selection.Elements; int n = set.Size; if( 0 < n ) { // If any elements were preselected, // export those to OBJ ICollection<ElementId> ids = set .Cast<Element>() .Select<Element, ElementId>( e => e.Id ) .ToArray<ElementId>(); collector = new FilteredElementCollector( doc, ids ); } else { // If nothing was preselected, export // all model elements to OBJ collector = new FilteredElementCollector( doc ); } collector.WhereElementIsNotElementType() .WhereElementIsViewIndependent(); if( null == _export_folder_name ) { _export_folder_name = Path.GetTempPath(); } string filename = null; if( !FileSelect( _export_folder_name, out filename ) ) { return Result.Cancelled; } _export_folder_name = Path.GetDirectoryName( filename ); ObjExporter exporter = new ObjExporter(); Options opt = app.Create.NewGeometryOptions(); ExportElements( exporter, collector, opt ); exporter.ExportTo( filename ); return Result.Succeeded; }