Leverage Vault numbering schemes to enforce file names when a user creates a new Data Standard file.
In the installed sample, the Number Scheme combo box shows all activated numbering schemes. In the XAML file, the combo box is bound to a PowerShell function called GetNumSchms
.
The GetNumSchms
function makes it easy to control which schemes should be shown to the user.
Filtering Numbering Schemes in Inventor Based on File Type
Without Data Standard, the user can always select between all activated Vault numbering schemes. With the following implementation of GetNumSchms
, different schemes will be available for components (IPT, IAM) and drawings (IDW, IPN and DWG). To make the sample work, numbering schemes that start with COMP or DRAWING need to be defined in Vault:
C:\ProgramData\Autodesk\<Vault Version>\Extensions\DataStandard\CAD\addinVault\Default.ps1
...
function GetNumSchms
{
try
{
$numSchems = $vault.DocumentService.GetNumberingSchemesByType('activated')
}
catch [System.Exception]
{
#[System.Windows.MessageBox]::Show($error)
}
$filename = $Prop["DocNumber"].Value
$fileExt = [System.IO.Path]::GetExtension($filename)
$ret = @()
foreach ($item-in-$numschems)
{
if (($fileExt -eq ".iam" -or $fileExt -eq ".ipt") -and $item.Name.StartsWith("COMP"))
{
$ret += $item.Name
}
elseif (($fileExt -eq ".idw" -or $fileExt -eq ".ipn" -or $fileExt -eq ".dwg") -and $item.Name.StartsWith("DRAWING"))
{
$ret += $item.Name
}
}
return $ret
}
...
Consider you have the following numbering scheme called TestScheme.
Now you want to pre-pend the filename with a fixed text based on the selected document type:
ENG-
for Inventor assemblies and parts (e.g., ENG-A-00004.ipt)ENGDOC-
for AutoCAD/Inventor drawings and Inventor presentations (e.g., ENGDOC-B-00001.idw).OFF-
for all other files (e.g., OFF-C-00002.docx).When clicking OK in the Create File Dialog (New Standard File), the PowerShell function GetNewFileName
is called before adding the file to Vault. Here you have the chance to modify the filename and include information from other properties.
C:\ProgramData\Autodesk\<Vault Version>\Extensions\DataStandard\Vault\addinVault\Default.ps1
...
function GetNewFileName
{
$prefix = ""
if($dswindow.findname("NUMSCHEME").IsEnabled -eq $false)
{
$filename = $dswindow.findname("filename").Text
}
else{
$filename = $Prop["_GeneratedNumber"].Value
if (($Prop["_FileExt"].Value -eq ".ipt") -or ($Prop["_FileExt"].Value -eq ".iam"))
{
$prefix = "ENG-"
}
elseif (($Prop["_FileExt"].Value -eq ".dwg") -or ($Prop["_FileExt"].Value -eq ".idw") -or ($Prop["_FileExt"].Value -eq ".ipn"))
{
$prefix = "ENGDOC-"
}
else
{
$prefix = "OFF-"
}
}
$newfileName = $prefix + $filename + $Prop["_FileExt"].Value
return $newfileName
}
With Data Standard for Inventor and AutoCAD, you can configure a combination of property values and a generated number for the filename.
For example, let's say that you want to automatically create unique file names in the format of: N-<Title>-####.ipt where N- is always applied, <Title> is the user-entered Title property, #### is a number automatically generated, and .ipt is the file extension.
This can be done by modifying the element <FileNameDefinition>
in Inventor.cfg or the AutoCAD.cfg files.
C:\ProgramData\Autodesk\<Vault Version>\Extensions\DataStandard\CAD\Inventor.cfg
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<PathDefinition>{Workspace}\{Prop[Folder].Value}</PathDefinition>
<FileNameDefinition>N-{Prop[Title].Value}-{Prop[DocNumber].Value}</FileNameDefinition>
<PropertyDefinitions>
<PropertyDefinition PropertyName="DocNumber" DataType="Text" InitialValue="{PathAndFileNameHandler.FileName}" />
...
The property DocNumber
contains the generated number, because it is defined in attribute GeneratedNumberProperty="DocNumber"
in the DSNumSchemeCtrl
control of the Inventor.xaml file.
By removing the DSNumSchemeCtrl
and the NumSchms
combo box from the default File.xaml file, the user cannot select a numbering scheme anymore.
The following sample implementation of GetNewFileName
uses the numbering scheme TestScheme from above and the value entered in the Title as a parameter for the numbering scheme.
C:\ProgramData\Autodesk\<Vault Version>\Extensions\DataStandard\Vault\addinVault\Default.ps1
...
function GetNewFileName
{
$numSchemes = $vault.DocumentService.GetNumberingSchemesByType([Autodesk.Connectivity.WebServices.NumSchmType]::Activated)
$testNumScheme = $numSchemes | Where-Object { $_.Name.Equals("testscheme") }
$NumGenArgs = @()
$NumGenArgs += $Prop["Title"].Value
$genNum = $vault.DocumentService.GenerateFileNumber($testnumscheme.schmid,-$numgenargs)
return $genNum + $Prop["_FileExt"].Value
}
...
For Inventor and AutoCAD, the implementation is similar to the sample above. But instead of returning a filename, the property DocNumber
has to be filled with a generated number. This property is then used to set the name for the current file:
C:\ProgramData\Autodesk\<Vault Version>\Extensions\DataStandard\CAD\addinVault\Default.ps1
...
function OnPostCloseDialog
{
if ($Prop["_CreateMode"].Value)
{
$numSchemes = $vault.DocumentService.GetNumberingSchemesByType([Autodesk.Connectivity.WebServices.NumSchmType]::Activated)
$testNumScheme = $numSchemes | Where-Object { $_.Name.Equals("testscheme") }
$NumGenArgs = @()
$NumGenArgs += $Prop["Title"].Value
$genNum = $vault.DocumentService.GenerateFileNumber($testnumscheme.schmid,-$numgenargs)
$Prop["DocNumber"].Value = $genNum
}
}
...