A Data Standard fellow from Australia came across with a nice, simple request. Would it be possible to have in the Data Standard dialog 2 combo-boxes where the user can pick from Vault folders and according subfolders? The answer is of course yes, and it’s not that much of work.
Basically we have to do 3 things:
- Add in the Inventor.cfg and/or AutoCAD.cfg 2 fields in order to store the selected folders, and use the 2 fields in the PathDefinition
- Add 2 combo-boxes in the Inventor.xaml and/or AutoCAD.xaml
- Add some logic in the PowerShell script in order to get the list for folders from Vault and present them in the Data Standard dialog
Let’s start with the CFG file. I added 2 properties called VaultProject and VaultSubFolder, and I extended the PathDefinition with such properties. Here the code:
<Configuration> <PathDefinition>{Workspace}\{Prop[VaultProject].Value}\{Prop[VaultSubFolder].Value}</PathDefinition> <FileNameDefinition>{Prop[VaultSubFolder].Value}</FileNameDefinition> <PropertyDefinitions> <PropertyDefinition PropertyName="VaultProject" DataType="Text" RequiresValue="true" /> <PropertyDefinition PropertyName="VaultSubFolder" DataType="Text" RequiresValue="true" /> .... </PropertyDefinitions> .... </Configuration>
Then I added the 2 combo-boxes into the XAML file. In order to position the combo-boxes at the right place, I had to add more rows in the parent Grid and reposition the existing controls. More information on XAML can be found here. And here is the code in the XAML.
<Grid Margin="25"> .... <Label Content="Vault Projects" Grid.Column="0" Grid.Row="6" /> <ComboBox Grid.Column="1" Grid.Row="6" ItemsSource="{Binding PsList[GetVaultProjects]}" SelectedValue="{Binding Prop[VaultProject].Value}" /> <Label Content="Vault SubFolders" Grid.Column="0" Grid.Row="8" /> <ComboBox Grid.Column="1" Grid.Row="8" SelectedValue="{Binding Prop[VaultSubFolder].Value}" x:Name="cmbVaultSubFolders"/> ...
As you can see, both combos have the SelectedValue bound to the according property, but only the first combo has an ItemsSource, bound to a PowerShell function.
Finally I wrote 2 little functions that pick folders from Vault. This is how my Default.ps1 looks like:
function InitializeWindow { ... $Prop["VaultProject"].add_PropertyChanged({ param($parameter,$source) if($source.PropertyName -eq "Value") { GetVaultSubFolders } }) ... } function GetVaultProjects { $folder = $vault.DocumentService.GetFolderByPath("$/Designs") $folders = $vault.DocumentService.GetFoldersByParentId($folder.Id,$false) $projects = $folders | Where-Object { $_.Cat.CatName -eq "Project" } $names = @() $projects | ForEach-Object { $names += $_.Name } return $names } function GetVaultSubFolders { $selectedProject = $Prop["VaultProject"].Value if($selectedProject -eq "") { return } $folder = $vault.DocumentService.GetFolderByPath("$/Designs/"+$selectedProject) $folders = $vault.DocumentService.GetFoldersByParentId($folder.Id,$false) $names = @() $folders | ForEach-Object { $names += $_.Name } $dSWindow.FindName("cmbVaultSubFolders").ItemsSource = $names }
The first function gets all folders underneath $/Designs in category project. The second function gets the subfolders of the in the first combo selected folder, and sets the ItemsSource of the second combo programmatically. Now, as the second combo shall show different folders based on the folder selected in the first combo, as the user picks a folder in the first combo, the second function must be executed. That is why I added an event handler for the property VaultProject. So, every time the VaultProject changes, the function is executed and the second combo gets appropriate values.
And here is a zip file of the CAD folder, which contains CFG, XAML and PS1.
That’s it! Try it out and leave a comment if you like it, or want to know more!
Hi,
Thank’s for this example.
I have tested and it don’t work properly. The file name is not correct.
The is False. The right value is {Prop[DocNumber].Value}.
Sory for my English…. :)
Regards
Dom
And another thing,
What happens when there will be more subfolders. For example 5-10
Regards
Dom
Hi,
I try to convert this code for Data Standard 2015 R2, but I dont know really how.
Plase can help me someone!
Thanks!!
Regrads
Thomas
Same here i can’t get it working for 2015 R2.
Hi,
I just tried it but combo boxes came empty. What could be the possible cause? Here is the screenshot;
Here is my folder structure in Vault;
Am I missing a setting?
Cheers,
Volkan
P.S. I’m using Vault Professional 2015
Hi,
I’m sorry, it’s my mistake. I copied the “Default.ps1” file to “C:\ProgramData\Autodesk\Vault 2015\Extensions\DataStandard\CAD\addins” and it worked like a charm.
Thank you very much for the post by the way. :)
Volkan
Hi,
I have the same Problem with empty boxes.
I copied the Deafailt.ps1 file to C:\ProgramData\Autodesk\Vault 2015\Extensions\DataStandard\CAD\addins and they are still empty.
What’s wrong?
Thanks,
Svjetlana