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: 

Categorize files with API / Data Standards

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
785 Views, 2 Replies

Categorize files with API / Data Standards

Hello everyone,

 

thanks in advance for your help. We are trying to categorize files through Data Standards using not the username, but the User group. It is like that because the Company we are doing the Project has hundreds of users, and we can not create rules for every user. The function we are thinking about would follow the next steps:

 

1.- Get the username: "$vaultUsername"

2.- Get the Usergroup associated to this user: "$vaultUsergroup" or "GetGroupByName"?

3.- Write down the Group name in an iProperty

 

Then a rule in vault would categorize the file depending on the Usergroup.

 

Our Client is still using Inventor 2013 and because of that we cannot use Data Standards in Inventor, only in Vault.

 

I am a complete beginner in Data Standards and Vault API, and it's costing me tons of effort to get it. Do I need to capture the "Create" or "Checkin" Events? How sould the function look like?

 

Any help would be appreciated.

 

Kind regards.

 

Carlos caro

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

Hi Carlos, in order to get the groups assigned to the currently logged in user, this could be the API sequence, made in PowerShell

 

$userId = $vault.AdminService.SecurityHeader.UserId
$allGroups = $vault.AdminService.GetAllGroups()
$groupIds = @($allGroups | ForEach-Object {  $_.Id })
$groupInfos = $vault.AdminService.GetGroupInfosByGroupIds($groupIds)
$groups = @($groupInfos | Where-Object { $_.Users | Where-Object { $_.Id -eq $userId } }) | ForEach-Object { $_.Group.Name }

 what this code does is to take the userID from the current user by simply looking in one of the webservices inside the SecurityHeader. I use the AdminService, just because for the following rows the AdminServices is used again, but any service, except the InformationService, would do.

Then all the groups gets collected, the according group IDs collected into an array, and then detailed infos for the groups gets requested. Now that we have all information, we can filter through all groups and pic those where our user is in. 

the syntax above is a "short" form as it uses the command-lets where-object, foreach-object in combination with the pipeline ( | ). I personally love this syntax as it gets the stuff done in one line, but i admit that it took a while to get into. So here is the same code in more common syntax:

 

$userId = $vault.AdminService.SecurityHeader.UserId
$allGroups = $vault.AdminService.GetAllGroups()
$groupIds = @()
foreach ($group in $allGroups) {
	
	$groupIds += $group.Id
}
$groupInfos = $vault.AdminService.GetGroupInfosByGroupIds($groupIds)
$groups = @()
foreach ($groupInfo in $groupInfos) {
	foreach ($user in $groupInfo.Users) {
		if($user.Id -eq $userId)
		{
			$groups += $groupInfo.Group.Name
		}
	}
}

 I hope you see the benefits of the first syntax. You may wonder why in the first example line 5 and 7 the commands are embedded into @( …. ). The reason is that PowerShell tries to be kind and if an array returns just one value, instead of passing an array with one element, it returns the element it self. With the additional @( … ), what comes back is always an array, worst case with just one element.

 

And here we are at my first attention point for you. I guess that users might be member of several groups, so the code above will provide you with a list of the groups the user is in. So, which one is the right one? In case you say there is only one group, then the first (and only) should be fine. Here you go

 

$groups[0]

 

Now, this is the Vault API syntax. The question is now how to bring the group name into an Inventor iProperty. Data Standard can be quite handy here, as at every initial save the dialog comes up and allows you to execute code. Now, in the default.ps1 there is the InitializeWindow, which is a function called before the dialog shows up. So, here you could populate the properties as you wish.

So, you have to define your custom property in the Inventor.cfg, and then inside the InitializeWindow copy-paste the code above and set you property to the identified group.

 

$Prop["YouProperty"].Value = $groups[0]

 The Dialog will show up, the user will fill it in, but in the meantime your property has been already set. Once the file gets checked into Vault, and you've mapped the iProperty to a Vault property, your rules will do the same.

 

as you can see, it's not big stuff, it's just about understanding the mechanism of Data Standard. Actually, there will be a DS introduction session at AU, so worth passing by.

 

Of course, with CAD 2013 and no Data Standard the code above does not relly help. You could think of some iLogic code, or a little Inventor Add-In, but probably best is to move to newer Inventor, which problably is on your roadmap anyway.

 

Alternativelly there might be some Vault customiozation that would set the Group Property and then call ApplyRules, so that the catgory gets generated. However, i think Data Standard would be a good place for doing this stuff and more.

 

i hope this gives you an idea how to proceed.

 

ciao

marco

 

 

 

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

Hey Marco

 

 

is there something different in Data Standard 2016 / 2017?

 

 

In this line, nothing happens

 

$allGroups = $vault.AdminService.GetAllGroups()

Or is this a permission problem?

currently, my role is only user

 

 

Markus

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

Post to forums  

Autodesk Design & Make Report