Display Integer Values as Mapped Text Values on Datasheet

Display Integer Values as Mapped Text Values on Datasheet

pmartick
Advocate Advocate
98 Views
3 Replies
Message 1 of 4

Display Integer Values as Mapped Text Values on Datasheet

pmartick
Advocate
Advocate

Inventor/Vault 2026.3

 

In my Datasheet I have three Dynamic Properties that are used for mapping with our ERP software. The property values that are mapped to ERP only accept integer values instead of user-friendly text so that's how these properties have to be set up.

 

What I would like to do with the Datasheet is set up the XAML/PowerShell to display the integer values as the equivalent text values on the Datasheet but still update the actual properties with the proper integer values in the background.

 

ETO Category:

  • 400 = "Fabrication"
  • 100 = "Purchased - Mechanical"
  • 110 = "Purchased - Controls/Electrical"
  • 200 = "Pump & Valves: Dept. 26"

UOM:

  • 1 = "AS"
  • 2 = "PC"
  • 11 = "FT"
  • -1 = "SA"

BOM Assembly Release:

  • 1 = "Contents of Assembly Only"
  • 2 = "Assembly Only"
  • 3 = "Both Assembly and Contents"

 

I believe I am on the right path already in trying to use a class with Value as the integer and DisplayValue as the string but so far am unable to get the data trigger combobox to accept it.

 

<DataTrigger Binding="{Binding Name}" Value="ETO_Category">
 <Setter Property="Template">
  <Setter.Value>
   <ControlTemplate>
    <ComboBox ItemsSource="{Binding ETOCollection}" DisplayMemberPath="DisplayValue"/>
   </ControlTemplate>
  </Setter.Value>
 </Setter>
</DataTrigger>

 

Public Class ETOClass {
	Public int Value { get; set; }
	Public string DisplayValue { get; set; }
}

Public ETOList<ETOClass> ETOCollection {
	get {
		return new ETOList<ETOClass> {
			new ETOClass { Value = 400, DisplayValue = "Fabrication" },
			new ETOClass { Value = 100, DisplayValue = "Purchased - Mechanical" },
			new ETOClass { Value = 110, DisplayValue = "Purchased - Controls/Electrical" },
			new ETOClass { Value = 200, DisplayValue = "Pump & Valves: Dept. 26" }
		}
	}
}

 

Is there something I'm missing, or should I use an entirely different method to achieve the same goal?

 

Thanks.

0 Likes
Accepted solutions (2)
99 Views
3 Replies
Replies (3)
Message 2 of 4

pmartick
Advocate
Advocate

After a couple days of R&D I did figure out how to achieve this on the Inventor side but not on the Vault side.

 

On the Inventor side I customized Default.ps1 to replace the ListValues of the three properties during the InitializeWindow function:

$Prop["ETO_Category"].ListValues = @("Fabrication", "Purchased - Mechanical", "Purchased - Controls/Electrical", "Pump & Valves: Dept. 26")
$Prop["UOM"].ListValues = @("AS", "PC", "FT", "SA")
$Prop["BOMAssemblyReleaseId"].ListValues = @("Contents of Assembly Only", "Assembly Only", "Both Assembly and Contents")

 

During the InitializeCategory function for each property I tried looking in the custom iProperties of the file to see if there's an already existing value and update the property in the datasheet if found:

try {
	switch ($Document.PropertySets.Item("Inventor User Defined Properties").Item("ETO_Category").Value) {
		400 { $Prop["ETO_Category"].Value = "Fabrication" }
		100 { $Prop["ETO_Category"].Value = "Purchased - Mechanical" }
		110 { $Prop["ETO_Category"].Value = "Purchased - Controls/Electrical" }
		200 { $Prop["ETO_Category"].Value = "Pump & Valves: Dept. 26" }
	}
}
catch {}
try {
	switch ($Document.PropertySets.Item("Inventor User Defined Properties").Item("UOM").Value) {
		1 { $Prop["UOM"].Value = "AS" }
		2 { $Prop["UOM"].Value = "PC" }
		11 { $Prop["UOM"].Value = "FT" }
		-1 { $Prop["UOM"].Value = "SA" }
	}
}
catch {}
try {
	switch ($Document.PropertySets.Item("Inventor User Defined Properties").Item("BOMAssemblyReleaseId").Value) {
		1 { $Prop["BOMAssemblyReleaseId"].Value = "Contents of Assembly Only" }
		2 { $Prop["BOMAssemblyReleaseId"].Value = "Assembly Only" }
		3 { $Prop["BOMAssemblyReleaseId"].Value = "Both Assembly and Contents" }
	}
}
catch {}

 

