<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic VDS create folder tree from template 2021 in Vault Customization Forum</title>
    <link>https://forums.autodesk.com/t5/vault-customization-forum/vds-create-folder-tree-from-template-2021/m-p/10296159#M3184</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I am still very new in customizing and just can't find the solution to my problem.&lt;BR /&gt;Currently I am trying to create a folder structure according to a template via VDS. Have already read some posts but it does not work yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My CreateFolder.ps1&lt;/P&gt;&lt;LI-CODE lang="general"&gt;$folderId=$vaultContext.CurrentSelectionSet[0].Id
$vaultContext.ForceRefresh = $true
$dialog = $dsCommands.GetCreateFolderDialog($folderId)

#override the default dialog file assigned
$xamlFile = New-Object CreateObject.WPF.XamlFile "ADSK.QS.Folder.xaml", "C:\ProgramData\Autodesk\Vault 2021\Extensions\DataStandard\Vault.Custom\Configuration\ADSK.QS.Folder.xaml"
$dialog.XamlFile = $xamlFile

$result = $dialog.Execute()
$dsDiag.Trace($result)

if($result)
{
	#new folder can be found in $dialog.CurrentFolder
	$folder = $vault.DocumentService.GetFolderById($folderId)
	$path=$folder.FullName+"/"+$dialog.CurrentFolder.Name
	
	#recursively add subfolders to new folders that are not base category folders
	$UIString = mGetUIStrings
	$NewFolder = $vault.DocumentService.GetFolderByPath($path)
	if($NewFolder.Cat.Catname -eq $UIString["CAT6"])
	{
		#the new folder is the targetfolder to create subfolders, the source folder is the template to be used
		$TempFolderName = "$/00_Administration/00_ProjektStruktur/Kunde/Standort" + $NewFolder.Cat.Catname
		$tempFolder = $vault.DocumentService.GetFolderByPath($TempFolderName)
		If($tempFolder){ mRecursivelyCreateFolders -targetFolder $NewFolder -sourceFolder $tempFolder}
	}

	$selectionId = [Autodesk.Connectivity.Explorer.Extensibility.SelectionTypeId]::Folder
	$location = New-Object Autodesk.Connectivity.Explorer.Extensibility.LocationContext $selectionId, $path
	$vaultContext.GoToLocation = $location
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Library.ps1&lt;/P&gt;&lt;LI-CODE lang="general"&gt;function mRecursivelyCreateFolders($sourceFolder, $targetFolder)
{

	If(-not $Global:FldPropDefs){
		$Global:FldPropDefs = $vault.PropertyService.GetPropertyDefinitionsByEntityClassId("FLDR")
		$Global:FldPropDefIds = @()
		$Global:FldPropDefs| ForEach-Object {
			If($_.IsSys -eq $false)
			{
				$Global:FldPropDefIds += $_.Id
			}
		}
	}

    $sourceSubFolders = $vault.DocumentService.GetFoldersByParentId($sourceFolder.Id,$false)
	
		$mFldIdsArray = @() #collect the level's folder(s) Id(s)
		$propInstParamArrayArray = @()

		foreach ($folder in $sourceSubFolders) {
			$mSourceFldrProps = $vault.PropertyService.GetProperties("FLDR", @($folder.id) , $Global:FldPropDefIds)
		
			$mSourceUdpInstArray = @()
			$mSourceUdpInstArray += 	$mSourceFldrProps | Where-Object { $Global:FldPropDefIds -contains $_.PropDefId}	

			$newTargetSubFolder = $vault.DocumentServiceExtensions.AddFolderWithCategory($folder.Name, $targetFolder.Id, $folder.IsLibrary, $folder.Cat.CatId)
			$mFldIdsArray  += $newTargetSubFolder.Id
			
			$propInstParamArray = New-Object Autodesk.Connectivity.WebServices.PropInstParamArray #collect the folder's property instance arrays
		
			Foreach($Inst in $mSourceUdpInstArray)
			{
				$propInstParam = New-Object Autodesk.Connectivity.WebServices.PropInstParam
				$propInstParam.PropDefId	= $Inst.PropDefId
				$propInstParam.Val = $Inst.Val
				$propInstParamArray.Items += $propInstParam
			}
						
			$propInstParamArrayArray += $propInstParamArray
			mrecursivelyCreateFolders -targetFolder $newTargetSubFolder -sourceFolder $folder
		
			#returning to the initial level we can update the level folder's properties

		 }
		Try{
				$vault.DocumentServiceExtensions.UpdateFolderProperties($mFldIdsArray, $propInstParamArrayArray)
			}
			catch {}
} #end function mRecursivelyCreateFolders&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In dataStandardVaultlob.txt I get an error.&lt;/P&gt;&lt;P&gt;2021-05-06 22:06:41,655 [1] ERROR CreateObject.WPF.DSNumSchemeCtrl - DSNumSchemeCtrl_ValueChanged:System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.&lt;BR /&gt;bei Common.NumberingScheme.NumSchmService.GetNumSchmFields(NumSchm numSchm)&lt;BR /&gt;bei CreateObject.WPF.DSNumSchemeCtrl.DSNumSchemeCtrl_ValueChanged(Object sender, RoutedPropertyChangedEventArgs`1 e)&lt;BR /&gt;2021-05-06 22:06:46,497 [1] ERROR CreateObject.WPF.DSNumSchemeCtrl - Invalid numschm value. Only object of Type NumSchm are accepted as value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone give me a hint what i am doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 May 2021 20:34:44 GMT</pubDate>
    <dc:creator>RamOnWe</dc:creator>
    <dc:date>2021-05-06T20:34:44Z</dc:date>
    <item>
      <title>VDS create folder tree from template 2021</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/vds-create-folder-tree-from-template-2021/m-p/10296159#M3184</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I am still very new in customizing and just can't find the solution to my problem.&lt;BR /&gt;Currently I am trying to create a folder structure according to a template via VDS. Have already read some posts but it does not work yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My CreateFolder.ps1&lt;/P&gt;&lt;LI-CODE lang="general"&gt;$folderId=$vaultContext.CurrentSelectionSet[0].Id
$vaultContext.ForceRefresh = $true
$dialog = $dsCommands.GetCreateFolderDialog($folderId)

#override the default dialog file assigned
$xamlFile = New-Object CreateObject.WPF.XamlFile "ADSK.QS.Folder.xaml", "C:\ProgramData\Autodesk\Vault 2021\Extensions\DataStandard\Vault.Custom\Configuration\ADSK.QS.Folder.xaml"
$dialog.XamlFile = $xamlFile

$result = $dialog.Execute()
$dsDiag.Trace($result)

if($result)
{
	#new folder can be found in $dialog.CurrentFolder
	$folder = $vault.DocumentService.GetFolderById($folderId)
	$path=$folder.FullName+"/"+$dialog.CurrentFolder.Name
	
	#recursively add subfolders to new folders that are not base category folders
	$UIString = mGetUIStrings
	$NewFolder = $vault.DocumentService.GetFolderByPath($path)
	if($NewFolder.Cat.Catname -eq $UIString["CAT6"])
	{
		#the new folder is the targetfolder to create subfolders, the source folder is the template to be used
		$TempFolderName = "$/00_Administration/00_ProjektStruktur/Kunde/Standort" + $NewFolder.Cat.Catname
		$tempFolder = $vault.DocumentService.GetFolderByPath($TempFolderName)
		If($tempFolder){ mRecursivelyCreateFolders -targetFolder $NewFolder -sourceFolder $tempFolder}
	}

	$selectionId = [Autodesk.Connectivity.Explorer.Extensibility.SelectionTypeId]::Folder
	$location = New-Object Autodesk.Connectivity.Explorer.Extensibility.LocationContext $selectionId, $path
	$vaultContext.GoToLocation = $location
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Library.ps1&lt;/P&gt;&lt;LI-CODE lang="general"&gt;function mRecursivelyCreateFolders($sourceFolder, $targetFolder)
{

	If(-not $Global:FldPropDefs){
		$Global:FldPropDefs = $vault.PropertyService.GetPropertyDefinitionsByEntityClassId("FLDR")
		$Global:FldPropDefIds = @()
		$Global:FldPropDefs| ForEach-Object {
			If($_.IsSys -eq $false)
			{
				$Global:FldPropDefIds += $_.Id
			}
		}
	}

    $sourceSubFolders = $vault.DocumentService.GetFoldersByParentId($sourceFolder.Id,$false)
	
		$mFldIdsArray = @() #collect the level's folder(s) Id(s)
		$propInstParamArrayArray = @()

		foreach ($folder in $sourceSubFolders) {
			$mSourceFldrProps = $vault.PropertyService.GetProperties("FLDR", @($folder.id) , $Global:FldPropDefIds)
		
			$mSourceUdpInstArray = @()
			$mSourceUdpInstArray += 	$mSourceFldrProps | Where-Object { $Global:FldPropDefIds -contains $_.PropDefId}	

			$newTargetSubFolder = $vault.DocumentServiceExtensions.AddFolderWithCategory($folder.Name, $targetFolder.Id, $folder.IsLibrary, $folder.Cat.CatId)
			$mFldIdsArray  += $newTargetSubFolder.Id
			
			$propInstParamArray = New-Object Autodesk.Connectivity.WebServices.PropInstParamArray #collect the folder's property instance arrays
		
			Foreach($Inst in $mSourceUdpInstArray)
			{
				$propInstParam = New-Object Autodesk.Connectivity.WebServices.PropInstParam
				$propInstParam.PropDefId	= $Inst.PropDefId
				$propInstParam.Val = $Inst.Val
				$propInstParamArray.Items += $propInstParam
			}
						
			$propInstParamArrayArray += $propInstParamArray
			mrecursivelyCreateFolders -targetFolder $newTargetSubFolder -sourceFolder $folder
		
			#returning to the initial level we can update the level folder's properties

		 }
		Try{
				$vault.DocumentServiceExtensions.UpdateFolderProperties($mFldIdsArray, $propInstParamArrayArray)
			}
			catch {}
} #end function mRecursivelyCreateFolders&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In dataStandardVaultlob.txt I get an error.&lt;/P&gt;&lt;P&gt;2021-05-06 22:06:41,655 [1] ERROR CreateObject.WPF.DSNumSchemeCtrl - DSNumSchemeCtrl_ValueChanged:System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.&lt;BR /&gt;bei Common.NumberingScheme.NumSchmService.GetNumSchmFields(NumSchm numSchm)&lt;BR /&gt;bei CreateObject.WPF.DSNumSchemeCtrl.DSNumSchemeCtrl_ValueChanged(Object sender, RoutedPropertyChangedEventArgs`1 e)&lt;BR /&gt;2021-05-06 22:06:46,497 [1] ERROR CreateObject.WPF.DSNumSchemeCtrl - Invalid numschm value. Only object of Type NumSchm are accepted as value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone give me a hint what i am doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 20:34:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/vds-create-folder-tree-from-template-2021/m-p/10296159#M3184</guid>
      <dc:creator>RamOnWe</dc:creator>
      <dc:date>2021-05-06T20:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: VDS create folder tree from template 2021</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/vds-create-folder-tree-from-template-2021/m-p/10304364#M3185</link>
      <description>&lt;P&gt;Does the basic folder creation for a project category work? Does your Vault have a numbering scheme of the same name as the project category?&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 05:42:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/vds-create-folder-tree-from-template-2021/m-p/10304364#M3185</guid>
      <dc:creator>Markus.Koechl</dc:creator>
      <dc:date>2021-05-11T05:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: VDS create folder tree from template 2021</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/vds-create-folder-tree-from-template-2021/m-p/10320058#M3186</link>
      <description>&lt;P&gt;Hi Markus,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your reply and sorry for the late response.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I was able to solve my problem myself in the meantime. I have searched for the category on the wrong level.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CreateFolder.ps1&lt;/P&gt;&lt;LI-CODE lang="general"&gt;if($NewFolder.Cat.Catname -eq $UIString["CAT6"])#Category Project
	{
		#the new folder is the targetfolder to create subfolders, the source folder is the template to be used
		$TempFolderName = "$/00_Administration/05_FolderStructures/Customer/Location/" + $NewFolder.Cat.Catname
		$tempFolder = $vault.DocumentService.GetFolderByPath($TempFolderName)
		If($tempFolder){mRecursivelyCreateFolders -targetFolder $NewFolder -sourceFolder $tempFolder}
	}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"CAT6" is category named "Project" and below the ".../Location/" folder the temp folder category has to be "Project".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My mistake was that former I pointed to ".../Location/Project/".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So now everything is working fine.&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 06:53:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/vds-create-folder-tree-from-template-2021/m-p/10320058#M3186</guid>
      <dc:creator>RamOnWe</dc:creator>
      <dc:date>2021-05-18T06:53:04Z</dc:date>
    </item>
  </channel>
</rss>

