Get Vault Connection object from Microsoft Office addin

Get Vault Connection object from Microsoft Office addin

m_melis
Contributor Contributor
1,301 Views
6 Replies
Message 1 of 7

Get Vault Connection object from Microsoft Office addin

m_melis
Contributor
Contributor

Hi,

 

i would like to create a Microsoft Word addin and I would like to get Vault Connection object to perform some operation on the .docx files after the Checkin post event.

I've created a vsto addin and during startup event I try to subscribe to the ConnectionExtablished event but it doesn't seem to works.

Can you help me to find a solution?

 

best

Massimo

0 Likes
1,302 Views
6 Replies
Replies (6)
Message 2 of 7

wayne.brill
Collaborator
Collaborator

Hello Massimo,

 

We have this DevBlog post http://adndevblog.typepad.com/manufacturing/2013/09/autocad-2014-vault-add-in-connection.html which shows how to get the connection in AutoCAD or Inventor but this approach does not work with the Vault Office Add-In.


I tried using the code in the Inventor example from that DevBlog post in an Excel Add-In and the connection is null. I asked a colleague in Vault Engineering about this:

 

>> >>

Looking at the code the office addins they are setting the VDF connection to the same place. Alternatively, you can also try “OfficeAddinCommon.dll”

Autodesk.Vault.OfficeAddinCommon.LoginManager.Instance.Connection


If both are returning null, it’s probably Office is preventing you from access the object in another Add-In.

<< <<

 

I tried using Autodesk.Vault.OfficeAddinCommon.LoginManager.Instance.Connection and the Connection is null there too.

 

Thanks,
Wayne Brill



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 7

m_melis
Contributor
Contributor

Hi Wayne,

 

So the only way to get the checkin event is to write my own office addin and develop my ribbon with login, logout, open, refresh from vault, checkin, checkout, undo checkout button and I have to completely replace Autodesk addin with my addin, because there isn't a way to get the connection object stored in Autodesk office addin: am I right?

In an office com addin the exposition of a class or of a method is possible if the addin developer would like to, can you confirm that Autodesk addin was not open to external call?

Have you got other suggestion?

 

Thank you very much

Massimo

0 Likes
Message 4 of 7

wayne.brill
Collaborator
Collaborator

Hi Massimo,

 

You could have Vault Extension that can get the WebServiceManager in one of the CheckinFileEvents. 

http://adndevblog.typepad.com/manufacturing/2013/06/get-webservicemanager-in-a-vault-event-handler.h...

 

I tested this from the Vault Word Add-In using this SDK sample:

C:\Program Files (x86)\Autodesk\Autodesk Vault 2015 SDK\vs12\CSharp\RestrictOperations

 

Below are some snippets that I added to that sample. When I check in a file from Word I see my events getting called.

 DocumentService.CheckinFileEvents.GetRestrictions += new EventHandler<CheckinFileCommandEventArgs>(CheckinFileEvents_GetRestrictions);

            //WB added
            DocumentService.CheckinFileEvents.Post += new EventHandler<CheckinFileCommandEventArgs>(CheckinFileEvents_Post);
            DocumentService.CheckinFileEvents.Pre += new EventHandler<CheckinFileCommandEventArgs>(CheckinFileEvents_Pre);

 

...

 

   //WB addedd
        void CheckinFileEvents_Post(object sender, CheckinFileCommandEventArgs e)
        {
            IWebService webService = (IWebService)sender;
            Autodesk.Connectivity.WebServicesTools.WebServiceManager wbSrvMgr;
            wbSrvMgr = webService.WebServiceManager;

            var propDefs = wbSrvMgr.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE");

            PropDef ProviderPropDef = null;
            foreach (var propDef in propDefs)
            {
                if (propDef.SysName == "Provider")
                {
                    ProviderPropDef = propDef;
                    break;
                }
            }
            // need to get a File.Id for GetProperties, e passed in only has the FileMasterId 
            FileArray[] myFileArray = wbSrvMgr.DocumentService.GetFilesByMasterIds(new long[] { e.FileMasterId });
            File myFile = myFileArray[0].Files[0];

            // get the value of the Provider from the file
            PropInst[] props = wbSrvMgr.PropertyService.GetProperties("FILE", new long[] { myFile.Id }, new long[] { ProviderPropDef.Id });

            // only want to try and display the value if it is something
            if (props[0].Val != null)
            {
                MessageBox.Show("File checked in by " + props[0].Val.ToString());
            }

        }

 

 

In my first reply I thought you were trying to get the login from the Vault Add-In so you would not have to have the user log in again. 

 

There is not any API for the Vault Office Add-In. These posts on the Vault idea station are related to the CAD Vault Add-Ins.

http://forums.autodesk.com/t5/vault-ideastation/api-access-to-vault-inventor-add-in-and-other-cad-ad...

http://forums.autodesk.com/t5/vault-ideastation/vault-api-enhancements/idi-p/5566309

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 7

m_melis
Contributor
Contributor

Hi,

 

sorry for the delay.

Your solution doesn't work for me:

 

This is a simple VSTO Word addin for 2013 and 2016 release, I can debug it but the AddFileEvent and the CheckinEvent are not fired

 

Snippet

public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            DocumentService.AddFileEvents.Post += AddFileEvents_Post;
            DocumentService.CheckinFileEvents.Post += CheckinFileEvents_Post;        
        }
 
        private void CheckinFileEvents_Post(object sender, CheckinFileCommandEventArgs e)
        {
 
        }
 
        private void AddFileEvents_Post(object sender, AddFileCommandEventArgs e)
        {
 
        }
 
        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }
 
        #region VSTO generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }

 

0 Likes
Message 6 of 7

wayne.brill
Collaborator
Collaborator

Hi Massimo,

 

Events are discussed in this post: (this is also in the Vault API help)

http://justonesandzeros.typepad.com/blog/2011/07/event-scope.html

 

It seems like you are trying to implement Scenario #4 as described in that article. "Application X" scope without using a plug-in". Because there is not a way to get the Word Vault Add-In connection it is not like "Scenario 3:  CAD application scope using a plug-in".

 

I do not see a way to get the Vault events when the Word Vault Add-in checks in a file without having a custom dll in the extensions folder (under ProgramData) like described in the "Scenario 1:  Global scope" or as described in "Scenario 4:  "Application X" scope without using a plug-in"

 

Thanks,

Wayne

 

 

 

 

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 7 of 7

m_melis
Contributor
Contributor

Hi Waine,

according to my tests the only way to get the connection object and of the events is to create an indipendent Word addin with all Autodesk stardard functionalities.

thank you very much for your help

Massimo

0 Likes