Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DataStandard Folder Structure

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
Marcel.Decressin
2785 Views, 9 Replies

DataStandard Folder Structure

Hello,
is it possible to create a complete Folder structure when creating a new Folder with Data Standard?

Thanks.

9 REPLIES 9
Message 2 of 10

YES! does this answer your qeustion? 🙂

 

I guess, you r next question is how to do it, right?

You need some lines of code in your C:\ProgramData\Autodesk\Vault 2015\Extensions\DataStandard\Vault\addinVault\Menus\CreateFolder.ps1.

 

Now, it really depends on what you like to do. If you always have a fixes structure you may write the code directly in the PS1. file. If you have an existing folder tree you like to copy, you can do that. If you like to create the sub folders only for certain type of folders, then you have to test against your new created folder.

 

here is a simple example that creates a fixed subfolder underneath your folder:

 

Your script should look like this:

...
....
..

$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 [System.Reflection.Assembly]::LoadFrom("C:\Program Files\Autodesk\Vault Professional 2015\Explorer\Autodesk.Connectivity.Explorer.Extensibility.dll") $selectionId = [Autodesk.Connectivity.Explorer.Extensibility.SelectionTypeId]::Folder $location = New-Object Autodesk.Connectivity.Explorer.Extensibility.LocationContext $selectionId, $path $vaultContext.GoToLocation = $location }

 

i have added an additional line in order to create a subfolder called "test folder"

$result = $dialog.Execute()
$dsDiag.Trace($result)

if($result)
{
	#new folder can be found in $dialog.CurrentFolder
	$folder = $vault.DocumentService.GetFolderById($folderId)
	
	$subFolder = $vault.DocumentService.AddFolder("test folder",$dialog.CurrentFolder.Id,$false);
	
	$path=$folder.FullName+"/"+$dialog.CurrentFolder.Name

	[System.Reflection.Assembly]::LoadFrom("C:\Program Files\Autodesk\Vault Professional 2015\Explorer\Autodesk.Connectivity.Explorer.Extensibility.dll")
	$selectionId = [Autodesk.Connectivity.Explorer.Extensibility.SelectionTypeId]::Folder
	$location = New-Object Autodesk.Connectivity.Explorer.Extensibility.LocationContext $selectionId, $path
	$vaultContext.GoToLocation = $location
}

 The AddFolder API command requires a folder name, the ID of the parent folder and wether it should be a library folder or not. The ID of the currently created folder is inside the $dialog.CurrentFolder.Id. So, i create a new folder called "test folder" under the folder with the ID $dialog.CurrentFolder.Id, and it will be not a library.

you can repeat such line for the amount of folders you like, and you can create more nested subfolders by repeating the logic using the $subFolder.Id as the parent folder.

In my case, now every time i create a folder, a subfolder "test folder" will be created. I guess you probably will do this only in certain cases. With the  $dialog.CurrentFolder.Id you could get the complete folder object and test against the folder category, name, username, etc. and then decide if to create the sub folders or not. Of course you can also create the subfolder in the according category, with according properties, with links to other objects, copy some template files into such folder, etc.

 

I hope you have a feel for the reach. Now it's up to you to define what exactly you are looking for. It's doable, i'm pretty sure.

 

ciao

marco

 

coolOrange
www.coolorange.com
Message 3 of 10

Yes, my next question would have been how to do it. 😉
Thank you for your help. Your example works fine.
I think it could be a good Idea to copy an existing folder Structure from Vault. Like a template structure. And this only for new Folders within the category Project. Or maybe with a checkbox....(Create with structure Yes/no).

So my next question is, how to copy an existing folder structure?

I really appreciate your help.

Message 4 of 10
Message 5 of 10

Hi Marcel, I saw you've found the answer 😉 I thought your question is a good example to create a blog of. As it was a bit longer to emplain, a blog was more apropriate. It does not exactly reflect the way you described the problem, but i think this covers also you situation. The example can be tewaked and enhanced in many ways, so it's a good starting point.

 

happy reading: http://blog.coolorange.com/2014/10/17/create-folder-tree-from-a-template/

 

if you or others have other cool ideas, please share, as i think the more examples are available, the better all gets an understanding of the possibilities.

 

ciao

marco

 

coolOrange
www.coolorange.com
Message 6 of 10
Anonymous
in reply to: marco.mirandola

Marco,

I have read through your blog that you linked and I can get most of it to work.  Currently I get the drop down dialog box to show my template  choice properly.  When I execute the dialog box all it is copying is the first subfolder in the structure and not parsing through the rest.

I am sure I am missing something simple but it is escaping me at the moment.

 

Also I am using Data Standard 2016 if that makes any difference.

 

Maybe there is a better way to do this now.

Thanks,

Mark

Message 7 of 10
marco.mirandola
in reply to: Anonymous

Hi Mark, i just tested this on my Vault 2016 and it worked right away. You mentioned you've have the first level of folders comming up correctly, right? just the sub folders are not comming over? Do you have any error message in the log file under c:\temp\dataStandardVaultlog.txt?

 

What you can do is add 

$dsDiag.Trace($sourceFolder.FullName)

in the function recursivelyCreateFolders like this:

function recursivelyCreateFolders($targetFolder, $sourceFolder)
{
$dsDiag.Trace($sourceFolder.FullName)
     $sourceSubFolders = $vault.DocumentService.GetFoldersByParentId($sourceFolder.Id,$false)
     foreach ($folder in $sourceSubFolders) {
          $newTargetSubFolder = $vault.DocumentServiceExtensions.AddFolderWithCategory($folder.Name, $targetFolder.Id, $folder.IsLibrary, $folder.Cat.CatId)
          recursivelyCreateFolders -targetFolder $newTargetSubFolder -sourceFolder $folder
     }
}

This way, you can test in the log window (Tools>Show Data Standard...) wether the function goes recursively in the nested folders or not.

 

ciao

marco

 

coolOrange
www.coolorange.com
Message 8 of 10

Hi @marco.mirandola I'd love to use this customization to copy a template folder structure.

 

I've read through your blog but I'm not sure what code goes in what file. Could you help me identify where each section of code should go?

 

Thanks very much!



Craig Henderson
Inventor Pro 2018.3.3, Build 284 / Vault Pro 2018 / Visual Studio 2012 / Excel 2013
Message 9 of 10
RobJordan
in reply to: marco.mirandola

Hi Marco,

I have used the code from the coolorange 2014 blog for quite a while now and its brilliant. However it only seems to work on windows 10.

 

Windows 7 doesn't seem to work properly, it will only copy the first folder and subfolders, as per highlighted in this image...Example.JPG

 

The C:\Temp\dataStandardVaultlog.txt shows the following error message...

 

2018-11-21 09:38:00,384 [1] FATAL myMenu.PSMenuCommandItem - ExecuteHandler failed with exception
System.Management.Automation.ScriptCallDepthException: The script failed due to call depth overflow. The call depth reached 1001 and the maximum is 1000.
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.Runspaces.Pipeline.Invoke()
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke()
at myMenu.PSMenuCommandItem.ExecuteHandler(Object sender, CommandItemEventArgs args)

 

If you have seen this before and could advise on why it doesn't seem to work on windows 7, that would be great.

 

Also if you know a line of code that would also copy the files inside the folders at the same time, that would be great! 🙂

 

Kindest Regards

Rob

 

Message 10 of 10
Markus.Koechl
in reply to: RobJordan

You can upgrade Powershell on W7 to version 5.1: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell?view=power...

I am pretty sure that this will resolve the issue. 



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report