This will present those properties in the datasheet with the translated values.

 

If there are any automations that require updating the selected value of the translated properties then check for and update with the translated values, not the original.

For example, use:

if ($Prop["BOMAssemblyReleaseId"].Value -ne "Assembly Only") { $Prop["BOMAssemblyReleaseId"].Value = "Assembly Only" }

Not:

if ($Prop["BOMAssemblyReleaseId"].Value -ne 2) { $Prop["BOMAssemblyReleaseId"].Value = 2 }

 

If those properties have a required set of ListValues in Vault, then you will need to add custom validation scripts just the same as adding a custom PartNumberValidation script just like in the VDS Tutorials adding the InitializeValidation function to the InitializeWindow function of Default.ps1

function InitializeETOValidation {
    try {
        if ($dsWindow.Name -eq 'InventorWindow') {
            $global:mETOProperty = "ETO_Category"
            $global:mUOMProperty = "UOM"
            $global:mBOMProperty = "BOMAssemblyReleaseId"
        }
        $Prop["$($global:mETOProperty)"].CustomValidation = { ValidateETONumber }
        $Prop["$($global:mUOMProperty)"].CustomValidation = { ValidateUOMNumber }
        $Prop["$($global:mBOMProperty)"].CustomValidation = { ValidateBOMNumber }
    }
    catch {}
}

function ValidateETONumber {
    switch ($Prop["ETO_Category"].Value) { { $_ -in "Fabrication", "Purchased - Mechanical", "Purchased - Controls/Electrical", "Pump & Valves: Dept. 26" } { return $true } }
}

function ValidateUOMNumber { switch ($Prop["UOM"].Value) { { $_ -in "AS", "PC", "FT", "SA" } { return $true } } }

function ValidateBOMNumber {
    switch ($Prop["BOMAssemblyReleaseId"].Value) { { $_ -in "Contents of Assembly Only", "Assembly Only", "Both Assembly and Contents" } { return $true } }
}

 

Finally, in the OnPostCloseDialog function you translate the text values back to the required integer values:

switch ($Prop["ETO_Category"].Value) {
	"Fabrication" { $Prop["ETO_Category"].Value = 400 }
	"Purchased - Mechanical" { $Prop["ETO_Category"].Value = 100 }
	"Purchased - Controls/Electrical" { $Prop["ETO_Category"].Value = 110 }
	"Pump & Valves: Dept. 26" { $Prop["ETO_Category"].Value = 200 }
}
switch ($Prop["UOM"].Value) {
	"AS" { $Prop["UOM"].Value = 1 }
	"PC" { $Prop["UOM"].Value = 2 }
	"FT" { $Prop["UOM"].Value = 11 }
	"SA" { $Prop["UOM"].Value = -1 }
}
switch ($Prop["BOMAssemblyReleaseId"].Value) {
	"Contents of Assembly Only" { $Prop["BOMAssemblyReleaseId"].Value = 1 }
	"Assembly Only" { $Prop["BOMAssemblyReleaseId"].Value = 2 }
	"Both Assembly and Contents" { $Prop["BOMAssemblyReleaseId"].Value = 3 }
}

 

However, I am now getting stuck on how to do this on the Vault side. I've figured out how to replace the ListValues and the currently selected value with the translated text values but I cannot figure out how to translate them back to the integer value when the OK button is pressed. In fact, clicking OK doesn't update any property changes at all so there's an error somewhere that's preventing value updates to get pushed back into the vault file.

 

Default.ps1:

