Generate Permanent Link of Entities in Vault and Open in Thin Client

By Daniel Du

You probablay have noticed that Vault 2014 releases a new client – Thin Client with completely new UI. It is really a light one, you do not need to install anything on client side, a broswer is good enough. Thin Client performs read-access tasks in a vault, such as searching the vault and viewing file history using a web browser. If you have not noticed this, try it now, goto http://servername/AutodeskTC in your broswer, where servername is either the IP address or the name of the computer hosting Autodesk Data Management Server.

In this post, I will introduce how to integerate Vault Explorer and Vault ThinClient. I will create a Vault Explorer plugin, which enable users to right click a file or folder in Explorer and view it in Vault ThinClient. This is a just a demonstration, you may have better idea to use this permanent link, for example, save it into your database or ERP systems. In Autodesk Vault 2014 API, KnowledgeVaultService provides functions to get/set the persistent ID of entities. GetPersistentIds and ResolvePersistentIds in the KnowledgeVaultService are the functions to use for converting between file IDs and the persistent IDs. Keep in mind that there are two types of persistent IDs for files. If EntPersistOpt is History, the Persistent ID is for a specific file version. If EntPersistOpt is Latest, the Persistent ID is for the latest version of the file. The caller has to know which type to use. There is no way to tell the type by looking at the Persistent ID itself. Another tricky part is that, the PersistentId retrieved from Vault API is not the exact id of ThinClient URL, here is the core snippet of generating url of files and folders in ThinClient:

string[] ids = webMgr.KnowledgeVaultService.GetPersistentIds(
    VDF.Vault.Currency.Entities.EntityClassIds.Files,
    new long[] { file.Id },
    Autodesk.Connectivity.WebServices.EntPersistOpt.Latest);

string id = ids[0];
id = id.TrimEnd('=');
url = string.Format("{0}://{1}/AutodeskTC/{1}/{2}#/Entity/Details?id=m{3}=&itemtype=File",
    serverUri.Scheme, serverUri.Host, currentConnection.Vault, id);
string[] ids = webMgr.KnowledgeVaultService.GetPersistentIds(
    VDF.Vault.Currency.Entities.EntityClassIds.Folder,
    new long[] { folder.Id },
    Autodesk.Connectivity.WebServices.EntPersistOpt.Latest);

string id = ids[0];
id = id.TrimEnd('=');
url = string.Format("{0}://{1}/AutodeskTC/{1}/{2}#/Entity/Entities?folder=m{3}=&start=0",
    serverUri.Scheme, serverUri.Host, currentConnection.Vault, id);

Please note that there is “m” in front of the persistent ID, which may confuse you, but it is how it works :) Following is the complete code for this plugin:

using Autodesk.Connectivity.Explorer.Extensibility;
using Autodesk.Connectivity.Extensibility.Framework;
using Autodesk.Connectivity.WebServices;
using Autodesk.Connectivity.WebServicesTools;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
using VDF = Autodesk.DataManagement.Client.Framework;

[assembly: ApiVersion("6.0")]
[assembly: ExtensionId("76491449-B3FB-4570-81C4-17FE48BF50CB")]

namespace ThinClientUrlExtension
{
    public class ThinClientUrlGenerator : IExplorerExtension
    {
        VDF.Vault.Currency.Connections.Connection currentConnection;

        public IEnumerable CommandSites()
        {
            CommandItem ThinClientUrlCmd = new CommandItem(
                "Autodesk.ADN.PermaLink", "View in Thin Client...")
            {
                NavigationTypes = new SelectionTypeId[] {
                    SelectionTypeId.File,
                    SelectionTypeId.FileVersion,
                    SelectionTypeId.Folder
                },
                MultiSelectEnabled = false
            };

            ThinClientUrlCmd.Execute += ThinClientUrlCmd_Execute;
            CommandSite permaLinkFileContextSite = new CommandSite(
                "Autodesk.ADN.PermaLinkFileContext", "PermaLinkFileContext")
            {
                DeployAsPulldownMenu = false,
                Location = CommandSiteLocation.FileContextMenu
            };
            permaLinkFileContextSite.AddCommand(ThinClientUrlCmd);

            CommandSite permaLinkFolderContextSite = new CommandSite(
                "Autodesk.ADN.PermaLinkFolderContext", "PermaLinkFolderContext")
            {
                DeployAsPulldownMenu = false,
                Location = CommandSiteLocation.FolderContextMenu
            };
            permaLinkFolderContextSite.AddCommand(ThinClientUrlCmd);

            List sites = new List();
            sites.Add(permaLinkFileContextSite);
            sites.Add(permaLinkFolderContextSite);

            return sites;
        }

