├── AddMaterials ├── Resources │ └── delete.png ├── Properties │ ├── ._AssemblyInfo.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── ViewModel │ ├── Enum │ │ └── Status.cs │ ├── Events │ │ └── DialogCloseEventArgs.cs │ ├── ViewModelLocator.cs │ ├── FillPatternViewModel.cs │ ├── MaterialViewModel.cs │ ├── FillPatternsViewModel.cs │ └── MaterialBrowserViewModel.cs ├── View │ ├── FillPatternsView.xaml.cs │ ├── Converters │ │ ├── StatusToErrorSignVisibilityConverter.cs │ │ ├── InversedStatusToErrorSignVisibilityConverter.cs │ │ ├── StatusToErrorMessageConverter.cs │ │ ├── BitmapToImageSourceConverter.cs │ │ └── BitmapSourceConverter.cs │ ├── MaterialsView.xaml.cs │ ├── Controls │ │ ├── FillPatternViewerControlWpf.xaml │ │ └── FillPatternViewerControlWpf.xaml.cs │ ├── Commands │ │ └── RelayCommand.cs │ ├── FillPatternsView.xaml │ └── MaterialsView.xaml ├── AddMaterials.addin ├── FillPatternBenchmarkCommand.cs ├── AddMaterials.csproj └── Command.cs ├── AddMaterials.sln ├── README.md ├── .gitignore └── LICENSE /AddMaterials/Resources/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeremytammik/AddMaterials/HEAD/AddMaterials/Resources/delete.png -------------------------------------------------------------------------------- /AddMaterials/Properties/._AssemblyInfo.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeremytammik/AddMaterials/HEAD/AddMaterials/Properties/._AssemblyInfo.cs -------------------------------------------------------------------------------- /AddMaterials/ViewModel/Enum/Status.cs: -------------------------------------------------------------------------------- 1 | namespace AddMaterials.ViewModel.Enum 2 | { 3 | public enum Status 4 | { 5 | Normal, 6 | 7 | BaseMaterialClassNotFound, 8 | 9 | ProjectAlreadyContainsMaterialWithTheSameName 10 | } 11 | } -------------------------------------------------------------------------------- /AddMaterials/ViewModel/Events/DialogCloseEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AddMaterials.ViewModel.Events 4 | { 5 | public class DialogCloseEventArgs : EventArgs 6 | { 7 | private readonly bool? result; 8 | 9 | public DialogCloseEventArgs(bool? result) 10 | { 11 | this.result = result; 12 | } 13 | 14 | public bool? Result 15 | { 16 | get { return result; } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /AddMaterials/ViewModel/ViewModelLocator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AddMaterials.ViewModel 4 | { 5 | public class ViewModelLocator 6 | { 7 | private static readonly Lazy InstanceObj = 8 | new Lazy(() => new ViewModelLocator()); 9 | 10 | public static ViewModelLocator Instance 11 | { 12 | get { return InstanceObj.Value; } 13 | } 14 | 15 | private ViewModelLocator() 16 | { 17 | 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /AddMaterials/ViewModel/FillPatternViewModel.cs: -------------------------------------------------------------------------------- 1 | using Autodesk.Revit.DB; 2 | 3 | namespace AddMaterials.ViewModel 4 | { 5 | public class FillPatternViewModel 6 | { 7 | private readonly FillPattern _fillPattern; 8 | 9 | public FillPatternViewModel(FillPattern fillPattern) 10 | { 11 | _fillPattern = fillPattern; 12 | } 13 | 14 | public FillPattern FillPattern 15 | { 16 | get { return _fillPattern; } 17 | } 18 | 19 | public string Name 20 | { 21 | get { return _fillPattern.Name; } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /AddMaterials/ViewModel/MaterialViewModel.cs: -------------------------------------------------------------------------------- 1 | using AddMaterials.ViewModel.Enum; 2 | using Autodesk.Revit.DB; 3 | 4 | namespace AddMaterials.ViewModel 5 | { 6 | public class MaterialViewModel 7 | { 8 | public string Name { get; set; } 9 | 10 | public string BaseMaterialClass { get; set; } 11 | 12 | public FillPattern SurfacePattern { get; set; } 13 | 14 | public FillPattern CutPattern { get; set; } 15 | 16 | public Color Color { get; set; } 17 | 18 | public double Transparency { get; set; } 19 | 20 | public Status Status { get; set; } 21 | 22 | public bool AddToProject { get; set; } 23 | } 24 | } -------------------------------------------------------------------------------- /AddMaterials/ViewModel/FillPatternsViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | 5 | namespace AddMaterials.ViewModel 6 | { 7 | public class FillPatternsViewModel 8 | { 9 | private ReadOnlyCollection _fillPatterns; 10 | 11 | public FillPatternsViewModel(IEnumerable fillPatterns) 12 | { 13 | _fillPatterns = new ReadOnlyCollection(new List(fillPatterns)); 14 | } 15 | 16 | public ReadOnlyCollection FillPatterns 17 | { 18 | get { return _fillPatterns; } 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /AddMaterials/View/FillPatternsView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows; 6 | using System.Windows.Controls; 7 | using System.Windows.Data; 8 | using System.Windows.Documents; 9 | using System.Windows.Input; 10 | using System.Windows.Media; 11 | using System.Windows.Media.Imaging; 12 | using System.Windows.Navigation; 13 | using System.Windows.Shapes; 14 | 15 | namespace AddMaterials.View 16 | { 17 | /// 18 | /// Interaction logic for FillPatternsView.xaml 19 | /// 20 | public partial class FillPatternsView 21 | { 22 | public FillPatternsView() 23 | { 24 | InitializeComponent(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AddMaterials/View/Converters/StatusToErrorSignVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | using AddMaterials.ViewModel.Enum; 6 | 7 | namespace AddMaterials.View.Converters 8 | { 9 | public class StatusToErrorSignVisibilityConverter : IValueConverter 10 | { 11 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 12 | { 13 | if (!(value is Status)) 14 | return Visibility.Collapsed; 15 | var status = (Status) value; 16 | 17 | return status != Status.Normal ? Visibility.Visible : Visibility.Collapsed; 18 | } 19 | 20 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 21 | { 22 | throw new NotSupportedException(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /AddMaterials/View/Converters/InversedStatusToErrorSignVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows; 4 | using System.Windows.Data; 5 | 6 | namespace AddMaterials.View.Converters 7 | { 8 | public class InversedStatusToErrorSignVisibilityConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | var converter = new StatusToErrorSignVisibilityConverter(); 13 | var converted = (Visibility)converter.Convert(value, targetType, parameter, culture); 14 | return converted == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible; 15 | } 16 | 17 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 18 | { 19 | throw new NotSupportedException(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /AddMaterials.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddMaterials", "AddMaterials\AddMaterials.csproj", "{CC6FB9CE-8D9C-494C-BA77-29961459647B}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {CC6FB9CE-8D9C-494C-BA77-29961459647B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {CC6FB9CE-8D9C-494C-BA77-29961459647B}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {CC6FB9CE-8D9C-494C-BA77-29961459647B}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {CC6FB9CE-8D9C-494C-BA77-29961459647B}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /AddMaterials/AddMaterials.addin: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AddMaterials 5 | Some description for AddMaterials 6 | AddMaterials.dll 7 | AddMaterials.Command 8 | a9ec88c8-33a3-4a4d-bb91-e0cb54623b34 9 | TBC_ 10 | The Building Coder, http://thebuildingcoder.typepad.com 11 | 12 | 13 | AddMaterials Fill Pattern benchmark 14 | Some description for AddMaterials 15 | AddMaterials.dll 16 | AddMaterials.FillPatternBenchmarkCommand 17 | ff23fb73-8f11-4c93-b867-9a599a73dd53 18 | TBC_ 19 | The Building Coder, http://thebuildingcoder.typepad.com 20 | 21 | 22 | -------------------------------------------------------------------------------- /AddMaterials/View/MaterialsView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using AddMaterials.ViewModel; 4 | using AddMaterials.ViewModel.Events; 5 | 6 | namespace AddMaterials.View 7 | { 8 | /// 9 | /// Interaction logic for MaterialsView.xaml 10 | /// 11 | public partial class MaterialsView 12 | { 13 | public MaterialsView() 14 | { 15 | InitializeComponent(); 16 | DataContextChanged += OnDataContextChanged; 17 | } 18 | 19 | private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) 20 | { 21 | var materialBrowser = e.NewValue as MaterialBrowserViewModel; 22 | if (materialBrowser != null) 23 | materialBrowser.RequestClose += OnRequestClose; 24 | } 25 | 26 | private void OnRequestClose(object sender, DialogCloseEventArgs e) 27 | { 28 | try 29 | { 30 | DialogResult = e.Result; 31 | } 32 | catch (InvalidOperationException) 33 | { 34 | Close(); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /AddMaterials/View/Converters/StatusToErrorMessageConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | using AddMaterials.ViewModel.Enum; 5 | 6 | namespace AddMaterials.View.Converters 7 | { 8 | public class StatusToErrorMessageConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | if (!(value is Status)) 13 | return string.Empty; 14 | var status = (Status) value; 15 | switch (status) 16 | { 17 | case Status.ProjectAlreadyContainsMaterialWithTheSameName: 18 | return "Project already contains material with the same name"; 19 | case Status.BaseMaterialClassNotFound: 20 | return "Base material class not found in the project"; 21 | default: 22 | return string.Empty; 23 | } 24 | } 25 | 26 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 27 | { 28 | throw new NotSupportedException(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /AddMaterials/View/Controls/FillPatternViewerControlWpf.xaml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 15 | 16 | 17 | 19 | 20 | 21 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /AddMaterials/ViewModel/MaterialBrowserViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows.Input; 4 | using AddMaterials.View.Commands; 5 | using AddMaterials.ViewModel.Events; 6 | 7 | namespace AddMaterials.ViewModel 8 | { 9 | public class MaterialBrowserViewModel 10 | { 11 | public event EventHandler RequestClose; 12 | 13 | protected void OnRequestClose(DialogCloseEventArgs e) 14 | { 15 | EventHandler handler = RequestClose; 16 | if (handler != null) handler(this, e); 17 | } 18 | 19 | protected void Close(bool? result) 20 | { 21 | OnRequestClose(new DialogCloseEventArgs(result)); 22 | } 23 | 24 | public IEnumerable Materials { get; set; } 25 | 26 | private ICommand okCommand; 27 | public ICommand OkCommand 28 | { 29 | get { return okCommand ?? (okCommand = new RelayCommand(o => Close(true))); } 30 | } 31 | 32 | private ICommand cancelCommand; 33 | public ICommand CancelCommand 34 | { 35 | get { return cancelCommand ?? (cancelCommand = new RelayCommand(o => Close(false))); } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /AddMaterials/View/Converters/BitmapToImageSourceConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Globalization; 4 | using System.Windows.Data; 5 | 6 | namespace AddMaterials.View.Converters 7 | { 8 | public class BitmapToImageSourceConverter : IValueConverter 9 | { 10 | private static readonly Lazy InstanceObj = 11 | new Lazy(() => new BitmapToImageSourceConverter()); 12 | 13 | public static BitmapToImageSourceConverter Instance 14 | { 15 | get { return InstanceObj.Value; } 16 | } 17 | 18 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 19 | { 20 | var bmp = value as Bitmap; 21 | if (bmp == null) 22 | { 23 | var defaultBmp = parameter as Bitmap; 24 | if (defaultBmp != null) 25 | return BitmapSourceConverter.ConvertFromImage(defaultBmp); 26 | } 27 | 28 | return bmp == null ? null : BitmapSourceConverter.ConvertFromImage(bmp); 29 | } 30 | 31 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 32 | { 33 | throw new NotSupportedException(); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /AddMaterials/FillPatternBenchmarkCommand.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Windows.Input; 3 | using AddMaterials.View; 4 | using AddMaterials.ViewModel; 5 | using Autodesk.Revit.Attributes; 6 | using Autodesk.Revit.DB; 7 | using Autodesk.Revit.UI; 8 | 9 | namespace AddMaterials 10 | { 11 | [Transaction( TransactionMode.ReadOnly )] 12 | public class FillPatternBenchmarkCommand 13 | : IExternalCommand 14 | { 15 | public Result Execute( 16 | ExternalCommandData commandData, 17 | ref string message, 18 | ElementSet elements ) 19 | { 20 | var doc = commandData.Application 21 | .ActiveUIDocument.Document; 22 | 23 | var fillPatternElements 24 | = new FilteredElementCollector( doc ) 25 | .OfClass( typeof( FillPatternElement ) ) 26 | .OfType() 27 | .OrderBy( fp => fp.Name ) 28 | .ToList(); 29 | 30 | var fillPatterns 31 | = fillPatternElements.Select( 32 | fpe => fpe.GetFillPattern() ); 33 | 34 | FillPatternsViewModel fillPatternsViewModel 35 | = new FillPatternsViewModel( fillPatterns 36 | .Select( x => new FillPatternViewModel( 37 | x ) ) ); 38 | 39 | FillPatternsView fillPatternsView 40 | = new FillPatternsView() 41 | { 42 | DataContext = fillPatternsViewModel 43 | }; 44 | 45 | fillPatternsView.ShowDialog(); 46 | 47 | return Result.Succeeded; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /AddMaterials/View/Commands/RelayCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Windows.Input; 4 | 5 | 6 | namespace AddMaterials.View.Commands 7 | { 8 | public class RelayCommand : ICommand 9 | { 10 | private readonly Action execute; 11 | private readonly Predicate canExecute; 12 | 13 | /// 14 | /// Creates a new command that can always execute. 15 | /// 16 | /// The execution logic. 17 | public RelayCommand(Action execute) 18 | : this(execute, null) 19 | { 20 | } 21 | 22 | /// 23 | /// Creates a new command. 24 | /// 25 | /// The execution logic. 26 | /// The execution status logic. 27 | public RelayCommand(Action execute, Predicate canExecute) 28 | { 29 | if (execute == null) 30 | throw new ArgumentNullException("execute"); 31 | 32 | this.execute = execute; 33 | this.canExecute = canExecute; 34 | } 35 | 36 | [DebuggerStepThrough] 37 | public bool CanExecute(object parameter) 38 | { 39 | return canExecute == null || canExecute(parameter); 40 | } 41 | 42 | public event EventHandler CanExecuteChanged 43 | { 44 | add { CommandManager.RequerySuggested += value; } 45 | remove { CommandManager.RequerySuggested -= value; } 46 | } 47 | 48 | public void Execute(object parameter) 49 | { 50 | execute(parameter); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AddMaterials 2 | 3 | Revit add-in to add materials from a list of properties defined in Excel. 4 | 5 | For more information, please refer to [The Building Coder](http://thebuildingcoder.typepad.com): 6 | 7 | - [Original implementation for Revit 2011](http://thebuildingcoder.typepad.com/blog/2010/08/add-new-materials-from-list.html#2) 8 | - [Reimplementation for Revit 2014](http://thebuildingcoder.typepad.com/blog/2014/03/adding-new-materials-from-list-updated.html) 9 | - [Improved error messages and reporting](http://thebuildingcoder.typepad.com/blog/2014/03/adding-new-materials-from-list-updated-again.html) 10 | - [WPF FillPattern viewer control](http://thebuildingcoder.typepad.com/blog/2014/04/wpf-fill-pattern-viewer-control.html) 11 | - [Check for already loaded materials](http://thebuildingcoder.typepad.com/blog/2014/04/getting-serious-adding-new-materials-from-list.html) 12 | - [FillPattern viewer benchmarking](http://thebuildingcoder.typepad.com/blog/2014/04/wpf-fill-pattern-viewer-control-benchmark.html) 13 | - [Fill Pattern Viewer Fix and Add Materials for 2016](http://thebuildingcoder.typepad.com/blog/2015/11/fill-pattern-viewer-fix-and-add-materials-2016.html) 14 | 15 | ## Authors 16 | 17 | - Jinsol Kim 18 | - Luke 19 | - Victor Chekalin, Виктор Чекалин 20 | - Alexander Ignatovich, Александр Игнатович 21 | - [@kfpopeye](https://github.com/kfpopeye) 22 | - Jeremy Tammik, 23 | [The Building Coder](http://thebuildingcoder.typepad.com) and 24 | [The 3D Web Coder](http://the3dwebcoder.typepad.com), 25 | [ADN](http://www.autodesk.com/adn) 26 | [Open](http://www.autodesk.com/adnopen), 27 | [Autodesk Inc.](http://www.autodesk.com) 28 | 29 | 30 | ## License 31 | 32 | This sample is licensed under the terms of the [Apache License](http://www.apache.org/licenses). 33 | Please see the [LICENSE](LICENSE) file for full details. 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | 5 | # mstest test results 6 | TestResults 7 | 8 | ## Ignore Visual Studio temporary files, build results, and 9 | ## files generated by popular Visual Studio add-ons. 10 | 11 | # User-specific files 12 | *.suo 13 | *.user 14 | *.sln.docstates 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Rr]elease/ 19 | x64/ 20 | *_i.c 21 | *_p.c 22 | *.ilk 23 | *.meta 24 | *.obj 25 | *.pch 26 | *.pdb 27 | *.pgc 28 | *.pgd 29 | *.rsp 30 | *.sbr 31 | *.tlb 32 | *.tli 33 | *.tlh 34 | *.tmp 35 | *.log 36 | *.vspscc 37 | *.vssscc 38 | .builds 39 | 40 | # Visual C++ cache files 41 | ipch/ 42 | *.aps 43 | *.ncb 44 | *.opensdf 45 | *.sdf 46 | 47 | # Visual Studio profiler 48 | *.psess 49 | *.vsp 50 | *.vspx 51 | 52 | # Guidance Automation Toolkit 53 | *.gpState 54 | 55 | # ReSharper is a .NET coding add-in 56 | _ReSharper* 57 | 58 | # NCrunch 59 | *.ncrunch* 60 | .*crunch*.local.xml 61 | 62 | # Installshield output folder 63 | [Ee]xpress 64 | 65 | # DocProject is a documentation generator add-in 66 | DocProject/buildhelp/ 67 | DocProject/Help/*.HxT 68 | DocProject/Help/*.HxC 69 | DocProject/Help/*.hhc 70 | DocProject/Help/*.hhk 71 | DocProject/Help/*.hhp 72 | DocProject/Help/Html2 73 | DocProject/Help/html 74 | 75 | # Click-Once directory 76 | publish 77 | 78 | # Publish Web Output 79 | *.Publish.xml 80 | 81 | # NuGet Packages Directory 82 | packages 83 | 84 | # Windows Azure Build Output 85 | csx 86 | *.build.csdef 87 | 88 | # Windows Store app package directory 89 | AppPackages/ 90 | 91 | # Others 92 | [Bb]in 93 | [Oo]bj 94 | sql 95 | TestResults 96 | [Tt]est[Rr]esult* 97 | *.Cache 98 | ClientBin 99 | [Ss]tyle[Cc]op.* 100 | ~$* 101 | *.dbmdl 102 | Generated_Code #added for RIA/Silverlight projects 103 | 104 | # Backup & report files from converting an old project file to a newer 105 | # Visual Studio version. Backup files are not needed, because we have git ;-) 106 | _UpgradeReport_Files/ 107 | Backup*/ 108 | UpgradeLog*.XML 109 | -------------------------------------------------------------------------------- /AddMaterials/View/Converters/BitmapSourceConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Windows; 4 | using System.Windows.Interop; 5 | using System.Windows.Media.Imaging; 6 | namespace AddMaterials.View.Converters 7 | { 8 | public class BitmapSourceConverter 9 | { 10 | [System.Runtime.InteropServices.DllImport("gdi32.dll")] 11 | private static extern bool DeleteObject(IntPtr hObject); 12 | 13 | public static BitmapSource ConvertFromImage(Bitmap image) 14 | { 15 | lock (image) 16 | { 17 | IntPtr hBitmap = image.GetHbitmap(); 18 | try 19 | { 20 | var bs = Imaging.CreateBitmapSourceFromHBitmap( 21 | hBitmap, 22 | IntPtr.Zero, 23 | Int32Rect.Empty, 24 | BitmapSizeOptions.FromEmptyOptions()); 25 | 26 | return bs; 27 | } 28 | finally 29 | { 30 | // ReSharper disable UnusedVariable 31 | var res = DeleteObject(hBitmap); 32 | // ReSharper restore UnusedVariable 33 | } 34 | } 35 | } 36 | 37 | public static BitmapSource ConvertFromIcon(Icon icon) 38 | { 39 | 40 | try 41 | { 42 | var bs = Imaging 43 | .CreateBitmapSourceFromHIcon(icon.Handle, 44 | new Int32Rect(0, 0, icon.Width, icon.Height), 45 | BitmapSizeOptions.FromWidthAndHeight(icon.Width, 46 | icon.Height)); 47 | return bs; 48 | } 49 | finally 50 | { 51 | DeleteObject(icon.Handle); 52 | icon.Dispose(); 53 | // ReSharper disable RedundantAssignment 54 | icon = null; 55 | // ReSharper restore RedundantAssignment 56 | } 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /AddMaterials/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle( "Revit AddMaterials Add-In" )] 9 | [assembly: AssemblyDescription( "Add materials from Excel spreadsheet to Revit project" )] 10 | [assembly: AssemblyConfiguration( "" )] 11 | [assembly: AssemblyCompany( "Autodesk Inc." )] 12 | [assembly: AssemblyProduct( "Revit AddMaterials Add-In" )] 13 | [assembly: AssemblyCopyright( "Copyright 2014 © Jeremy Tammik Autodesk Inc." )] 14 | [assembly: AssemblyTrademark( "" )] 15 | [assembly: AssemblyCulture( "" )] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible( false )] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid( "321044f7-b0b2-4b1c-af18-e71a19252be0" )] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | // 2014-03-20 2014.0.0.0 migrated from Revit 2011 to Revit 2014 36 | // 2014-03-29 2014.0.0.1 error message and reporting enhancements 37 | // 2014-04-02 2014.0.0.2 usability enhancements by Alexander Ignatovich 38 | // 2014-04-20 2015.0.0.2 migrated to Revit 2015 39 | // 2014-04-20 2015.0.0.3 integrated fill pattern viewer benchmark 40 | // 2015-11-04 2015.0.0.4 updated FillPatternViewerControlWpf.xaml.cs, merged pull request #1 by @kfpopeye 41 | // 2015-11-04 2015.0.0.5 updated FillPatternViewerControlWpf.xaml.cs, merged pull request #3 by @kfpopeye 42 | // 2015-11-04 2016.0.0.0 tested and migrated to Revit 2016 43 | // 2019-06-07 2016.0.0.1 integrated pull request #4 by @ridespirals -- handle 0 or negative DashPatterns 44 | // 2019-06-12 2020.0.0.0 flat migration to Revit 2020 45 | // 2019-06-12 2020.0.0.1 implemented suggestion by Александр Пекшев: Replace FillPattern = "{Binding CutPattern}" with FillPattern = "{Binding CutPattern, IsAsync=True}" and drawing thumbnails can get even faster 46 | // 47 | [assembly: AssemblyVersion( "2020.0.0.1" )] 48 | [assembly: AssemblyFileVersion( "2020.0.0.1" )] 49 | -------------------------------------------------------------------------------- /AddMaterials/View/FillPatternsView.xaml: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 31 | 32 | 34 | 35 | 38 | 39 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /AddMaterials/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace AddMaterials.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | public class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | public static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AddMaterials.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | public static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Bitmap. 65 | /// 66 | public static System.Drawing.Bitmap Error { 67 | get { 68 | object obj = ResourceManager.GetObject("Error", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /AddMaterials/View/MaterialsView.xaml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 53 | 54 | 55 | 56 | 57 | 59 | 60 | 61 | 63 | 64 | 67 | 68 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 81 | 82 | 83 | 85 | 86 | 89 | 90 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 103 | 104 | 106 | 107 | 108 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 121 |