function InitializeWindow {	
	#begin rules applying commonly
	InitializeWindowTitle
	InitializeNumSchm
	InitializeCategory
	InitializeNameValidation
	#end rules applying commonly
	$mWindowName = $dsWindow.Name
	switch ($mWindowName) {
		"FileWindow" {
			#rules applying for File
			$dsWindow.FindName("TemplateCB").add_SelectionChanged({ OnTemplateChanged })
			#enable custom validation for Part Number property
			InitializePartNumberValidation
			InitializeETOValidation
			$Prop["ETO_Category"].ListValues = @("Fabrication", "Purchased - Mechanical", "Purchased - Controls/Electrical", "Pump & Valves: Dept. 26")
			$Prop["UOM"].ListValues = @("AS", "PC", "FT", "SA")
			$Prop["BOMAssemblyReleaseId"].ListValues = @("Contents of Assembly Only", "Assembly Only", "Both Assembly and Contents")
			switch ($Prop["ETO_Category"].Value) {
				400 { $Prop["ETO_Category"].Value = "Fabrication" }
				100 { $Prop["ETO_Category"].Value = "Purchased - Mechanical" }
				110 { $Prop["ETO_Category"].Value = "Purchased - Controls/Electrical" }
				200 { $Prop["ETO_Category"].Value = "Pump & Valves: Dept. 26" }
			}
			switch ($Prop["UOM"].Value) {
				1 { $Prop["UOM"].Value = "AS" }
				2 { $Prop["UOM"].Value = "PC" }
				11 { $Prop["UOM"].Value = "FT" }
				-1 { $Prop["UOM"].Value = "SA" }
			}
			switch ($Prop["BOMAssemblyReleaseId"].Value) {
				1 { $Prop["BOMAssemblyReleaseId"].Value = "Contents of Assembly Only" }
				2 { $Prop["BOMAssemblyReleaseId"].Value = "Assembly Only" }
				3 { $Prop["BOMAssemblyReleaseId"].Value = "Both Assembly and Contents" }
			}
		}
		#rules applying for Folder
		"FolderWindow" {}
		#rules applying for Custom Object
		"CustomObjectWindow" {}
	}
}

 

ETOValidation.ps1:

function InitializeETOValidation {
    try {
        if ($dsWindow.Name -eq 'FileWindow') {
            $global:mETOProperty = "ETO_Category"
            $global:mUOMProperty = "UOM"
            $global:mBOMProperty = "BOMAssemblyReleaseId"
        }
        $Prop["$($global:mETOProperty)"].CustomValidation = { ValidateETONumber }
        $Prop["$($global:mUOMProperty)"].CustomValidation = { ValidateUOMNumber }
        $Prop["$($global:mBOMProperty)"].CustomValidation = { ValidateBOMNumber }
    }
    catch {}
}

function ValidateETONumber {
    switch ($Prop["ETO_Category"].Value) { { $_ -in "Fabrication", "Purchased - Mechanical", "Purchased - Controls/Electrical", "Pump & Valves: Dept. 26" } { return $true } }
}

function ValidateUOMNumber { switch ($Prop["UOM"].Value) { { $_ -in "AS", "PC", "FT", "SA" } { return $true } } }

function ValidateBOMNumber {
    switch ($Prop["BOMAssemblyReleaseId"].Value) { { $_ -in "Contents of Assembly Only", "Assembly Only", "Both Assembly and Contents" } { return $true } }
}

 

There is no OnPostCloseDialog function in the Default.ps1 file where this could be useful. According to the tutorial I'm supposed to copy "DataStandard\Vault\addinVault\Menus\EditFile.ps1" over to the matching location in the Vault.Custom folder and make edits but I'm having trouble finding any examples on how or where to make edits to property values after the OK button is clicked.

0 Likes
Message 3 of 4

Markus.Koechl
Autodesk
Autodesk
Accepted solution

You can evaluate these two options for Vault:
1) implement your own OnPostClose function. Replace the command behind the OK button with the call of your OnPostClose function and close the dialog as a last step.

XAML:
Command="{Binding PsCmd[myOnPostCloseDialog]}"
function myOnPostCloseDialog()
{
	#region of postclose actions
		
	#endregion of postclose actions

	$dsWindow.CloseWindowCommand.Execute($this)
}

 2) leverage the built-in OnPostClose scripts ..\Menus\CreateFile.ps1 and ..\EditFile.ps1. As these run in a separate PS runspace you need to handover your values, e.g., using a text file. You can find sample implementations here (its a folder post close sample, but you will get the principle): VDS-Sample-Configurations-2027/VDS-PDMC-Sample/Vault.Custom/addinVault/Menus/ADSK.QS.CreateFolder.ps.... A dialog closed with OK returns $result = true.



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
Message 4 of 4

pmartick
Advocate
Advocate
Accepted solution

I tested just changing the XAML OK command to the powershell function and before executing the CloseWindowCommand translated the string values back to integers and it worked just fine without having to implement the handoff script you mentioned. This may be needed for others if creating new Inventor files in Vault is part of their workflow, but I'm only interested in editing and viewing existing file properties through Vault at this time since we always create new Inventor files through Inventor.

 