        void ThinClientUrlCmd_Execute(object sender, CommandItemEventArgs e)
        {
            WebServiceManager webMgr = currentConnection.WebServiceManager;

            ISelection selectedItem = e.Context.CurrentSelectionSet.FirstOrDefault();
            if (selectedItem != null)
            {
                Uri serverUri = new Uri(webMgr.InformationService.Url);
                string url;

                if (selectedItem.TypeId == SelectionTypeId.File)
                {
                    File file = webMgr.DocumentService.GetLatestFileByMasterId(selectedItem.Id);
                    if (file == null)
                    {
                        return;
                    }

                    string[] ids = webMgr.KnowledgeVaultService.GetPersistentIds(
                        VDF.Vault.Currency.Entities.EntityClassIds.Files,
                        new long[] { file.Id },
                        Autodesk.Connectivity.WebServices.EntPersistOpt.Latest);

                    string id = ids[0];
                    id = id.TrimEnd('=');
                    url = string.Format("{0}://{1}/AutodeskTC/{1}/{2}#/Entity/Details?id=m{3}=&itemtype=File",
                                        serverUri.Scheme, serverUri.Host, currentConnection.Vault, id);

                    //Open with default browser
                    Process.Start(url);

                    //copy url to clipboard
                    Clipboard.SetText(url);
                }

                if (selectedItem.TypeId == SelectionTypeId.Folder)
                {
                    Folder folder = webMgr.DocumentService.GetFolderById(selectedItem.Id);
                    if (folder == null)
                    {
                        return;
                    }

                    string[] ids = webMgr.KnowledgeVaultService.GetPersistentIds(
                        VDF.Vault.Currency.Entities.EntityClassIds.Folder,
                        new long[] { folder.Id },
                        Autodesk.Connectivity.WebServices.EntPersistOpt.Latest);

                    string id = ids[0];
                    id = id.TrimEnd('=');
                    url = string.Format("{0}://{1}/AutodeskTC/{1}/{2}#/Entity/Entities?folder=m{3}=&start=0",
                        serverUri.Scheme, serverUri.Host, currentConnection.Vault, id);

                    //Open with default browser
                    Process.Start(url);

                    //copy url to clipboard
                    Clipboard.SetText(url);
                }
            }
        }

        public void OnLogOn(IApplication application)
        {
            currentConnection = application.Connection;
        }

        public IEnumerable CustomEntityHandlers()
        {
            throw new NotImplementedException();
        }

        public IEnumerable DetailTabs()
        {
            throw new NotImplementedException();
        }

        public IEnumerable HiddenCommands()
        {
            throw new NotImplementedException();
        }

        public void OnLogOff(IApplication application)
        {

        }

        public void OnShutdown(IApplication application)
        {

        }

        public void OnStartup(IApplication application)
        {

        }
    }
}

Let’s take a look at how it works:

image

image

image

image

Hope it helps!


Comments

3 responses to “Generate Permanent Link of Entities in Vault and Open in Thin Client”

  1. Hi Daniel,
    I have failed to generate a hyperlink/url to a vaulted file using the persistent id (Vault Explorer, Not thin client). Although it works fine using the filename in the url, the filename could be renamed, thus making a broken link.
    This is using the filename: which works correctly when I click on it, it opens the vault and selects the $/yvcvcvvcxvc.dwg file.
    http://servername:80/AutodeskDM/Services/EntityDataommandRequest.aspx?Vault=vaultname&ObjectId=%24%2fyvcycvvcyxvc.dwg&ObjectType=File&Command=Select
    Now I tried using the persistent Id : clicking on this results in crashing of the vault application.
    http://servername:80/AutodeskDM/Services/EntityDataommandRequest.aspx?Vault=vaultname&ObjectId=mRklMRTpMQVRFU1Q6NTM1&ObjectType=File&Command=Select
    I even went further by tweaking the “.acr” file which is an xml file and still not been successful.
    My question is this: will this ever work using persistent ids for Vault Explorer?
    Thanks,

  2. This is good i will try and hope it works

  3. Hi Daniel,
    thanks for the well explained information.
    It helped me to get in the right direction, but it didn’t work for me with just copy paste.
    By the way I have used Vault 2017 and if other people also struggle here is a PowerShell snippet which is easly be done with the free tool called powerVault (https://www.coolorange.com/en/apps_vault.php):
    function Get-VaultThinUrl($Entity, [Autodesk.Connectivity.WebServices.EntPersistOpt]$EntityOutput = “Latest”) {
    $serverUri = New-Object Uri -ArgumentList @($vault.InformationService.Url)
    $persistendId = ($vault.KnowledgeVaultService.GetPersistentIds($entity.’Entity Type ID’, $entity.Id, $entityOutput)) | select -First 1
    $persistendTrimedId = $persistendId.TrimEnd(‘=’)
    “$($serverUri.Scheme)://$($serverUri.Host)/AutodeskTC/$($vaultConnection.Server)/$($vaultConnection.Vault)#/Entity/Details?id=m$persistendTrimedId=&itemtype=File”
    }
    Open-VaultConnection -Server coolOrange -Vault Patrick
    $file = Get-VaultFile -File “$/Pad Lock.pdf”
    Get-VaultThinUrl -Entity $file
    Output: http://coolOrange/AutodeskTC/coolOrange/Patrick#/Entity/Details?id=mRklMRTpMQVRFU1Q6OTAzNzMz=&itemtype=File

Leave a Reply to MaryCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading