Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Search by and snoop" command #42

Merged
merged 1 commit into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 78 additions & 77 deletions CS/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
}
9 changes: 9 additions & 0 deletions CS/RevitLookup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@
<Compile Include="Snoop\Forms\Parameters.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Snoop\Forms\SearchBy.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Snoop\Forms\SearchBy.Designer.cs">
<DependentUpon>SearchBy.cs</DependentUpon>
</Compile>
<Compile Include="Snoop\Utils.cs">
<SubType>Code</SubType>
</Compile>
Expand Down Expand Up @@ -368,6 +374,9 @@
<DependentUpon>Parameters.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Snoop\Forms\SearchBy.resx">
<DependentUpon>SearchBy.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Xml\Forms\Dom.resx">
<DependentUpon>Dom.cs</DependentUpon>
<SubType>Designer</SubType>
Expand Down
112 changes: 112 additions & 0 deletions CS/Snoop/Forms/SearchBy.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions CS/Snoop/Forms/SearchBy.cs
Original file line number Diff line number Diff line change
@@ -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<ElementId> 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<ElementId> 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");
}
}
}
Loading