Message 1 of 10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So i was looking at Jeremy's sample post about modeless forms and was trying to modify one of the examples to do something other than flip the door. Here's my attempt and an issue it generated.
For some reason when I try to execute the DeleteViews() method which should be triggered by RequestId.TurnIn what happens is that both of the functions defined below get executed: DeleteSheets and DeleteViews.
Is there a way to assign separate function calls to each button?
Thanks!
// // (C) Copyright 2003-2015 by Autodesk, Inc. // // Permission to use, copy, modify, and distribute this software in // object code form for any purpose and without fee is hereby granted, // provided that the above copyright notice appears in all copies and // that both that copyright notice and the limited warranty and // restricted rights notice below appear in all supporting // documentation. // // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE // UNINTERRUPTED OR ERROR FREE. // // Use, duplication, or disclosure by the U.S. Government is subject to // restrictions set forth in FAR 52.227-19 (Commercial Computer // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) // (Rights in Technical Data and Computer Software), as applicable. // using System; using System.Collections.Generic; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using System.Linq; namespace Revit.SDK.Samples.ModelessForm_ExternalEvent.CS { /// <summary> /// A class with methods to execute requests made by the dialog user. /// </summary> /// public class RequestHandler : IExternalEventHandler { // A trivial delegate, but handy private delegate void DoorOperation(FamilyInstance e); // The value of the latest request made by the modeless form private Request m_request = new Request(); /// <summary> /// A public property to access the current request value /// </summary> public Request Request { get { return m_request; } } /// <summary> /// A method to identify this External Event Handler /// </summary> public String GetName() { return "R2014 External Event Sample"; } /// <summary> /// The top method of the event handler. /// </summary> /// <remarks> /// This is called by Revit after the corresponding /// external event was raised (by the modeless form) /// and Revit reached the time at which it could call /// the event's handler (i.e. this object) /// </remarks> /// public void Execute(UIApplication uiapp) { try { switch (Request.Take()) { case RequestId.None: { return; // no request at this time -> we can leave immediately } case RequestId.Delete: { DeleteSheets(uiapp, "Delete sheets"); //ModifySelectedDoors(uiapp, "Delete sheets", e => e.Document.Delete(e.Id)); break; } //case RequestId.FlipLeftRight: // { // ModifySelectedDoors(uiapp, "Flip door Hand", e => e.flipHand()); // break; // } //case RequestId.FlipInOut: // { // ModifySelectedDoors(uiapp, "Flip door Facing", e => e.flipFacing()); // break; // } //case RequestId.MakeLeft: // { // ModifySelectedDoors(uiapp, "Make door Left", MakeLeft); // break; // } //case RequestId.MakeRight: // { // ModifySelectedDoors(uiapp, "Make door Right", MakeRight); // break; // } //case RequestId.TurnOut: // { // ModifySelectedDoors(uiapp, "Place door Out", TurnOut); // break; // } case RequestId.TurnIn: { DeleteViews(uiapp, "Place door In"); break; } //case RequestId.Rotate: // { // ModifySelectedDoors(uiapp, "Rotate door", FlipHandAndFace); // break; // } default: { // some kind of a warning here should // notify us about an unexpected request break; } } } finally { Application.thisApp.WakeFormUp(); } return; } /// <summary> /// The main door-modification subroutine - called from every request /// </summary> /// <remarks> /// It searches the current selection for all doors /// and if it finds any it applies the requested operation to them /// </remarks> /// <param name="uiapp">The Revit application object</param> /// <param name="text">Caption of the transaction for the operation.</param> /// private void DeleteSheets(UIApplication uiapp, String text) { UIDocument uidoc = uiapp.ActiveUIDocument; if (uidoc != null) { ICollection<ElementId> allSheets = new FilteredElementCollector(uidoc.Document) .OfClass(typeof(ViewSheet)) .ToElementIds(); using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start(text) == TransactionStatus.Started) { foreach (ElementId id in allSheets) { uidoc.Document.Delete(id); } trans.Commit(); } } } } private void DeleteViews(UIApplication uiapp, String text) { UIDocument uidoc = uiapp.ActiveUIDocument; if (uidoc != null) { using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start(text) == TransactionStatus.Started) { try { View currentView = uidoc.ActiveView; List<ElementId> exclude = new List<ElementId>(); exclude.Add(currentView.Id); ExclusionFilter filter = new ExclusionFilter(exclude); IList<Element> collection = new FilteredElementCollector(uidoc.Document).OfClass(typeof(View)).WherePasses(filter).ToElements(); for (var i = 0; i < collection.Count; i++) { View v = collection[i] as View; if (v.Name == "Project View") { collection.RemoveAt(i); } } int x = 0; foreach (Element e in collection) { try { View view = e as View; // all views/sheets are deleted and increment counter by 1 uidoc.Document.Delete(view.Id); x += 1; } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } } trans.Commit(); TaskDialog.Show("DeleteAllSheetsViews", "Views & Sheets Deleted: " + x.ToString()); } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } } } } } ////////////////////////////////////////////////////////////////////////// // // Helpers - simple delegates operating upon an instance of a door private void FlipHandAndFace(FamilyInstance e) { e.flipFacing(); e.flipHand(); } // Note: The door orientation [left/right] is according the common // conventions used by the building industry in the Czech Republic. // If the convention is different in your county (like in the U.S), // swap the code of the MakeRight and MakeLeft methods. private static void MakeLeft(FamilyInstance e) { if (e.FacingFlipped ^ e.HandFlipped) e.flipHand(); } private void MakeRight(FamilyInstance e) { if (!(e.FacingFlipped ^ e.HandFlipped)) e.flipHand(); } // Note: The In|Out orientation depends on the position of the // wall the door is in; therefore it does not necessary indicates // the door is facing Inside, or Outside, respectively. // The presented implementation is good enough to demonstrate // how to flip a door, but the actual algorithm will likely // have to be changes in a read-world application. private void TurnIn(FamilyInstance e) { if (!e.FacingFlipped) e.flipFacing(); } private void TurnOut(FamilyInstance e) { if (e.FacingFlipped) e.flipFacing(); } } // class } // namespace
Solved! Go to Solution.