Skip to main content

Programmatically Add a File to a BimlStudio Project

This script will include a file that exists in the file system in the current BimlStudio project. This script uses an Invoke since the operation occurs on a separate thread.

This is a useful pattern to combine with auto-generated Biml.

<#
/*=============================================================================
Description:
This script will include a file that exists in the file system in the
current BimlStudio project. This script uses an Invoke since the operation occurs
on a separate thread.

This is a useful pattern to combine with auto-generated Biml.
=============================================================================*/
#>

<#@ template language="C#" hostspecific="True"#>
<#@ assembly name="C:\Program Files\Varigence\BimlStudio\BimlStudio.exe" #>
<#@ assembly name="C:\Program Files\Varigence\BimlStudio\WpfControls.dll" #>
<#@ assembly name="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PresentationFramework.dll" #>
<#@ assembly name="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xaml.dll" #>
<#@ import namespace="Varigence.BimlStudio.Managers" #>

<Biml xmlns="http://schemas.varigence.com/biml.xsd">
</Biml>
<#
WriteLine("<!--");
// Display the project context; this might be useful to find the relative location of a file.
var model = ProjectManager.GetInstance().CurrentProjectViewModel;
WriteLine("Project Directory: {0}", model.DirectoryPath);
WriteLine("Project File Path: {0}", model.FilePath);

// Add a file that exists in the File System to the current BimlStudio project.
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() => { ProjectManager.GetInstance().Project.AddNewPathToModel(@"C:\SVN\edw\edw3\trunk\Jobs\MyAwesomeJob\MyFile.txt", Varigence.Utility.Files.ExplorerItemType.File); }));
WriteLine("-->");
#>

Submitted by David Darden.