public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; IntPtr hwnd = uiapp.MainWindowHandle; FilteredElementCollector rooms = new FilteredElementCollector(doc) .OfClass(typeof(SpatialElement)) .OfCategory(BuiltInCategory.OST_Rooms); foreach (Room room in rooms) { CmdUploadRooms.UploadRoom(hwnd, doc, room); } DbUpdater.SetLastSequence(); return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { if (!App.Subscribed && -1 == DbUpdater.LastSequence) { DbUpdater.SetLastSequence(); } DbUpdater.ToggleSubscription( commandData.Application); return(Result.Succeeded); }
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; if( null == doc ) { Util.ErrorMsg( "Please run this command in a valid" + " Revit project document." ); return Result.Failed; } if( -1 == DbUpdater.LastSequence ) { DbUpdater.SetLastSequence(); return Result.Succeeded; } //// Retrieve all room unique ids in model: //FilteredElementCollector rooms // = new FilteredElementCollector( doc ) // .OfClass( typeof( SpatialElement ) ) // .OfCategory( BuiltInCategory.OST_Rooms ); //IEnumerable<string> roomUniqueIds // = rooms.Select<Element, string>( // e => e.UniqueId ); ////string ids = "?keys=[%22" + string.Join( //// "%22,%22", roomUniqueIds ) + "%22]"; //// Retrieve furniture transformations //// after last sequence number: //CouchDatabase db = new RoomEditorDb().Db; //ChangeOptions opt = new ChangeOptions(); //opt.IncludeDocs = true; //opt.Since = LastSequence; //opt.View = "roomedit/map_room_to_furniture"; //// I tried to add a filter to this view, but //// that is apparently not supported by the //// CouchDB or DreamSeat GetChanges functionality. ////+ ids; // failed attempt to filter view by room id keys //// Specify filter function defined in //// design document to get updates ////opt.Filter = //CouchChanges<DbFurniture> changes // = db.GetChanges<DbFurniture>( opt ); //CouchChangeResult<DbFurniture>[] results // = changes.Results; //DbUpdater updater = new DbUpdater( // doc, roomUniqueIds ); //foreach( CouchChangeResult<DbFurniture> result // in results ) //{ // updater.UpdateBimFurniture( result.Doc ); // LastSequence = result.Sequence; //} //DbUpdater updater = new DbUpdater( doc ); DbUpdater updater = new DbUpdater( uiapp ); updater.UpdateBim(); return Result.Succeeded; }
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; if (null == doc) { Util.ErrorMsg("Please run this command in a valid" + " Revit project document."); return(Result.Failed); } // Iterate over all pre-selected rooms Selection sel = uidoc.Selection; ICollection <ElementId> ids = sel.GetElementIds(); if (0 < ids.Count) { foreach (ElementId id in ids) { if (!(doc.GetElement(id) is Room)) { Util.ErrorMsg("Please pre-select only room" + " elements before running this command."); return(Result.Failed); } } } // If no rooms were pre-selected, // prompt for post-selection if (null == ids || 0 == ids.Count) { IList <Reference> refs = null; try { refs = sel.PickObjects(ObjectType.Element, new RoomSelectionFilter(), "Please select rooms."); } catch (Autodesk.Revit.Exceptions .OperationCanceledException) { return(Result.Cancelled); } ids = new List <ElementId>( refs.Select <Reference, ElementId>( r => r.ElementId)); } // Upload selected rooms to cloud database foreach (ElementId id in ids) { UploadRoom(doc, doc.GetElement(id) as Room); } DbUpdater.SetLastSequence(); return(Result.Succeeded); }
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; //IWin32Window revit_window // = new JtWindowHandle( // ComponentManager.ApplicationWindow ); // pre-2020 IWin32Window revit_window = new JtWindowHandle(uiapp.MainWindowHandle); // 2020 if (null == doc) { Util.ErrorMsg("Please run this command in a valid" + " Revit project document."); return(Result.Failed); } // Interactive sheet selection. FrmSelectSheets form = new FrmSelectSheets(doc); if (DialogResult.OK == form.ShowDialog( revit_window)) { List <ViewSheet> sheets = form.GetSelectedSheets(); int n = sheets.Count; string caption = Util.PluralString( n, "Sheet") + " Selected"; string msg = string.Join(", ", sheets.Select <Element, string>( e => Util.SheetDescription(e))) + "."; // Determine all floor plan views displayed // in the selected sheets. Dictionary <View, int> views = new Dictionary <View, int>( new ElementEqualityComparer()); int nFloorPlans = 0; foreach (ViewSheet sheet in sheets) { foreach (View v in sheet.GetAllPlacedViews() .Select <ElementId, View>(id => doc.GetElement(id) as View)) { if (!views.ContainsKey(v)) { if (IsFloorPlan(v)) { ++nFloorPlans; } views.Add(v, 0); } ++views[v]; } } msg += (1 == n) ? "\nIt contains" : "\nThey contain"; n = views.Count; msg += string.Format( " {0} including {1}: ", Util.PluralString(n, "view"), Util.PluralString(nFloorPlans, "floor plan")); msg += string.Join(", ", views.Keys.Select <Element, string>( e => e.Name)) + "."; Util.InfoMsg2(caption, msg, false); // Determine all categories occurring // in the views displayed by the sheets. List <Category> categories = new List <Category>( new CategoryCollector(views.Keys).Keys); // Sort categories alphabetically by name // to display them in selection form. categories.Sort( delegate(Category c1, Category c2) { return(string.Compare(c1.Name, c2.Name)); }); // Interactive category selection. FrmSelectCategories form2 = new FrmSelectCategories(categories); if (DialogResult.OK == form2.ShowDialog( revit_window)) { categories = form2.GetSelectedCategories(); n = categories.Count; caption = Util.PluralString(n, "Category") + " Selected"; msg = string.Join(", ", categories.Select <Category, string>( e => e.Name)) + "."; Util.InfoMsg2(caption, msg, false); // Convert category list to a dictionary for // more effective repeated lookup. // //Dictionary<ElementId, Category> catLookup = // categories.ToDictionary<Category, ElementId>( // c => c.Id ); // // No, much better: set up a reusable element // filter for the categories of interest: ElementFilter categoryFilter = new LogicalOrFilter(categories .Select <Category, ElementCategoryFilter>( c => new ElementCategoryFilter(c.Id)) .ToList <ElementFilter>()); // Instantiate a container for all // cloud data repository content. SheetModelCollections modelCollections = new SheetModelCollections( DbUpload.GetProjectInfo(doc).Id); foreach (ViewSheet sheet in sheets) { // Define preview form caption. caption = "Sheet and Viewport Loops - " + Util.SheetDescription(sheet); // This is currently not used for anything. ListSheetAndViewTransforms(sheet); // Determine the polygon loops representing // the size and location of given sheet and // the viewports it contains. JtLoops sheetViewportLoops = GetSheetViewportLoops( modelCollections, sheet); // Determine graphics for family instances, // their symbols and other BIM parts. GetBimGraphics(modelCollections, sheet, categoryFilter); // Display sheet and viewports with the // geometry retrieved in a temporary GeoSnoop // form generated on the fly for debugging // purposes. Bitmap bmp = GeoSnoop.DisplaySheet( sheet.Id, sheetViewportLoops, modelCollections); GeoSnoop.DisplayImageInForm( revit_window, caption, false, bmp); // Upload data to the cloud database. DbUpload.DbUploadSheet(sheet, sheetViewportLoops, modelCollections); } DbUpdater.SetLastSequence(); } } return(Result.Succeeded); }
/// <summary> /// Wait far a moment before requerying database. /// </summary> //static Stopwatch _stopwatch = null; void OnIdling( object sender, IdlingEventArgs ea) { using (JtTimer pt = new JtTimer("OnIdling")) { // Use with care! This loads the CPU: ea.SetRaiseWithoutDelay(); ++_counter; if (0 == (_counter % _update_interval)) { if (0 == (_counter % _message_interval)) { Util.Log(string.Format( "OnIdling called {0} times", _counter)); } // Have we waited long enough since the last attempt? //if( null == _stopwatch // || _stopwatch.ElapsedMilliseconds > 500 ) RoomEditorDb rdb = new RoomEditorDb(); //int n = rdb.LastSequenceNumber; if (rdb.LastSequenceNumberChanged( DbUpdater.LastSequence)) { UIApplication uiapp = sender as UIApplication; Document doc = uiapp.ActiveUIDocument.Document; Util.Log("furniture update begin"); //FilteredElementCollector rooms // = new FilteredElementCollector( doc ) // .OfClass( typeof( SpatialElement ) ) // .OfCategory( BuiltInCategory.OST_Rooms ); //IEnumerable<string> roomUniqueIds // = rooms.Select<Element, string>( // e => e.UniqueId ); //CouchDatabase db = rdb.Db; //ChangeOptions opt = new ChangeOptions(); //opt.IncludeDocs = true; //opt.Since = CmdUpdate.LastSequence; //opt.View = "roomedit/map_room_to_furniture"; //CouchChanges<DbFurniture> changes // = db.GetChanges<DbFurniture>( opt ); //CouchChangeResult<DbFurniture>[] results // = changes.Results; //DbUpdater updater = new DbUpdater( // doc, roomUniqueIds ); //foreach( CouchChangeResult<DbFurniture> result // in results ) //{ // updater.UpdateBimFurniture( result.Doc ); // CmdUpdate.LastSequence = result.Sequence; //} DbUpdater updater = new DbUpdater(uiapp); updater.UpdateBim(); Util.Log("furniture update end"); // _stopwatch = new Stopwatch(); // _stopwatch.Start(); //} //catch( Exception ex ) //{ // //uiapp.Application.WriteJournalComment // Debug.Print( // "Room Editor: an error occurred " // + "executing the OnIdling event:\r\n" // + ex.ToString() ); // Debug.WriteLine( ex ); //} } } } }
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; if (null == doc) { Util.ErrorMsg("Please run this command in a valid" + " Revit project document."); return(Result.Failed); } if (-1 == DbUpdater.LastSequence) { DbUpdater.SetLastSequence(); return(Result.Succeeded); } //// Retrieve all room unique ids in model: //FilteredElementCollector rooms // = new FilteredElementCollector( doc ) // .OfClass( typeof( SpatialElement ) ) // .OfCategory( BuiltInCategory.OST_Rooms ); //IEnumerable<string> roomUniqueIds // = rooms.Select<Element, string>( // e => e.UniqueId ); ////string ids = "?keys=[%22" + string.Join( //// "%22,%22", roomUniqueIds ) + "%22]"; //// Retrieve furniture transformations //// after last sequence number: //CouchDatabase db = new RoomEditorDb().Db; //ChangeOptions opt = new ChangeOptions(); //opt.IncludeDocs = true; //opt.Since = LastSequence; //opt.View = "roomedit/map_room_to_furniture"; //// I tried to add a filter to this view, but //// that is apparently not supported by the //// CouchDB or DreamSeat GetChanges functionality. ////+ ids; // failed attempt to filter view by room id keys //// Specify filter function defined in //// design document to get updates ////opt.Filter = //CouchChanges<DbFurniture> changes // = db.GetChanges<DbFurniture>( opt ); //CouchChangeResult<DbFurniture>[] results // = changes.Results; //DbUpdater updater = new DbUpdater( // doc, roomUniqueIds ); //foreach( CouchChangeResult<DbFurniture> result // in results ) //{ // updater.UpdateBimFurniture( result.Doc ); // LastSequence = result.Sequence; //} //DbUpdater updater = new DbUpdater( doc ); DbUpdater updater = new DbUpdater(uiapp); updater.UpdateBim(); return(Result.Succeeded); }
/// <summary> /// Wait far a moment before requerying database. /// </summary> //static Stopwatch _stopwatch = null; void OnIdling( object sender, IdlingEventArgs ea ) { using( JtTimer pt = new JtTimer( "OnIdling" ) ) { // Use with care! This loads the CPU: ea.SetRaiseWithoutDelay(); ++_counter; if( 0 == ( _counter % _update_interval ) ) { if( 0 == ( _counter % _message_interval ) ) { Util.Log( string.Format( "OnIdling called {0} times", _counter ) ); } // Have we waited long enough since the last attempt? //if( null == _stopwatch // || _stopwatch.ElapsedMilliseconds > 500 ) RoomEditorDb rdb = new RoomEditorDb(); //int n = rdb.LastSequenceNumber; if( rdb.LastSequenceNumberChanged( DbUpdater.LastSequence ) ) { UIApplication uiapp = sender as UIApplication; Document doc = uiapp.ActiveUIDocument.Document; Util.Log( "furniture update begin" ); //FilteredElementCollector rooms // = new FilteredElementCollector( doc ) // .OfClass( typeof( SpatialElement ) ) // .OfCategory( BuiltInCategory.OST_Rooms ); //IEnumerable<string> roomUniqueIds // = rooms.Select<Element, string>( // e => e.UniqueId ); //CouchDatabase db = rdb.Db; //ChangeOptions opt = new ChangeOptions(); //opt.IncludeDocs = true; //opt.Since = CmdUpdate.LastSequence; //opt.View = "roomedit/map_room_to_furniture"; //CouchChanges<DbFurniture> changes // = db.GetChanges<DbFurniture>( opt ); //CouchChangeResult<DbFurniture>[] results // = changes.Results; //DbUpdater updater = new DbUpdater( // doc, roomUniqueIds ); //foreach( CouchChangeResult<DbFurniture> result // in results ) //{ // updater.UpdateBimFurniture( result.Doc ); // CmdUpdate.LastSequence = result.Sequence; //} DbUpdater updater = new DbUpdater( uiapp ); updater.UpdateBim(); Util.Log( "furniture update end" ); // _stopwatch = new Stopwatch(); // _stopwatch.Start(); //} //catch( Exception ex ) //{ // //uiapp.Application.WriteJournalComment // Debug.Print( // "Room Editor: an error occurred " // + "executing the OnIdling event:\r\n" // + ex.ToString() ); // Debug.WriteLine( ex ); //} } } } }