Concatenating Combo Box Selectedvaluepath value to data standard property!

Concatenating Combo Box Selectedvaluepath value to data standard property!

Anonymous
Not applicable
858 Views
1 Reply
Message 1 of 2

Concatenating Combo Box Selectedvaluepath value to data standard property!

Anonymous
Not applicable

Hello All, I have in my inventor.xaml file some combo boxes which are defined via a notepad that has the data structure of the properties. Within the data structure I have also included an associated ID to each type of data. For example Machine 1> Code:M1->Model A->Code MA. What I want is the codes to be concatendated such that after the series of combo boxes it would come to a code which is UD to be Code: M1MA. However the code I have set to do this concatenation is not working.

Here is the code for the default.ps1 file :


function InitializeWindow
{
 $dsWindow.Width = 600
 $dsWindow.Height = 400
 $Prop["Machine"].add_PropertyChanged({param( $parameter, $source) if($source.PropertyName -eq "Value") { Category_OnPropertyChanged }})
 $Prop["Model"].add_PropertyChanged({param( $parameter, $source) if($source.PropertyName -eq "Value") { AddDesc_OnPropertyChanged }}) 
 $mWindowName = $dsWindow.Name
 switch($mWindowName)
 {
  "InventorWindow"
  {
   #rules applying for Inventor   
  }
  "AutoCADWindow"
  {
   #rules applying for AutoCAD
  }
  default
  {
   #rules applying commonly
  }
 }
 if ($Prop["_CreateMode"].Value)
    {
        $mappedRootPath = $Prop["_VaultVirtualPath"].Value + $Prop["_WorkspacePath"].Value
     $mappedRootPath = $mappedRootPath -replace "\\", "/" -replace "//", "/"

        if ($mappedRootPath -eq '')
        {
            $mappedRootPath = '$'
        }
     $rootFolder = $vault.DocumentService.GetFolderByPath($mappedRootPath)
     $root = New-Object PSObject -Property @{ Name = $rootFolder.Name; ID=$rootFolder.Id } 
     AddCombo -data $root
    }
}
function AddinLoaded
{
 #Executed when DataStandard is loaded in Inventor
}
function AddinUnloaded
{
 #Executed when DataStandard is unloaded in Inventor
}

function GetNumSchms
{
 try
 {
  $numSchems = $vault.DocumentService.GetNumberingSchemesByType('Activated')
        if ($numSchems.Count -gt 0)
  {
   $list = New-Object 'System.Collections.Generic.List[System.Object]'
   foreach ($item in $numSchems)
   {
    if ($item.IsDflt)
    {
     $list.Insert(0,$item)
    }
    else
    {
     $list.Add($item)
    }
   }
   return $list
  }
 }
 catch [System.Exception]
 {  
  #[System.Windows.MessageBox]::Show($error)
 } 
}

function GetCategories
{
 if ($Prop["_CreateMode"].Value)
 {
     $cats = $vault.CategoryService.GetCategoriesByEntityClassId("FILE", $true)
        if ($cats.Count -gt 0)
        {
            $list = New-Object 'System.Collections.Generic.List[System.Object]'
   foreach ($item in $cats)
   {
    if ($item.Name -eq 'Engineering')
    {
     $list.Insert(0,$item)
    }
    else
    {
     $list.Add($item)
    }
   }
   return $list
        }       
 }
    if ($Prop["_EditMode"].Value)
 {
     return GetCategoryByFileName $Prop["_FileName"].Value
 }
}

function OnPostCloseDialog
{
 $mWindowName = $dsWindow.Name
 switch($mWindowName)
 {
  "InventorWindow"
  {
   #rules applying for Inventor
  }
  "AutoCADWindow"
  {
   #rules applying for AutoCAD
  }
  default
  {
   #rules applying commonly
  }
 }
}

function Category_OnPropertyChanged
{
$dsWindow.FindName("code").Content  = $Prop['Machine'].Value + " " + $Prop['Model'].Value
}

 

Highlighted in Red is where the code is present to do the concatenation!!!!!

 

 

Here is the invetor.xaml file where the properties are binded and defined:

<?xml version="1.0" encoding="utf-8"?>
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:WPF="clr-namespace:dataStandard.UI.View;assembly=dataStandard.UI"
              xmlns:system="clr-namespace:System;assembly=mscorlib"
               x:Name="InventorWindow"
               WindowStyle="ToolWindow"
               ShowInTaskbar="False"
               Topmost="True"
               MinWidth="880"
               MinHeight="540"
               Background="#F0F0F0">
    <WPF:DSWindow.Resources>
<XmlDataProvider x:Key="myData" Source="C:\ProgramData\Autodesk\Vault 2016\Extensions\DataStandard\CAD\Configuration\myData.xml"/>
 
                   
              >
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="8" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="8" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="8" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="8" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="8" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="8" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="8" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="8" />
                <RowDefinition Height="Auto" />
           <RowDefinition Height="8" />
                <RowDefinition Height="Auto" />
           <RowDefinition Height="8" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="140" />
                <ColumnDefinition Width="*"
                                  MinWidth="300" />
            </Grid.ColumnDefinitions>
        
            <Label Grid.Row="2"
                   Grid.Column="0"
                   Content="{Binding UIString[LBL10], FallbackValue=Number Scheme}" />
            <ComboBox Grid.Column="1"
                      Grid.Row="2"
                      x:Name="NumSchms"
                      DisplayMemberPath="Name"
                      SelectedIndex="0"
                      Style="{StaticResource NumSchmStyle}" />
            <Label Grid.Row="4"
                   Grid.Column="0"
                   Content="{Binding UIString[LBL31], FallbackValue=Number}" />
            <WPF:DSNumSchemeCtrl Grid.Row="4"
                                  Grid.Column="1"
                                  Scheme="{Binding SelectedItem, ElementName=NumSchms}"
                                  IsEnabled="{Binding IsEnabled, ElementName=NumSchms}"
                                  GeneratedNumberProperty="DocNumber" />
            <Label Content="{Binding UIString[LBL1], FallbackValue=Folder}"
                   Grid.Row="6"
                   Grid.Column="0"
                   Visibility="{Binding CreateMode, Converter={StaticResource BooleanToVisibilityConverter}}"/>
            <WrapPanel Name="BreadCrumb"
                       Grid.Column="1"
                       Grid.Row="6"
                       ItemWidth="165">
                <WrapPanel.Resources>
                    <Style TargetType="{x:Type ComboBox}">
                        <Setter Property="Margin" Value="0,5,15,0" />
                        <Setter Property="ToolTip" Value="{Binding Path=SelectedValue.Name, RelativeSource={RelativeSource Self}}"/>
                    </Style>
                </WrapPanel.Resources>
            </WrapPanel>
            <Label Content="*"
                   Grid.Column="0"
                   Grid.Row="6"
                   Foreground="#FF0000"
                   HorizontalAlignment="Right"
                   FontWeight="Bold"
                   Visibility="{Binding CreateMode, Converter={StaticResource BooleanToVisibilityConverter}}" />
            <Label Content="{Binding UIString[LBL2], FallbackValue=Title}"
                   Grid.Column="0"
                   Grid.Row="8" />
            <TextBox Text="{Binding Prop[Title].Value, UpdateSourceTrigger=PropertyChanged}"
                     Grid.Column="1"
                     Grid.Row="8"/>
            <Label Content="*"
                   Grid.Column="0"
                   Grid.Row="8"
                   Foreground="#FF0000"
                   HorizontalAlignment="Right"
                   FontWeight="Bold" />
            <Label Content="{Binding UIString[LBL3], FallbackValue=Description}"
                   Grid.Column="0"
                   Grid.Row="10" />
            <TextBox Text="{Binding Prop[Description].Value}"
                     Grid.Column="1"
                     Grid.Row="10"
                     x:Name="Description"
                     VerticalScrollBarVisibility="Auto"
                     MinHeight="50"
                     MaxHeight="50"
                     TextWrapping="Wrap"
                     AcceptsReturn="True" />
            <Label Content="{Binding UIString[LBL5], FallbackValue=Path}"
                   Grid.Column="0"
                   Grid.Row="12" />
            <TextBox Text="{Binding PathAndFileNameHandler.Path}"
                     Grid.Column="1"
                     Grid.Row="12"
                     IsReadOnly="True"
                     Background="#F0F0F0"
                     Margin="0,2" />


            <Label Content="Machine type" Grid.Row="14" Grid.Column="0" />
            <ComboBox Name="cmbMachType"
            SelectedValue="{Binding Prop[Machine].Value}"
                     Grid.Column="1"
                     Grid.Row="14"
ItemsSource="{Binding Mode=OneWay, Source={StaticResource myData}, XPath=/myData/Machine}" DisplayMemberPath="@type" SelectedValuePath="@code"/>
<Label Content="Model" Grid.Row="16" Grid.Column="0" />
            <ComboBox Name="cmbModel"
            SelectedValue="{Binding Prop[Model].Value}"
                     Grid.Column="1"
                     Grid.Row="16"
ItemsSource="{Binding SelectedItem, ElementName=cmbMachType}" DisplayMemberPath="@type" SelectedValuePath="@code"/>
<Label Content="code" Grid.Row="18" Grid.Column="0" />
        <TextBox Grid.Column="1" Grid.Row="18" Text="{Binding Prop[code].Value}"/>
<!--<Label Content="Code" Grid.Row="18" Grid.Column="0" />
            <TextBox Text="{Binding Prop[Code].Value}"
                     Grid.Column="1"
                     Grid.Row="18" /-->

            <Label Content="{Binding UIString[LBL6], FallbackValue=File Name}"
                   Grid.Row="20"
                   Grid.Column="0" />
            <TextBox Grid.Row="20"
                     Grid.Column="1"
                     x:Name="FILENAME"
                     Style="{StaticResource FileNameStyle}"
                     Margin="0,2" />

            <Label Content="*"
                   Grid.Column="0"
                   Grid.Row="20"
                   Foreground="#FF0000"
                   HorizontalAlignment="Right"
                   FontWeight="Bold"
                   Visibility="{Binding CreateMode, Converter={StaticResource BooleanToVisibilityConverter}}" />

        </Grid>
       
    </DockPanel>
</WPF:DSWindow>

 

Could someone please help me populate Code UD property in data standard. Right now the code is not being generated !! Kudos and a lot of thanks is given in advanced! p.s. I tried a lot of different ways to accomplish this:

 

scfreenshot1.PNG

0 Likes
859 Views
1 Reply
Reply (1)
Message 2 of 2

wangdu
Collaborator
Collaborator

hi,

 

Try this

 

function InitializeWindow
{
 $dsWindow.Width = 600
 $dsWindow.Height = 400
 $Prop["Machine"].add_PropertyChanged({param( $parameter, $source) if($source.PropertyName -eq "Value") { Machine_OnPropertyChanged }})
 $Prop["Model"].add_PropertyChanged({param( $parameter, $source) if($source.PropertyName -eq "Value") { Model_OnPropertyChanged }}) 
 $mWindowName = $dsWindow.Name
...
}

Machine_OnPropertyChanged and Model_OnPropertyChanged should both execute this same code

 

$Prop["code"].Value = "($Prop["Machine"].Value)  $($Prop["Model"].Value)"

As for why it works, because Prop[code].Value is bound to the Textbox's Text property and so everytime you change the value of the code property in the powershell like above, due to the binding the value is updated in the textbox. likewise, if you change the text by typing something, as it is bound to the code property, the code property will be having the typed value.

 

Hope it helps!

 

Wangdu

 

coolOrange

www.coolOrange.com

0 Likes