{"id":75,"date":"2017-01-18T09:28:27","date_gmt":"2017-01-18T00:28:27","guid":{"rendered":"https:\/\/mathcadbimthingy.wordpress.com\/?p=75"},"modified":"2020-03-20T06:18:23","modified_gmt":"2020-03-20T06:18:23","slug":"create-project-and-item-templates-in-visual-studio-revit-apiwpf-series-13","status":"publish","type":"post","link":"https:\/\/mathcadbimthingys.technikstudio.com\/index.php\/2017\/01\/18\/create-project-and-item-templates-in-visual-studio-revit-apiwpf-series-13\/","title":{"rendered":"Create Project and Item Templates in Visual Studio (Revit API+WPF Series 1\/3)"},"content":{"rendered":"<p>In this three-part series, I will be tackling about proper basic integration of Windows Presentation Foundation (WPF) in your Revit API plug-ins using C# .NET.<\/p>\n<p>For the first part, we will discuss creating project and item templates that we will use to create new projects with WPF functionality. For the item template, however, the objective is to be able to create plug-in executable classes without repeatedly creating lines common to your coding workflow.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Creating a Project Template<\/strong><\/p>\n<p>Visual Studio does not provide a class library project template that we can use for our WOF-ed plugins. So we need to create it. We will be starting to create a project template from a WPF application.<\/p>\n<p>1.) From the <b>File<\/b>&nbsp;menu, create a new project. On the left panel, select either <i>C#<\/i>&nbsp;or <i>Visual Basic<\/i>, and from the center panel, select <b>WPF Application<\/b>&nbsp;(see figure below).&nbsp;<\/p>\n<p>Name your project appropriately, (in my case, it&#8217;s <i>Revit API with WPF<\/i>),&nbsp;and then click the <b>OK<\/b>&nbsp;button.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-80\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-1.png\" alt=\"revitapiwpf1-1\" width=\"469\" height=\"463\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-1.png 469w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-1-300x296.png 300w\" sizes=\"(max-width: 469px) 100vw, 469px\" \/><\/p>\n<p>Initially, the new project is created like the figure below. There are files created here that we really do not need, so we have to remove them.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-81\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-2.png\" alt=\"revitapiwpf1-2\" width=\"313\" height=\"453\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-2.png 313w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-2-207x300.png 207w\" sizes=\"(max-width: 313px) 100vw, 313px\" \/><\/p>\n<p>2.) Delete the files <i>MainWindow.xaml<\/i>, <i>App.xaml<\/i> and <i>App.config<\/i>. All subsequent files will be deleted automatically.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-82\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-3.png\" alt=\"revitapiwpf1-3\" width=\"531\" height=\"537\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-3.png 531w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-3-297x300.png 297w\" sizes=\"(max-width: 531px) 100vw, 531px\" \/><\/p>\n<p>3.) Let us add the reference files we need for creating new Revit API plugins.<\/p>\n<p>From the Solution Explorer window, right-click on <i>References<\/i>, and click <b>Add Reference&#8230;<\/b><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-83\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-4.png\" alt=\"revitapiwpf1-4\" width=\"469\" height=\"312\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-4.png 469w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-4-300x200.png 300w\" sizes=\"(max-width: 469px) 100vw, 469px\" \/><\/p>\n<p>4.) The Reference Manager window as shown below will open. Click on the <b>Browse&#8230;<\/b>&nbsp;button.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-84\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-5.png\" alt=\"revitapiwpf1-5\" width=\"876\" height=\"557\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-5.png 876w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-5-300x191.png 300w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-5-768x488.png 768w\" sizes=\"(max-width: 876px) 100vw, 876px\" \/><\/p>\n<p>5.) Browse to your Revit application location, and select the files <i>RevitAPI.dll<\/i> and <i>RevitAPIUI.dll<\/i>. Click on the <b>Add<\/b>&nbsp;button when done. Then on the Reference Manager window, click <b>OK<\/b>.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-85\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-6.png\" alt=\"revitapiwpf1-6\" width=\"648\" height=\"654\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-6.png 648w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-6-297x300.png 297w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-6-150x150.png 150w\" sizes=\"(max-width: 648px) 100vw, 648px\" \/><\/p>\n<p>Try to expand the <i>References<\/i>&nbsp;item from the Solution Explorer window, and we can confirm that the files were added.<\/p>\n<p>Everytime we create a new Revit plugin project, these files will be included in our project. But most of the time, these files post a warning saying that their location is not found.<\/p>\n<p>To enable the location of these files to be always found, let us proceed to the next step.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-86\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-7.png\" alt=\"revitapiwpf1-7\" width=\"310\" height=\"449\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-7.png 310w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-7-207x300.png 207w\" sizes=\"(max-width: 310px) 100vw, 310px\" \/><\/p>\n<p>6.) In the Solution Explorer window, right-click on the project name, and select <b>Properties&#8230;<\/b>&nbsp;and in the properties window, select the <b>Reference Paths<\/b>&nbsp;item.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-88\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-9.png\" alt=\"revitapiwpf1-9\" width=\"920\" height=\"370\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-9.png 920w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-9-300x121.png 300w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-9-768x309.png 768w\" sizes=\"(max-width: 920px) 100vw, 920px\" \/><\/p>\n<p>7.) Click the ellipsis button on the upper right hand of the window, and browse for the folder where the reference files we just added are located.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-89\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-10.png\" alt=\"revitapiwpf1-10\" width=\"730\" height=\"230\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-10.png 730w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-10-300x95.png 300w\" sizes=\"(max-width: 730px) 100vw, 730px\" \/><\/p>\n<p>Click the <b>Add Folder<\/b>&nbsp;button. When we add the folder, Visual Studio will recognize the location of the reference files, and the warning icon will not show up anymore.<\/p>\n<p>In addition to this, whenever we update these reference files to newer versions, we will just re-locate the folder (if in case we update the files to a version say Revit 2018, we can just change the text <i>2017<\/i>&nbsp;to <i>2018<\/i> and click the <b>Update<\/b>&nbsp;button).<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-90\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-11.png\" alt=\"revitapiwpf1-11\" width=\"723\" height=\"226\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-11.png 723w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-11-300x94.png 300w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/p>\n<p>Let us set the output type of this project template. Since we are creating a project template which is a class library, let us set it to a class library.<\/p>\n<p>8.) In the same window, switch to the <b>Application<\/b>&nbsp;tab. Set the Output Type&nbsp;to <i>Class Library<\/i>.<\/p>\n<p>Close the window if you wish.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-91\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-12.png\" alt=\"revitapiwpf1-12\" width=\"915\" height=\"360\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-12.png 915w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-12-300x118.png 300w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-12-768x302.png 768w\" sizes=\"(max-width: 915px) 100vw, 915px\" \/><\/p>\n<p>9.) Compile the project. The compile must be successful.<\/p>\n<p>Next, we need to change one property from the project, but we will not do this inside Visual Studio.<\/p>\n<p>10.) Open Windows Explorer and locate the project. Right-click on the project file (the one with a .csproj extension), and open the file with Notepad or any text editor you have (mine is with Notepad++).<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-92\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-13.png\" alt=\"revitapiwpf1-13\" width=\"599\" height=\"147\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-13.png 599w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-13-300x74.png 300w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/><\/p>\n<p>11.) From the text editor, look for the line with a &lt;AssemblyName&gt; entry. The entry must be the same as the name of our project.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-93\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-14.png\" alt=\"revitapiwpf1-14\" width=\"650\" height=\"300\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-14.png 650w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-14-300x138.png 300w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>Change the name with <i>$safeprojectname$<\/i>.<\/p>\n<p>We do this so that whenever we create a new project, the assembly name will always be the name of our project. If we do not, the assembly name will always be the name of the project template.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-94\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-15.png\" alt=\"revitapiwpf1-15\" width=\"433\" height=\"90\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-15.png 433w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-15-300x62.png 300w\" sizes=\"(max-width: 433px) 100vw, 433px\" \/><\/p>\n<p>12.) Save the file in your text editor.<\/p>\n<p>When we do that, Visual Studio will prompt like the window show below.<\/p>\n<p>Click on <b>Reload<\/b>&nbsp;to reload and update the project file.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-95\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-16.png\" alt=\"revitapiwpf1-16\" width=\"666\" height=\"204\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-16.png 666w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-16-300x92.png 300w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/p>\n<p>Now the necessary basic settings are done, we can already export the project to a template.<\/p>\n<p>13.) From the <b>File<\/b>&nbsp;menu, select <b>Export Template&#8230;<\/b><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-96\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-17.png\" alt=\"revitapiwpf1-17\" width=\"325\" height=\"463\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-17.png 325w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-17-211x300.png 211w\" sizes=\"(max-width: 325px) 100vw, 325px\" \/><\/p>\n<p>14.) Make sure the template type is set to <i>Project Template<\/i>. Then click the <b>Next&gt;<\/b>&nbsp;button.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-97\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-18.png\" alt=\"revitapiwpf1-18\" width=\"731\" height=\"559\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-18.png 731w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-18-300x229.png 300w\" sizes=\"(max-width: 731px) 100vw, 731px\" \/><\/p>\n<p>15.) In the <i>Select Template Options<\/i>&nbsp;window, give an appropriate template name and template description.<\/p>\n<p>Optionally, you can attach icon and preview images for the template.<\/p>\n<p>Leave all other options as is.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-98\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-19.png\" alt=\"revitapiwpf1-19\" width=\"727\" height=\"555\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-19.png 727w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-19-300x229.png 300w\" sizes=\"(max-width: 727px) 100vw, 727px\" \/><\/p>\n<p>16.) Click on the <b>Finish<\/b>&nbsp;button to create the project template.<\/p>\n<p>The File Explorer will open and show us fhe location of the created template. Close this window when done.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-99\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-20.png\" alt=\"revitapiwpf1-20\" width=\"698\" height=\"151\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-20.png 698w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-20-300x65.png 300w\" sizes=\"(max-width: 698px) 100vw, 698px\" \/><\/p>\n<p>17.) Try to create a project using the project we just created.<\/p>\n<p>Create a new project from the <b>File<\/b> menu, and from the template panel, check if the project template is included. If included, select the template and press the <b>OK<\/b>&nbsp;button.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-100\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-21.png\" alt=\"revitapiwpf1-21\" width=\"711\" height=\"327\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-21.png 711w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-21-300x138.png 300w\" sizes=\"(max-width: 711px) 100vw, 711px\" \/><\/p>\n<p>18.) Look at the Solution Explorer window and check the reference files are added and without warnings.<\/p>\n<p>Also, try to open the <i>Properties<\/i>&nbsp;window of the project, and from the <i>Applications<\/i>&nbsp;tab,&nbsp;check if the assembly name is the name of our project name.<\/p>\n<p>When things gone well, we need to check one more thing.<\/p>\n<p>Let us try to add a WPF window.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-101\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-22.png\" alt=\"revitapiwpf1-22\" width=\"308\" height=\"424\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-22.png 308w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-22-218x300.png 218w\" sizes=\"(max-width: 308px) 100vw, 308px\" \/><\/p>\n<p>19.) Right-click on the project name in the Solution Explorer, and then from the <i>Add<\/i>&nbsp;item, select <b>Window&#8230;<\/b><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-102\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-23.png\" alt=\"revitapiwpf1-23\" width=\"698\" height=\"599\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-23.png 698w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-23-300x257.png 300w\" sizes=\"(max-width: 698px) 100vw, 698px\" \/><\/p>\n<p>20.) The template panel must show templates with the <i>(WPF)<\/i>&nbsp;text.<\/p>\n<p>Select <b>Window (WPF)<\/b>, give it a name, and press the <b>Add<\/b>&nbsp;button.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-103\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-24.png\" alt=\"revitapiwpf1-24\" width=\"983\" height=\"753\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-24.png 983w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-24-300x230.png 300w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-24-768x588.png 768w\" sizes=\"(max-width: 983px) 100vw, 983px\" \/><\/p>\n<p>Now our template is also capable of creating WPF windows.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-104\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-25.png\" alt=\"revitapiwpf1-25\" width=\"1143\" height=\"505\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-25.png 1143w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-25-300x133.png 300w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-25-1024x452.png 1024w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-25-768x339.png 768w\" sizes=\"(max-width: 1143px) 100vw, 1143px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Creating an Item Template<\/strong><\/p>\n<p>Although this has nothing to do with WPF, we take advantage of this procedure because we also need to create new plugin classes compliant with our coding workflow.<\/p>\n<p>1.) Reopen the project template project we created earlier.<\/p>\n<p>2.) Right-click on the project name from the Solution Explorer. From the <i>Add<\/i>&nbsp;item, select <b>New Item&#8230;<\/b><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-105\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-26.png\" alt=\"revitapiwpf1-26\" width=\"700\" height=\"542\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-26.png 700w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-26-300x232.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>3.) From the middle panel, select <b>Class<\/b>. Give the new class an appropriate file name, and click on the <b>Add<\/b>&nbsp;button.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-106\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-27.png\" alt=\"revitapiwpf1-27\" width=\"761\" height=\"559\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-27.png 761w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-27-300x220.png 300w\" sizes=\"(max-width: 761px) 100vw, 761px\" \/><\/p>\n<p>3.) Copy the code on the figure below.<\/p>\n<p>To reduce the typing effort, we do the following sub-steps.<\/p>\n<p>Since the class derives from IExternalCommand&nbsp;interface class, input <i>IExternalCommand<\/i>&nbsp;after the class name separated by a comma. Press <b>Ctrl+.<\/b>&nbsp;(period) and select <b>Autodesk.Revit.UI<\/b>&nbsp;to add the reference class.<\/p>\n<p>Right-click over the IExternalCommand base class, and from the context menu, implement the <i>IExternalCommand<\/i>&nbsp;interface.<\/p>\n<p>This procedure will add the Execute function inside the class.<\/p>\n<p>In the Execute function, add the other set of code as shown below. Also, add the other lines with the <i>using<\/i>&nbsp;statement and the <i>Transaction<\/i>&nbsp;attribute above the class declaration.<\/p>\n<p>The code inside the Execute function may differ to your liking.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-107\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-28.png\" alt=\"revitapiwpf1-28\" width=\"580\" height=\"593\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-28.png 580w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-28-293x300.png 293w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/p>\n<p>4.) Let us change the class name to comply with the template settings. Select the class name and replace it with <i>$safeitemname$<\/i>&nbsp;as shown below.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-108\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-29.png\" alt=\"revitapiwpf1-29\" width=\"405\" height=\"76\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-29.png 405w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-29-300x56.png 300w\" sizes=\"(max-width: 405px) 100vw, 405px\" \/><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-109\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-30.png\" alt=\"revitapiwpf1-30\" width=\"331\" height=\"73\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-30.png 331w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-30-300x66.png 300w\" sizes=\"(max-width: 331px) 100vw, 331px\" \/><\/p>\n<p>5.) Save the file. Then from the <b>File<\/b>&nbsp;menu, select <b>Export Template&#8230;<\/b><\/p>\n<p>6.) From the window, select <b>Item Template<\/b>, then click <b>Next &gt;<\/b>.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-110\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-31.png\" alt=\"revitapiwpf1-31\" width=\"547\" height=\"391\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-31.png 547w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-31-300x214.png 300w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/p>\n<p>7.) In the <i>Select Item to Export<\/i>&nbsp;window, check on the file we just created. In this case, the <i>Revit API<\/i>&nbsp;<i>Executable.cs<\/i>&nbsp;file.<\/p>\n<p>Click <b>Next &gt; <\/b>afterwards.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-111\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-32.png\" alt=\"revitapiwpf1-32\" width=\"723\" height=\"555\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-32.png 723w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-32-300x230.png 300w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/p>\n<p>8.) In the next window, we can add reference files necessary for our item template. Since we do not need any, just click <b>Next &gt;<\/b>.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-112\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-33.png\" alt=\"revitapiwpf1-33\" width=\"723\" height=\"554\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-33.png 723w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-33-300x230.png 300w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/p>\n<p>9.) In the next window, enter the appropriate template name, description and images if needed.<\/p>\n<p>Click the <b>Finish<\/b>&nbsp;button when done.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-113\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-34.png\" alt=\"revitapiwpf1-34\" width=\"727\" height=\"557\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-34.png 727w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-34-300x230.png 300w\" sizes=\"(max-width: 727px) 100vw, 727px\" \/><\/p>\n<p>Let us see if the item template will appear in the item templates list.<\/p>\n<p>Before we proceed, I recommend to re-open Visual Studio in order for the new item template to be loaded properly.<\/p>\n<p>10.) Open the test project we created earlier. Try to add a new item.<\/p>\n<p>Once the window is opened, we can see that our item template is already loaded in Visual Studio.<\/p>\n<p>Select the template, give an appropriate file name, and click <b>Add<\/b>.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-115\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-36.png\" alt=\"revitapiwpf1-36\" width=\"851\" height=\"341\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-36.png 851w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-36-300x120.png 300w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-36-768x308.png 768w\" sizes=\"(max-width: 851px) 100vw, 851px\" \/><\/p>\n<p>The new class file will contain all the code we entered during the creation. Also, we can see that the class name is the name of the file.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-116\" src=\"http:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-37.png\" alt=\"revitapiwpf1-37\" width=\"627\" height=\"632\" srcset=\"https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-37.png 627w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-37-298x300.png 298w, https:\/\/mathcadbimthingys.technikstudio.com\/wp-content\/uploads\/2017\/01\/revitapiwpf1-37-150x150.png 150w\" sizes=\"(max-width: 627px) 100vw, 627px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>So there you have it.<\/p>\n<p>If you have any questions, feedback or comments regarding this post, please make sure to post them in the comment section below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this three-part series, I will be tackling about proper basic integration of Windows Presentation Foundation (WPF) in your Revit API plug-ins using C# .NET. For the first part, we will discuss creating project and item templates that we will use to create new projects with WPF functionality. For the item template, however, the objective [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":107,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/mathcadbimthingys.technikstudio.com\/index.php\/wp-json\/wp\/v2\/posts\/75"}],"collection":[{"href":"https:\/\/mathcadbimthingys.technikstudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mathcadbimthingys.technikstudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mathcadbimthingys.technikstudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mathcadbimthingys.technikstudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":1,"href":"https:\/\/mathcadbimthingys.technikstudio.com\/index.php\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"predecessor-version":[{"id":273,"href":"https:\/\/mathcadbimthingys.technikstudio.com\/index.php\/wp-json\/wp\/v2\/posts\/75\/revisions\/273"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mathcadbimthingys.technikstudio.com\/index.php\/wp-json\/wp\/v2\/media\/107"}],"wp:attachment":[{"href":"https:\/\/mathcadbimthingys.technikstudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mathcadbimthingys.technikstudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mathcadbimthingys.technikstudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}