Skip to content

Commit

Permalink
add compare two element
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Sep 3, 2023
1 parent 20ee88c commit cad4135
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 8 deletions.
47 changes: 39 additions & 8 deletions RevitElementBipChecker/Command/BipCheckerCommand.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
using System.Windows;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using KellermanSoftware.CompareNetObjects;
using ObjectsComparer;
using RevitElementBipChecker.Model;
using RevitElementBipChecker.View;
using RevitElementBipChecker.Viewmodel;
using Difference = KellermanSoftware.CompareNetObjects.Difference;

namespace RevitElementBipChecker.Command
{
Expand All @@ -18,15 +26,38 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;




BipCheckerViewmodel vm = new BipCheckerViewmodel(uidoc);
FrmBipChecker frMainWindows = new FrmBipChecker(vm);
frMainWindows.WindowStartupLocation = WindowStartupLocation.CenterScreen;
frMainWindows.SetRevitAsWindowOwner();
frMainWindows.Show();
// write to csv

// DataTable dataTable = new DataTable();
// dataTable.Columns.Add("Name");
// dataTable.Columns.Add("Type");
// dataTable.Columns.Add("Value1");
// dataTable.Columns.Add("Value2");
// foreach (var difference in differences)
// {
// DataRow dataRow = dataTable.NewRow();
// dataRow["Name"] = difference.Name;
// dataRow["Type"] = difference.Type;
// dataRow["Value1"] = difference.Value1;
// dataRow["Value2"] = difference.Value2;
// dataTable.Rows.Add(dataRow);
// }
// dataTable.ExportCsv();
// BipCheckerViewmodel vm = new BipCheckerViewmodel(uidoc);
// FrmBipChecker frMainWindows = new FrmBipChecker(vm);
// frMainWindows.WindowStartupLocation = WindowStartupLocation.CenterScreen;
// frMainWindows.SetRevitAsWindowOwner();
// frMainWindows.Show();
return Result.Succeeded;
}

}


public class BipCheckerCommandAvail : IExternalCommandAvailability
{
public BipCheckerCommandAvail()
Expand All @@ -35,7 +66,7 @@ public BipCheckerCommandAvail()

public bool IsCommandAvailable(UIApplication uiApp, CategorySet selectedCategories)
{
if(uiApp.ActiveUIDocument!=null)
if (uiApp.ActiveUIDocument != null)
{
return true;
}
Expand All @@ -45,4 +76,4 @@ public bool IsCommandAvailable(UIApplication uiApp, CategorySet selectedCategori
}
}
}
}
}
31 changes: 31 additions & 0 deletions RevitElementBipChecker/Command/CompareCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Windows;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using RevitElementBipChecker.Model;
using RevitElementBipChecker.View;

namespace RevitElementBipChecker.Command;

[Transaction(TransactionMode.Manual)]
public class CompareCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;
Reference r1 = uidoc.Selection.PickObject(ObjectType.Element,"Select first element");
Element element1 = doc.GetElement(r1);
Reference r2 = uidoc.Selection.PickObject(ObjectType.Element,"Select second element");
Element element2 = doc.GetElement(r2);
FrmCompareBip frmCompareBip = new FrmCompareBip(element1,element2);

frmCompareBip.WindowStartupLocation = WindowStartupLocation.CenterScreen;
frmCompareBip.SetRevitAsWindowOwner();
frmCompareBip.Show();
return Result.Succeeded;
}
}
97 changes: 97 additions & 0 deletions RevitElementBipChecker/Model/ParameterComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows.Media;

namespace RevitElementBipChecker.Model;

public class ParameterComparer
{
public static List<ParameterDifference> CompareParameters(List<ParameterBase> list1, List<ParameterBase> list2)
{
var differences = new List<ParameterDifference>();

// Find parameters in list1 that are not in list2
foreach (var parameter1 in list1)
{
var parameter2 = list2.FirstOrDefault(p => p.Name == parameter1.Name);

if (parameter2 == null)
{
differences.Add(new ParameterDifference
{
Name = parameter1.Name,
Type = parameter1.Type,
Value1 = parameter1.Value,
Value2 = null // Not found in list2
});
}
else if (parameter1.Type != parameter2.Type || parameter1.Value != parameter2.Value)
{
differences.Add(new ParameterDifference
{
Name = parameter1.Name,
Type = parameter1.Type,
Value1 = parameter1.Value,
Value2 = parameter2.Value
});
}
}

// Find parameters in list2 that are not in list1
foreach (var parameter2 in list2)
{
var parameter1 = list1.FirstOrDefault(p => p.Name == parameter2.Name);

if (parameter1 == null)
{
differences.Add(new ParameterDifference
{
Name = parameter2.Name,
Type = parameter2.Type,
Value1 = null, // Not found in list1
Value2 = parameter2.Value
});
}
}
return differences;
}
}
public class ParameterBase
{
public string Name { get; set; }
public string Value { get; set; }
public string Type { get; set; }
}
public class ParameterDifference: INotifyPropertyChanged
{
public string Name { get; set; }
public string Type { get; set; }
public string Value1 { get; set; }
public string Value2 { get; set; }
private Brush _backgroundColor = Brushes.Transparent;
public Brush BackgroundColor
{
get { return _backgroundColor; }
set
{
_backgroundColor = value;
OnPropertyChanged(nameof(BackgroundColor));
}
}
public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
}
2 changes: 2 additions & 0 deletions RevitElementBipChecker/RevitElementBipChecker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
<PackageReference Include="Chuongmep.Revit.Api.AdWindows" Version="$(RevitVersion).*">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="CompareNETObjects" Version="4.80.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ObjectsComparer" Version="1.4.1" />
</ItemGroup>
</Project>
51 changes: 51 additions & 0 deletions RevitElementBipChecker/View/FrmCompareBip.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<Window x:Class="RevitElementBipChecker.View.FrmCompareBip"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="Mini Compare Two Element" Height="600" Width="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="35" />
</Grid.RowDefinitions>
<DataGrid
x:Name="dataGrid"
Background="WhiteSmoke"
AlternatingRowBackground="Transparent"
AlternationCount="2"
IsReadOnly="True"
AutoGenerateColumns="False">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="{Binding BackgroundColor}" />
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Width="100" Header="Parameter Name" Binding="{Binding Name}" />
<DataGridTextColumn Width="70" Header="Type" Binding="{Binding Type}" />
<DataGridTextColumn Width="*" Header="Value Element1" Binding="{Binding Value1}" />
<DataGridTextColumn Width="*" Header="Value Element2" Binding="{Binding Value2}" />
</DataGrid.Columns>
</DataGrid>
<Grid Grid.Row="1" Margin="2,2,2,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Content="Toggle"
Margin="1,1,1,1"
Background="WhiteSmoke"
ToolTip="Toggle to check different parameters between two elements invert"
Click="ToggleClick">
</Button>
<Button IsCancel="True"
Background="WhiteSmoke"
Margin="1,1,1,1"
Click="CloseClick" Grid.Column="1" Grid.Row="0" Content="Close">
</Button>
</Grid>

</Grid>
</Window>
Loading

0 comments on commit cad4135

Please sign in to comment.