diff --git a/CS/App.cs b/CS/App.cs
index 888c4b7e7..25df7a948 100644
--- a/CS/App.cs
+++ b/CS/App.cs
@@ -35,83 +35,84 @@
namespace RevitLookup
{
- [Transaction( TransactionMode.Manual )]
- [Regeneration( RegenerationOption.Manual )]
- public class App : IExternalApplication
- {
- static AddInId m_appId = new AddInId( new Guid(
- "356CDA5A-E6C5-4c2f-A9EF-B3222116B8C8" ) );
-
- // get the absolute path of this assembly
- static string ExecutingAssemblyPath = System.Reflection.Assembly
- .GetExecutingAssembly().Location;
-
- private AppDocEvents m_appDocEvents;
-
- public Result OnStartup(
- UIControlledApplication application )
- {
-
- // Call this method explicitly in App.cs when Revit starts up because,
- // in .NET 4, the static variables will not be initialized until use them.
- Snoop.Collectors.CollectorObj.InitializeCollectors();
- AddMenu( application );
- AddAppDocEvents( application.ControlledApplication );
-
- return Result.Succeeded;
- }
-
- public Result OnShutdown(
- UIControlledApplication application )
- {
- RemoveAppDocEvents();
-
- return Result.Succeeded;
- }
-
- private void AddMenu( UIControlledApplication app )
- {
- RibbonPanel rvtRibbonPanel = app.CreateRibbonPanel( "Revit Lookup" );
- PulldownButtonData data = new PulldownButtonData( "Options", "Revit Lookup" );
-
- RibbonItem item = rvtRibbonPanel.AddItem( data );
- PulldownButton optionsBtn = item as PulldownButton;
-
- // Add Icons to main RevitLookup Menu
- optionsBtn.Image = GetEmbeddedImage("RevitLookup.Resources.RLookup-16.png");
- optionsBtn.LargeImage = GetEmbeddedImage("RevitLookup.Resources.RLookup-32.png");
-
- optionsBtn.AddPushButton( new PushButtonData( "HelloWorld", "Hello World...", ExecutingAssemblyPath, "RevitLookup.HelloWorld" ) );
- optionsBtn.AddPushButton( new PushButtonData( "Snoop Db..", "Snoop DB...", ExecutingAssemblyPath, "RevitLookup.CmdSnoopDb" ) );
- optionsBtn.AddPushButton( new PushButtonData( "Snoop Current Selection...", "Snoop Current Selection...", ExecutingAssemblyPath, "RevitLookup.CmdSnoopModScope" ) );
- optionsBtn.AddPushButton( new PushButtonData( "Snoop Active View...", "Snoop Active View...", ExecutingAssemblyPath, "RevitLookup.CmdSnoopActiveView" ) );
- optionsBtn.AddPushButton( new PushButtonData( "Snoop Application...", "Snoop Application...", ExecutingAssemblyPath, "RevitLookup.CmdSnoopApp" ) );
- optionsBtn.AddPushButton( new PushButtonData( "Test Framework...", "Test Framework...", ExecutingAssemblyPath, "RevitLookup.CmdTestShell" ) );
- }
-
- private void AddAppDocEvents( ControlledApplication app )
- {
- m_appDocEvents = new AppDocEvents( app );
- m_appDocEvents.EnableEvents();
- }
-
- private void RemoveAppDocEvents()
- {
- m_appDocEvents.DisableEvents();
- }
-
- static BitmapSource GetEmbeddedImage(string name)
+ [Transaction(TransactionMode.Manual)]
+ [Regeneration(RegenerationOption.Manual)]
+ public class App : IExternalApplication
{
- try
- {
- Assembly a = Assembly.GetExecutingAssembly();
- Stream s = a.GetManifestResourceStream(name);
- return BitmapFrame.Create(s);
- }
- catch
- {
- return null;
- }
+ static AddInId m_appId = new AddInId(new Guid(
+ "356CDA5A-E6C5-4c2f-A9EF-B3222116B8C8"));
+
+ // get the absolute path of this assembly
+ static string ExecutingAssemblyPath = System.Reflection.Assembly
+ .GetExecutingAssembly().Location;
+
+ private AppDocEvents m_appDocEvents;
+
+ public Result OnStartup(
+ UIControlledApplication application)
+ {
+
+ // Call this method explicitly in App.cs when Revit starts up because,
+ // in .NET 4, the static variables will not be initialized until use them.
+ Snoop.Collectors.CollectorObj.InitializeCollectors();
+ AddMenu(application);
+ AddAppDocEvents(application.ControlledApplication);
+
+ return Result.Succeeded;
+ }
+
+ public Result OnShutdown(
+ UIControlledApplication application)
+ {
+ RemoveAppDocEvents();
+
+ return Result.Succeeded;
+ }
+
+ private void AddMenu(UIControlledApplication app)
+ {
+ RibbonPanel rvtRibbonPanel = app.CreateRibbonPanel("Revit Lookup");
+ PulldownButtonData data = new PulldownButtonData("Options", "Revit Lookup");
+
+ RibbonItem item = rvtRibbonPanel.AddItem(data);
+ PulldownButton optionsBtn = item as PulldownButton;
+
+ // Add Icons to main RevitLookup Menu
+ optionsBtn.Image = GetEmbeddedImage("RevitLookup.Resources.RLookup-16.png");
+ optionsBtn.LargeImage = GetEmbeddedImage("RevitLookup.Resources.RLookup-32.png");
+
+ optionsBtn.AddPushButton(new PushButtonData("HelloWorld", "Hello World...", ExecutingAssemblyPath, "RevitLookup.HelloWorld"));
+ optionsBtn.AddPushButton(new PushButtonData("Snoop Db..", "Snoop DB...", ExecutingAssemblyPath, "RevitLookup.CmdSnoopDb"));
+ optionsBtn.AddPushButton(new PushButtonData("Snoop Current Selection...", "Snoop Current Selection...", ExecutingAssemblyPath, "RevitLookup.CmdSnoopModScope"));
+ optionsBtn.AddPushButton(new PushButtonData("Snoop Active View...", "Snoop Active View...", ExecutingAssemblyPath, "RevitLookup.CmdSnoopActiveView"));
+ optionsBtn.AddPushButton(new PushButtonData("Snoop Application...", "Snoop Application...", ExecutingAssemblyPath, "RevitLookup.CmdSnoopApp"));
+ optionsBtn.AddPushButton(new PushButtonData("Search and Snoop...", "Search and Snoop...", ExecutingAssemblyPath, "RevitLookup.CmdSearchBy"));
+ optionsBtn.AddPushButton(new PushButtonData("Test Framework...", "Test Framework...", ExecutingAssemblyPath, "RevitLookup.CmdTestShell"));
+ }
+
+ private void AddAppDocEvents(ControlledApplication app)
+ {
+ m_appDocEvents = new AppDocEvents(app);
+ m_appDocEvents.EnableEvents();
+ }
+
+ private void RemoveAppDocEvents()
+ {
+ m_appDocEvents.DisableEvents();
+ }
+
+ static BitmapSource GetEmbeddedImage(string name)
+ {
+ try
+ {
+ Assembly a = Assembly.GetExecutingAssembly();
+ Stream s = a.GetManifestResourceStream(name);
+ return BitmapFrame.Create(s);
+ }
+ catch
+ {
+ return null;
+ }
+ }
}
- }
}
diff --git a/CS/RevitLookup.csproj b/CS/RevitLookup.csproj
index 389ecad56..318abe984 100644
--- a/CS/RevitLookup.csproj
+++ b/CS/RevitLookup.csproj
@@ -319,6 +319,12 @@
Form
+
+ Form
+
+
+ SearchBy.cs
+
Code
@@ -368,6 +374,9 @@
Parameters.cs
Designer
+
+ SearchBy.cs
+
Dom.cs
Designer
diff --git a/CS/Snoop/Forms/SearchBy.Designer.cs b/CS/Snoop/Forms/SearchBy.Designer.cs
new file mode 100644
index 000000000..43f8bd6db
--- /dev/null
+++ b/CS/Snoop/Forms/SearchBy.Designer.cs
@@ -0,0 +1,112 @@
+namespace RevitLookup.Snoop.Forms
+{
+ partial class SearchBy
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.m_cbSearchByVariant = new System.Windows.Forms.ComboBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.m_tbSearchValue = new System.Windows.Forms.TextBox();
+ this.label2 = new System.Windows.Forms.Label();
+ this.m_bnFindAndSnoop = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // m_cbSearchByVariant
+ //
+ this.m_cbSearchByVariant.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.m_cbSearchByVariant.FormattingEnabled = true;
+ this.m_cbSearchByVariant.Items.AddRange(new object[] {
+ "ElementId",
+ "UniqId"});
+ this.m_cbSearchByVariant.Location = new System.Drawing.Point(117, 12);
+ this.m_cbSearchByVariant.Name = "m_cbSearchByVariant";
+ this.m_cbSearchByVariant.Size = new System.Drawing.Size(255, 21);
+ this.m_cbSearchByVariant.TabIndex = 0;
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(12, 15);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(58, 13);
+ this.label1.TabIndex = 1;
+ this.label1.Text = "Search by:";
+ //
+ // m_tbSearchValue
+ //
+ this.m_tbSearchValue.Location = new System.Drawing.Point(117, 39);
+ this.m_tbSearchValue.Name = "m_tbSearchValue";
+ this.m_tbSearchValue.Size = new System.Drawing.Size(255, 20);
+ this.m_tbSearchValue.TabIndex = 2;
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(12, 43);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(99, 13);
+ this.label2.TabIndex = 3;
+ this.label2.Text = "Value to search for:";
+ //
+ // m_bnFindAndSnoop
+ //
+ this.m_bnFindAndSnoop.Location = new System.Drawing.Point(117, 76);
+ this.m_bnFindAndSnoop.Name = "m_bnFindAndSnoop";
+ this.m_bnFindAndSnoop.Size = new System.Drawing.Size(100, 23);
+ this.m_bnFindAndSnoop.TabIndex = 4;
+ this.m_bnFindAndSnoop.Text = "Find and snoop";
+ this.m_bnFindAndSnoop.UseVisualStyleBackColor = true;
+ this.m_bnFindAndSnoop.Click += new System.EventHandler(this.m_bnFindAndSnoop_Click);
+ //
+ // SearchBy
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(384, 111);
+ this.Controls.Add(this.m_bnFindAndSnoop);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.m_tbSearchValue);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.m_cbSearchByVariant);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
+ this.Name = "SearchBy";
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+ this.Text = "SearchBy";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.ComboBox m_cbSearchByVariant;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.TextBox m_tbSearchValue;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.Button m_bnFindAndSnoop;
+ }
+}
\ No newline at end of file
diff --git a/CS/Snoop/Forms/SearchBy.cs b/CS/Snoop/Forms/SearchBy.cs
new file mode 100644
index 000000000..42d3f908f
--- /dev/null
+++ b/CS/Snoop/Forms/SearchBy.cs
@@ -0,0 +1,75 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+using Autodesk.Revit.DB;
+using Form = System.Windows.Forms.Form;
+
+namespace RevitLookup.Snoop.Forms
+{
+ public partial class SearchBy : Form
+ {
+ private readonly Document _doc;
+
+ public SearchBy(Document doc)
+ {
+ InitializeComponent();
+ m_cbSearchByVariant.SelectedIndex = 0;
+ _doc = doc;
+ }
+
+ private void m_bnFindAndSnoop_Click(object sender, System.EventArgs e)
+ {
+ if (string.IsNullOrEmpty(m_tbSearchValue.Text))
+ {
+ MessageBox.Show(@"You did not enter a value to search for", @"Attention!", MessageBoxButtons.OK,
+ MessageBoxIcon.Stop);
+ }
+ switch (m_cbSearchByVariant.SelectedItem)
+ {
+ case "ElementId": // by ElementId
+ SearcAndSnoopByElementId();
+ break;
+ case "UniqId": // by UniqId
+ SearchAndSnoopByUniqId();
+ break;
+ }
+ }
+
+ private void SearcAndSnoopByElementId()
+ {
+ if (int.TryParse(m_tbSearchValue.Text, out var id))
+ {
+ FilteredElementCollector elemTypeCtor = (new FilteredElementCollector(_doc)).WhereElementIsElementType();
+ FilteredElementCollector notElemTypeCtor = (new FilteredElementCollector(_doc)).WhereElementIsNotElementType();
+ FilteredElementCollector allElementCtor = elemTypeCtor.UnionWith(notElemTypeCtor);
+ ICollection ids = allElementCtor
+ .Where(el => el.Id.IntegerValue == id).Select(el => el.Id).ToList();
+ if (ids.Count != 0)
+ {
+ Snoop.Forms.Objects form = new Snoop.Forms.Objects(_doc, ids);
+ form.ShowDialog();
+ }
+ else
+ MessageBox.Show($@"No items with ID {id} found");
+ }
+ else
+ MessageBox.Show(@"The ID value must represent an integer value");
+ }
+
+ private void SearchAndSnoopByUniqId()
+ {
+ FilteredElementCollector elemTypeCtor = (new FilteredElementCollector(_doc)).WhereElementIsElementType();
+ FilteredElementCollector notElemTypeCtor = (new FilteredElementCollector(_doc)).WhereElementIsNotElementType();
+ FilteredElementCollector allElementCtor = elemTypeCtor.UnionWith(notElemTypeCtor);
+ ICollection ids = allElementCtor
+ .Where(el => el.UniqueId == m_tbSearchValue.Text).Select(el => el.Id).ToList();
+ if (ids.Count != 0)
+ {
+ Snoop.Forms.Objects form = new Snoop.Forms.Objects(_doc, ids);
+ form.ShowDialog();
+ }
+ else
+ MessageBox.Show($@"No items with ID {m_tbSearchValue.Text} found");
+ }
+ }
+}
diff --git a/CS/Snoop/Forms/SearchBy.resx b/CS/Snoop/Forms/SearchBy.resx
new file mode 100644
index 000000000..1af7de150
--- /dev/null
+++ b/CS/Snoop/Forms/SearchBy.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/CS/TestCmds.cs b/CS/TestCmds.cs
index d3e57013e..16460ada1 100644
--- a/CS/TestCmds.cs
+++ b/CS/TestCmds.cs
@@ -31,6 +31,7 @@
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using System.Reflection;
+using RevitLookup.Snoop.Forms;
// Each command is implemented as a class that provides the IExternalCommand Interface
//
@@ -269,4 +270,38 @@ public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet el
return result;
}
}
+
+ ///
+ /// Search by and Snoop command: Browse elements found by the condition
+ ///
+
+ [Transaction(TransactionMode.Manual)]
+ [Regeneration(RegenerationOption.Manual)]
+ public class CmdSearchBy : IExternalCommand
+ {
+ public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elems)
+ {
+ Result result;
+
+ try
+ {
+ Snoop.CollectorExts.CollectorExt.m_app = cmdData.Application;
+ UIDocument revitDoc = cmdData.Application.ActiveUIDocument;
+ Document dbdoc = revitDoc.Document;
+ Snoop.CollectorExts.CollectorExt.m_activeDoc = dbdoc; // TBD: see note in CollectorExt.cs
+
+ SearchBy searchByWin = new SearchBy(dbdoc);
+ ActiveDoc.UIApp = cmdData.Application;
+ searchByWin.ShowDialog();
+ result = Result.Succeeded;
+ }
+ catch (System.Exception e)
+ {
+ msg = e.Message;
+ result = Result.Failed;
+ }
+
+ return result;
+ }
+ }
}