VDS create folder tree from template 2021

VDS create folder tree from template 2021

RamOnWe
Contributor Contributor
718 Views
2 Replies
Message 1 of 3

VDS create folder tree from template 2021

RamOnWe
Contributor
Contributor

Hello all,


I am still very new in customizing and just can't find the solution to my problem.
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.

 

My CreateFolder.ps1

$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
}

 

Library.ps1

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

 

In dataStandardVaultlob.txt I get an error.

2021-05-06 22:06:41,655 [1] ERROR CreateObject.WPF.DSNumSchemeCtrl - DSNumSchemeCtrl_ValueChanged:System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei Common.NumberingScheme.NumSchmService.GetNumSchmFields(NumSchm numSchm)
bei CreateObject.WPF.DSNumSchemeCtrl.DSNumSchemeCtrl_ValueChanged(Object sender, RoutedPropertyChangedEventArgs`1 e)
2021-05-06 22:06:46,497 [1] ERROR CreateObject.WPF.DSNumSchemeCtrl - Invalid numschm value. Only object of Type NumSchm are accepted as value.

 

Can someone give me a hint what i am doing wrong?

 

0 Likes
Accepted solutions (1)
719 Views
2 Replies
Replies (2)
Message 2 of 3

Markus.Koechl
Autodesk
Autodesk

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?



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 3 of 3

RamOnWe
Contributor
Contributor
Accepted solution

Hi Markus,

 

thanks for your reply and sorry for the late response. 


I was able to solve my problem myself in the meantime. I have searched for the category on the wrong level.

 

CreateFolder.ps1

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}
	}

 

"CAT6" is category named "Project" and below the ".../Location/" folder the temp folder category has to be "Project". 

 

My mistake was that former I pointed to ".../Location/Project/".

 

So now everything is working fine.

0 Likes