Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The coolDialog
function Show-MessageBox {
param(
$Title = "The cool Dialog",
[Parameter(Mandatory=$true)]
$Message,
[System.Windows.Forms.MessageBoxIcon]$Icon = "Information",
[System.Windows.Forms.MessageBoxButtons]$Buttons = "Ok"
)
[System.Windows.Forms.MessageBox]::Show($Message, $Title, $Buttons, $Icon) | Out-Null
}
try {
$folderId = $vaultContext.CurrentSelectionSet | select -First 1 -ExpandProperty "Id"
if(-not $folderId) {
throw "No valid folder selected!"
}
$fldr = $vault.DocumentService.GetFolderById($folderId)
$folder = New-Object Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.Folder -ArgumentList @($vaultConnection, $fldr)
[xml]$xamlContent = Get-Content "$($env:ProgramData)\Autodesk\Vault 2018\Extensions\DataStandard\Vault.Custom\addinVault\Menus\TheCoolDialog.xaml"
$theCoolWindow = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader -ArgumentList @($xamlContent)))
$theCoolWindow.FindName("StackPanelCoolView").DataContext = $folder
$theCoolWindow.FindName("BtnCool").add_Click({
$coolUserInput = $theCoolWindow.FindName("TxtCoolInput").Text
if($coolUserInput -notlike "*cool*") {
Show-MessageBox -Message "Your input was not cool!`nTry it again!" -Icon "Warning"
} else {
@(@($theCoolWindow) + $theCoolWindow.FindName("StackPanelCoolView").Children + $theCoolWindow.FindName("StackPanelCoolBtns").Children) | where { $_.GetType() -ne [system.windows.controls.stackpanel] } | foreach {
$isTextBox = $_.GetType() -eq [system.windows.controls.TextBox]
$_.BorderBrush = "White"
$_.Background = if($isTextBox) { "LightGoldenrodYellow" } else { "Orange"}
$_.Foreground = if($isTextBox) { "DarkOrange" } else { "White" }
}
Show-MessageBox -Message "Your input was $coolUserInput!"
}
})
$theCoolWindow.FindName("BtnCancel").add_Click({
$theCoolWindow.Close()
})
$theCoolWindow.ShowDialog() | Out-Null
} catch {
$errorMessage = "Error message: '$($_.Exception.Message)'`n`n`nSTACKTRACE:`n$($_.InvocationInfo.PositionMessage)`n`n$($_.ScriptStacktrace)"
Show-MessageBox -Message $errorMessage -Icon "Error"
}
<?xml version="1.0" encoding="utf-8"?>
<!--
Label: Label string for the command, must be quoted
Description: Description text for the menucommand. Must be quoted
Hint: Hint string, must be quoted
PSFile: Name of the *ps1 file that contains the powershell script to execute when the menu command is invoked, value must be quoted.
Image: Name of a bitmap file that contains the image for the menu command. Image should be 16x16 or 32x32, value must be quoted.
ToolbarPaintStyle: Controls how the item is drawn on toolbars, values are Text, Glyph, TextAndGlyph
NavigationTypes: comma separated list of entities for which this command should be active. Values are Bom, ChangeOrder, File, FileVersion, Folder, Item, Other
MultiSelectEnabled: If true, command is active for multiple selections, can be true or false
-->
<mymenu>
<MenuItem>
<NewTask Label="$UIString[MNU22]" Description="$UIString[MNU17]" Hint="$UIString[MNU18]"
PSFile="CreateCustomObject.ps1" Image="NewCustomObject.ico" ToolbarPaintStyle="TextAndGlyph"
NavigationTypes="Task" MultiSelectEnabled="False" />
<EditTask Label="$UIString[MNU21]" Description="$UIString[MNU19]" Hint="$UIString[MNU20]"
PSFile="EditCustomObject.ps1" Image="EditCustomObject.ico" ToolbarPaintStyle="TextAndGlyph"
NavigationTypes="Task" MultiSelectEnabled="False" />
<NewFile Label="$UIString[MNU1]" Description="$UIString[MNU11]" Hint="$UIString[MNU7]" PSFile="CreateFile.ps1"
Image="NewStandardFile.ico" ToolbarPaintStyle="TextAndGlyph" NavigationTypes="File,Folder"
MultiSelectEnabled="False" />
<EditFile Label="$UIString[MNU2]" Description="$UIString[MNU12]" Hint="$UIString[MNU8]" PSFile="EditFile.ps1"
Image="EditFileDatasheet.ico" ToolbarPaintStyle="TextAndGlyph" NavigationTypes="File"
MultiSelectEnabled="False" />
<NewFolder Label="$UIString[MNU3]" Description="$UIString[MNU13]" Hint="$UIString[MNU9]" PSFile="CreateFolder.ps1"
Image="NewStandardFolder.ico" ToolbarPaintStyle="TextAndGlyph" NavigationTypes="Folder"
MultiSelectEnabled="False" />
<EditFolder Label="$UIString[MNU4]" Description="$UIString[MNU14]" Hint="$UIString[MNU10]" PSFile="EditFolder.ps1"
Image="EditFolderDatasheet.ico" ToolbarPaintStyle="TextAndGlyph" NavigationTypes="Folder"
MultiSelectEnabled="False" />
<ShowLog Label="$UIString[MNU5]" Description="$UIString[MNU15]" Hint="$UIString[MNU5]" PSFile="ShowLog.ps1"
Image="Log.ico" ToolbarPaintStyle="TextAndGlyph" MultiSelectEnabled="False" />
<AboutDialog Label="$UIString[MNU6]" Description="$UIString[MNU16]" Hint="$UIString[MNU6]"
PSFile="ShowAboutDialog.ps1" Image="About.ico" ToolbarPaintStyle="TextAndGlyph"
MultiSelectEnabled="False" />
<CoolDialog Label="Make something cool" Description="Lets be cool" Hint="'Cool'" PSFile="MakeSomethingCool.ps1" Image="coolOrange.ico" ToolbarPaintStyle="TextAndGlyph" NavigationTypes="Folder" MultiSelectEnabled="False" />
</MenuItem>
<!--
Label: String displayed as the label, e.g. for submenus, quoted
DeployAsPulldown: If true, used as submenu, values are true or false
Location: Specifies the location of the command site within the Vault CLient UI, values are
StandardToolbar, AdvancedToolbar, BehaviorsToolbar, ItemBomToolbar,
FileMenu, EditMenu, ActionsMenu, ToolsMenu, HelpMenu, FileContextMenu, FolderContextMenu, ChangeOrderContextMenu, ItemContextMenu
Items: list with MenuItems. Name should be same as the element name defined in the MenuItem.
-->
<CommandSite>
<FileContext Label="myMenu" DeployAsPullDown="False" Location="FileContextMenu">
<Item Name="NewFile"></Item>
<Item Name="EditFile"></Item>
</FileContext>
<FolderContex Label="myMenu" DeployAsPullDown="False" Location="FolderContextMenu">
<Item Name="NewFile"></Item>
<Item Name="NewFolder"></Item>
<Item Name="EditFolder"></Item>
<Item Name="CoolDialog"></Item>
</FolderContex>
<StandardToolbar Label="myMenu" DeployAsPullDown="False" Location="StandardToolbar">
<Item Name="NewFile"></Item>
<Item Name="EditFile"></Item>
</StandardToolbar>
<ToolsMenu Label="myMenu" DeployAsPullDown="False" Location="ToolsMenu">
<Item Name="ShowLog"></Item>
</ToolsMenu>
<HelpMenu Label="myMenu" DeployAsPullDown="False" Location="HelpMenu">
<Item Name="AboutDialog"></Item>
</HelpMenu>
<CustomObject Label="Task" DeployAsPullDown="False" Location="Task">
<Item Name="NewTask"></Item>
<Item Name="EditTask"></Item>
</CustomObject>
</CommandSite>
<!--
Comma separated list
To suppress the command "New Library Folder" add the following two commands to the list below:
NewLibraryFolder,NewLibraryFolderForContextMenus
To suppress "Rename" for folder add this line:
Folder.Rename
-->
<SuppressMenuItems>
NewFolder,NewFolderGroupMenu,NewFolderGroupButton,NewFolderForContextMenus
</SuppressMenuItems>
</mymenu>
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ig="http://schemas.infragistics.com/xaml"
SizeToContent="WidthAndHeight"
Title="The coolDialog"
WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Margin"
Value="10" />
<Setter Property="Height"
Value="30" />
<Setter Property="FontSize"
Value="14" />
<Setter Property="Width"
Value="140" />
</Style>
<Style TargetType="{x:Type Label}">
<Setter Property="FontSize"
Value="12" />
</Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="FontSize"
Value="12" />
<Setter Property="Height"
Value="20" />
<Setter Property="Margin"
Value="5" />
</Style>
</Window.Resources>
<StackPanel Name="StackPanelCoolView">
<Label Content="Selected folder:" />
<TextBox Text="{Binding Path=FullName, Mode=OneWay}"
IsReadOnly="True" />
<Label Content="Insert a cool text:" />
<TextBox Text="Type something cool" x:Name="TxtCoolInput" />
<StackPanel Orientation="Horizontal" Name="StackPanelCoolBtns">
<Button Content="Make something cool"
TabIndex="1"
x:Name="BtnCool" />
<Button Content="Close"
TabIndex="2"
x:Name="BtnCancel" />
</StackPanel>
</StackPanel>
</Window>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment