Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Vault 2015 R2 and Power Shell, DataStrandard

2 REPLIES 2
Reply
Message 1 of 3
Denis99
858 Views, 2 Replies

Vault 2015 R2 and Power Shell, DataStrandard

Hello,

 

Im a beginner in the Vault customization with PowerShell. I must modify a little bit the Data Standard and I have a little problem with powerShell, When I open a .ps1 file for example the "Default.ps1", I will Test the function "GetNumSchms" but it doesn't works....What Must I do...?

 

 

Fail.png

 

Thank you very much!

Best regards.

2 REPLIES 2
Message 2 of 3
marco.mirandola
in reply to: Denis99

hi Denis, and welcome to Data Standard 😉

 

PowerShell executes so called Command-Lets, such as Set-Location for changing your current folder location, and the like. The scripts gets read from top to bottom. All the functions defined in the script gets first "acquired" and later executed if someone calls them.

Now, you call a function, such as the GetNumSchms but this function never has been "acquired" by the script engine, as the script never run. In order to do that, just select the complete function and on the context menu execute "Run selection". this way, the selected script will be executed. As the selection is a function, it will be only read into the memory. Now you can call your function from the command line.

 

You will notice that the function will throw an exception. The reason is that in that function you try to connect to Vault. the variable $vault should contain a connection to Vault. If the script is executed from within the context of Vault, or Inventor/AutoCAD, then the $vault is set, and also some other variables. 

If you like to test the function from the commandline, then you have to populate the $vault variable, and potentially some more.

 

For the case of the GetNumSchms, only the $vault must be set. In order to do that, go at the top of the default.ps1 file. you will find 3 commented lines like this:

#[System.Reflection.Assembly]::LoadFrom("C:\Program Files (x86)\Autodesk\Autodesk Vault 2015 SDK\bin\Autodesk.Connectivity.WebServices.dll")

#$cred = New-Object Autodesk.Connectivity.WebServicesTools.UserPasswordCredentials("localhost", "Vault", "Administrator", "")

#$vault = New-Object Autodesk.Connectivity.WebServicesTools.WebServiceManager($cred) 

 

the first line loads the WebServices DLL in order to connect to Vault. The second creates a variable with your login-credentials. The third populates the $vault variable with the connection information.

You can select each line one by one withouth the #, which is the comment symbol, and execute them. In case you dont have the WebServices.DLL, then install the Vault SDK from the Vault client folder.

 

After this, your PowerShell editor is connected to Vault and you can execute the command. I made a short video that http://www.screencast.com/t/LpS9UgR3HWu

 

addtitionaly you may have a look also to this video that shows how functions might be debugged: http://www.screencast.com/t/t7ke42PigE

on this link you will find other interesting videos on Data Standard.

 

i hope this helps.

 

ciao

marco

 

coolOrange
www.coolorange.com
Message 3 of 3
Denis99
in reply to: marco.mirandola

Hello,

 

First of all, thank you very much for the answears.

 

I have see the video you made, but I still having problems. When I try to run the first line ( I made it like you in the video, I select the line without the '#' and run the selected line) It gives me an error. ( I have version 1 in PowerShell I dont know if this is important or not)

Fail.png

 

I have installed the Vault SDK and I have the ..WebServices.dll

ruta.png

 

 

I dont know what the problem can be.

 

I have see all the videos you recommend me (Thank you so much there are very good) and I have a question, I must remove the "WPF:DSNumSchemeCtrl" and make something similar, the question is with the "Accept" button

<Button Content="{Binding UIString[BTN1]}" Command="{Binding CloseWindowCommand, ElementName=FileWindow}" IsEnabled="{Binding IsNotReadonly}" Grid.Column="1" HorizontalAlignment="Right" Width="80" ></Button>

 If I remove the DSNumSchemeCtrl, when I press the Button the "CloseWindowCommand" call the GenerateNumber function?

 

#define the parametrisation for the number generator here
function GenerateNumber
{
	$dsDiag.Trace(">> GenerateNumber")
	$selected = $dsWindow.FindName("NumSchms").Text
	if($selected -eq "") { return "na" }

	$ns = $global:numSchems | Where-Object { $_.Name.Equals($selected) }
	switch ($selected) {
		"Sequential" { $NumGenArgs = @(""); break; }
		default      { $NumGenArgs = @(""); break; }
	}
	$dsDiag.Trace("GenerateFileNumber($($ns.SchmID), $NumGenArgs)")
	$vault.DocumentService.GenerateFileNumber($ns.SchmID, $NumGenArgs)
	$dsDiag.Trace("<< GenerateNumber")
}

 

I Will that when you press the Button it calls the "GenerateNumber" function.

 

Thank you so much for all your help!

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report