File.xaml:

<Button x:Name="btnOK" Content="{Binding UIString[BTN1], FallbackValue=OK}"
                    Command="{Binding PsCmd[OnPostCloseDialog]}"
                    Width="80" Height="24" IsDefault="True" Margin="0,0,10,0">

 

Default.ps1:

function OnPostCloseDialog {
	switch ($Prop["ETO_Category"].Value) {
		"Fabrication" { $Prop["ETO_Category"].Value = 400 }
		"Purchased - Mechanical" { $Prop["ETO_Category"].Value = 100 }
		"Purchased - Controls/Electrical" { $Prop["ETO_Category"].Value = 110 }
		"Pump & Valves: Dept. 26" { $Prop["ETO_Category"].Value = 200 }
	}
	switch ($Prop["UOM"].Value) {
		"AS" { $Prop["UOM"].Value = 1 }
		"PC" { $Prop["UOM"].Value = 2 }
		"FT" { $Prop["UOM"].Value = 11 }
		"SA" { $Prop["UOM"].Value = -1 }
	}
	switch ($Prop["BOMAssemblyReleaseId"].Value) {
		"Contents of Assembly Only" { $Prop["BOMAssemblyReleaseId"].Value = 1 }
		"Assembly Only" { $Prop["BOMAssemblyReleaseId"].Value = 2 }
		"Both Assembly and Contents" { $Prop["BOMAssemblyReleaseId"].Value = 3 }
	}
	$dsWindow.CloseWindowCommand.Execute($this)
}

 

For those who are interested, here's how I got this to work with the Datasheet tab in the Vault viewer:

The OnTabContextChanged function in Default.ps1 is what runs whenever a file is selected. Put the same property validation initialization and property value translator code inside an if condition looking for selection context to be FileMaster and the name of the xaml file to be Datasheet.xaml

$xamlFile = ([System.IO.FileInfo]::new($VaultContext.UserControl.XamlFile)).Name
if ($VaultContext.SelectedObject.TypeId.SelectionContext -eq "FileMaster" -and $xamlFile -eq "Datasheet.xaml") {
	InitializeETOValidation
	try {
		switch ($Prop["ETO_Category"].Value) {
			400 { $Prop["ETO_Category"].Value = "Fabrication" }
			100 { $Prop["ETO_Category"].Value = "Purchased - Mechanical" }
			110 { $Prop["ETO_Category"].Value = "Purchased - Controls/Electrical" }
			200 { $Prop["ETO_Category"].Value = "Pump & Valves: Dept. 26" }
		}
	}
	catch {}
	try {
		switch ($Prop["UOM"].Value) {
			1 { $Prop["UOM"].Value = "AS" }
			2 { $Prop["UOM"].Value = "PC" }
			11 { $Prop["UOM"].Value = "FT" }
			-1 { $Prop["UOM"].Value = "SA" }
		}
	}
	catch {}
	try {
		switch ($Prop["BOMAssemblyReleaseId"].Value) {
			1 { $Prop["BOMAssemblyReleaseId"].Value = "Contents of Assembly Only" }
			2 { $Prop["BOMAssemblyReleaseId"].Value = "Assembly Only" }
			3 { $Prop["BOMAssemblyReleaseId"].Value = "Both Assembly and Contents" }
		}
	}
	catch {}
}

 

I also had to update my ETOValidation.ps1 script to work for both FileWindow and MainWindow so the property validation runs on the Datasheet viewer and the Edit Datasheet window to not false flag validation errors.

function InitializeETOValidation {
    try {
        switch ($dsWindow.Name) {
            { $_ -in 'FileWindow', 'MainWindow' } {
                $global:mETOProperty = "ETO_Category"
                $global:mUOMProperty = "UOM"
                $global:mBOMProperty = "BOMAssemblyReleaseId"
            }
        }
        $Prop["$($global:mETOProperty)"].CustomValidation = { ValidateETONumber }
        $Prop["$($global:mUOMProperty)"].CustomValidation = { ValidateUOMNumber }
        $Prop["$($global:mBOMProperty)"].CustomValidation = { ValidateBOMNumber }
    }
    catch {}
}

 

pmartick_1-1786551688914.png

 

Thanks @Markus.Koechl as always!

0 Likes