Hide Table of Contents

Install Add-in Example (C#)

This example shows how to install an add-in and obtain information about it.

NOTE: If using the .NET Framework 4.0 primary interop assembly provided with SOLIDWORKS Enterprise PDM, see Using .NET Framework 4.0 in Stand-alone Applications.

//----------------------------------------------------------------------------
// Preconditions:
//  1. Start Microsoft Visual Studio 2010.
//     a. Click File > New > Project > Visual C# > Windows Forms Application.
//     b. Type AddinMgr_CSharp in Name.
//     c. Click Browse and navigate to the folder where to create the project.
//     d. Click OK
//     e. Click Show All Files in the Solution Explorer toolbar and expand 
//        Form1.cs in the Solution Explorer.
//     f. Create a form similar to the form shown above and change:
//        1. Top label to VaultsLabel.
//        2. Combo box to VaultsComboBox.
//        3. Browse for add-in button to BrowseButton.
//        4. List box to AddinListBox.
//        5. Install add-in button to LoadAddin.
//     g. Replace the code in Form1.cs with this code.
//     h. Replace the code in Form1.Designer.cs with this code.
//  2. Add EPDM.Interop.epdm.dll as a reference (right-click the project
//     name in the Solution Explorer, click Add Reference, click 
//     Assemblies > Framework in the left-side panel, browse to the top folder of 
//     your SOLIDWORKS Enterprise PDM installation, locate and click 
//     EPDM.Interop.epdm.dll, click Open, and click Add).
//  3. Add Microsoft.VisualBasic as a reference (click 
//     COM in the left-side panel, click 
//     Microsoft.VisualBasic, click Add, and click Close).
//  4. Right-click EPDM.Interop.epdm in References, click Properties, and set 
//     Embed Interop Types to False to handle methods that pass arrays of 
//     structures.
//  5. Click Debug > Start Debugging or press F5.
//
// Postconditions: 
//  1. The Install add-in dialog box displays.
//     a. Select a vault view.
//     b. Click Browse for add-in.
//     c. In the Browse for add-ins dialog:
//        1. Navigate to your add-in directory and click addin_name.dll 
//           and Interop.EdmLib.dll.

//        2. Click Open.
//     d. Click Install add-in.
//        A message box containing information about each add-in installed in
//        the selected vault displays.

//     e. Click OK to close each message box.
//  2. Close the Install add-in dialog box.
//----------------------------------------------------------------------------
 

//Form1.cs

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Xml.Serialization;
using System.Windows.Forms;
using System.ComponentModel;
using EPDM.Interop.epdm;
 
namespace AddinMgr_CSharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private IEdmVault5 vault1 = null;
 
        public void Form1_Load(System.Object sender, System.EventArgs e)
        {
            try
            {
                IEdmVault5 vault1 = new EdmVault5();
                IEdmVault8 vault = (IEdmVault8)vault1;
                EdmViewInfo[] Views = null;
 
                vault.GetVaultViews(out Views, false);
                VaultsComboBox.Items.Clear();
                foreach (EdmViewInfo View in Views)
                {
                    VaultsComboBox.Items.Add(View.mbsVaultName);
                }
                if (VaultsComboBox.Items.Count > 0)
                {
                    VaultsComboBox.Text = (string)VaultsComboBox.Items[0];
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 
        public void BrowseButton_Click(System.Object sender, System.EventArgs e)
        {
            try
            {
                AddinListBox.Items.Clear();
 
                
                if (vault1 == null)
                {
                    vault1 = new EdmVault5();
                }
                if (!vault1.IsLoggedIn)
                {
                    vault1.LoginAuto(VaultsComboBox.Text, this.Handle.ToInt32());
                }
 
                //Set the initial directory in the Browse for add-ins dialog
                AddinOpenFileDialog.InitialDirectory = vault1.RootFolderPath;

                //Show the Browse for add-ins dialog
                System.Windows.Forms.DialogResult DialogResult;
                DialogResult = AddinOpenFileDialog.ShowDialog();

                //If the user did not click Open, exit the subroutine
                if (!(DialogResult == System.Windows.Forms.DialogResult.OK))
                {
                    return;
                }
 
                foreach (string FileName in AddinOpenFileDialog.FileNames)
                {
                    AddinListBox.Items.Add(FileName);
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 
        public void LoadAddin_Click(System.Object sender, System.EventArgs e)
        {
            try
            {
                
                IEdmVault7 vault2 = null;
                if (vault1 == null)
                {
                    vault1 = new EdmVault5();
                }
                vault2 = (IEdmVault7)vault1;
                if (!vault1.IsLoggedIn)
                {
                    vault1.LoginAuto(VaultsComboBox.Text, this.Handle.ToInt32());
                }
 
                IEdmAddInMgr8 AddinMgr = default(IEdmAddInMgr8);
                AddinMgr = (IEdmAddInMgr8)vault1;
 
                
                string fileList = "";
                int fileidx = 1;
 
                // Save the path and name of the add-in just installed
                string justInstalledPathName = "";
 
                foreach (string FileName in AddinListBox.Items)
                {
                    if (!(FileName.Contains("Interop")))
                    {
                        justInstalledPathName = FileName;
                    }
 
                    if (fileidx == 1)
                    {
                        fileList = FileName;
                    }
                    else
                    {
                        fileList = fileList + Constants.vbLf + FileName;
                    }
 
                    fileidx = fileidx + 1;
                }
 
         
                AddinMgr.AddAddIns(fileList, (int)EdmAddAddInFlags.EdmAddin_AddAllFilesToOneAddIn, null);
 
 
                // Get information about each of the installed add-ins
                EdmAddInInfo2[] addIns = null;
                AddinMgr.GetInstalledAddIns(out addIns);
 
                string addinName = "";
                string s = "";
                int idx = 0;
                idx = Information.LBound(addIns);
 
 
                while (idx <= Information.UBound(addIns))
                {
                    s = "Add-in: " + addIns[idx].mbsAddInName + Constants.vbLf + "Class: " + addIns[idx].mbsClassID + Constants.vbLf;
                    s = s + "Company: " + addIns[idx].mbsCompany + Constants.vbLf + "Description: " + addIns[idx].mbsDescription + Constants.vbLf;
                    s = s + "Path: " + addIns[idx].mbsModulePath + Constants.vbLf + "Version: " + Convert.ToString(addIns[idx].mlAddInVersion) + Constants.vbLf;
                    s = s + "Req ver: " + Convert.ToString(addIns[idx].mlRequiredVersionMajor) + "." + Convert.ToString(addIns[idx].mlRequiredVersionMinor);
 
                    Interaction.MsgBox(s);
                    // Save the name of the add-in just installed
                    addinName = addIns[idx].mbsAddInName;
                    
                    idx = idx + 1;
                }
 
                // Get information about each of the add-ins installed for debugging
                EdmAddInInfo2[] debugAddIns = new EdmAddInInfo2[10];
                AddinMgr.GetDebugAddIns(ref debugAddIns);
 
                idx = Information.LBound(debugAddIns);
 
                while (idx <= Information.UBound(debugAddIns))
                {
                    s = "Debug add-in: " + debugAddIns[idx].mbsAddInName + Constants.vbLf + "Class: " + debugAddIns[idx].mbsClassID + Constants.vbLf;
                    s = s + "Company: " + debugAddIns[idx].mbsCompany + Constants.vbLf + "Description: " + debugAddIns[idx].mbsDescription + Constants.vbLf;
                    s = s + "Path: " + debugAddIns[idx].mbsModulePath + Constants.vbLf + "Version: " + Convert.ToString(debugAddIns[idx].mlAddInVersion) + Constants.vbLf;
                    s = s + "Req ver: " + Convert.ToString(debugAddIns[idx].mlRequiredVersionMajor) + "." + Convert.ToString(debugAddIns[idx].mlRequiredVersionMinor);
 
                    Interaction.MsgBox(s);
                    idx = idx + 1;
                }
 
                // Get information about the add-in just installed
                EdmAddInInfo2 poInfo = new EdmAddInInfo2();
                AddinMgr.GetAddInInfo2(justInstalledPathName, nullref poInfo);
 
                s = "Getting info for add-in: " + poInfo.mbsAddInName + Constants.vbLf + "Class: " + poInfo.mbsClassID + Constants.vbLf;
                s = s + "Company: " + poInfo.mbsCompany + Constants.vbLf + "Description: " + poInfo.mbsDescription + Constants.vbLf;
                s = s + "Path: " + poInfo.mbsModulePath + Constants.vbLf + "Version: " + Convert.ToString(poInfo.mlAddInVersion) + Constants.vbLf;
                s = s + "Req ver: " + Convert.ToString(poInfo.mlRequiredVersionMajor) + "." + Convert.ToString(poInfo.mlRequiredVersionMinor);
 
                Interaction.MsgBox(s);
 
                // Extract information about the add-in just installed
                EdmAddInFileInfo[] ppoFiles = null;
                EdmAddInMenuInfo[] ppoCmds = null;
                AddinMgr.GetInstalledAddIn(addinName, "c:\\temp"out poInfo, out ppoFiles, out ppoCmds);
 
                string msg = null;
                msg = "Extracting info for add-in: " + poInfo.mbsAddInName + Constants.vbLf;
                msg = msg + "CLSID=" + poInfo.mbsClassID + Constants.vbLf;
                msg = msg + "Company=" + poInfo.mbsCompany + Constants.vbLf;
                msg = msg + "Module=" + poInfo.mbsModulePath + Constants.vbLf;
                msg = msg + "Version=" + Convert.ToString(poInfo.mlAddInVersion) + Constants.vbLf;
                msg = msg + "Requires version=" + Convert.ToString(poInfo.mlRequiredVersionMajor) + "." + Convert.ToString(poInfo.mlRequiredVersionMinor);
                msg = msg + Constants.vbLf + "Files:" + Constants.vbLf;
 
                idx = Information.LBound(ppoFiles);
                while (idx <= Information.UBound(ppoFiles))
                {
                    msg = msg + ppoFiles[idx].mbsFileName + " Flags=" + Convert.ToString(ppoFiles[idx].mlEdmAddInFileInfoFlags) + Constants.vbLf;
                    idx = idx + 1;
                }
 
                msg = msg + Constants.vbLf + "Commands:" + Constants.vbLf;
 
                idx = Information.LBound(ppoCmds);
                while (idx <= Information.UBound(ppoCmds))
                {
                    msg = msg + "'" + ppoCmds[idx].mbsMenuStr + "' Flags=" + Convert.ToString(ppoCmds[idx].mlEdmMenuFlags) + Constants.vbLf;
                    idx = idx + 1;
                }
 
                vault1.MsgBox(this.Handle.ToInt32(), msg);
 
                // Get CAF information about the add-in just installed
                AddinMgr.GetCAFInfo(poInfo.mbsModulePath"c:\\temp"out poInfo, out ppoFiles, out ppoCmds);
                msg = "Getting CAF info for add-in: " + poInfo.mbsAddInName + Constants.vbLf;
                msg = msg + "CLSID=" + poInfo.mbsClassID + Constants.vbLf;
                msg = msg + "Company=" + poInfo.mbsCompany + Constants.vbLf;
                msg = msg + "Module=" + poInfo.mbsModulePath + Constants.vbLf;
                msg = msg + "Version=" + Convert.ToString(poInfo.mlAddInVersion) + Constants.vbLf;
                msg = msg + "Requires version=" + Convert.ToString(poInfo.mlRequiredVersionMajor) + "." + Convert.ToString(poInfo.mlRequiredVersionMinor);
                msg = msg + Constants.vbLf + "Files:" + Constants.vbLf;
 
                idx = Information.LBound(ppoFiles);
                while (idx <= Information.UBound(ppoFiles))
                {
                    msg = msg + ppoFiles[idx].mbsFileName + " Flags=" + Convert.ToString(ppoFiles[idx].mlEdmAddInFileInfoFlags) + Constants.vbLf;
                    idx = idx + 1;
                }
 
                msg = msg + Constants.vbLf + "Commands:" + Constants.vbLf;
 
                idx = Information.LBound(ppoCmds);
                while (idx <= Information.UBound(ppoCmds))
                {
                    msg = msg + "'" + ppoCmds[idx].mbsMenuStr + "' flags=" + Convert.ToString(ppoCmds[idx].mlEdmMenuFlags) + Constants.vbLf;
                    idx = idx + 1;
                }
 
                vault1.MsgBox(this.Handle.ToInt32(), msg);
 
                return;
 
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
 
        }
        
    }
}

 

Back to top

//Form1.Designer.cs

namespace AddinMgr_CSharp
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Windows Form Designer generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.VaultsLabel = new System.Windows.Forms.Label();
            this.VaultsComboBox = new System.Windows.Forms.ComboBox();
            this.BrowseButton = new System.Windows.Forms.Button();
            this.AddinListBox = new System.Windows.Forms.ListBox();
            this.LoadAddin = new System.Windows.Forms.Button();
            this.AddinOpenFileDialog = new System.Windows.Forms.OpenFileDialog();
            this.SuspendLayout();
            //
            //VaultsLabel
            //
            this.VaultsLabel.AutoSize = true;
            this.VaultsLabel.Location = new System.Drawing.Point(13, 26);
            this.VaultsLabel.Name = "VaultsLabel";
            this.VaultsLabel.Size = new System.Drawing.Size(91, 13);
            this.VaultsLabel.TabIndex = 0;
            this.VaultsLabel.Text = "Select vault view:";
            //
            //VaultsComboBox
            //
            this.VaultsComboBox.FormattingEnabled = true;
            this.VaultsComboBox.Location = new System.Drawing.Point(16, 59);
            this.VaultsComboBox.Name = "VaultsComboBox";
            this.VaultsComboBox.Size = new System.Drawing.Size(121, 21);
            this.VaultsComboBox.TabIndex = 1;
            //
            //BrowseButton
            //
            this.BrowseButton.Location = new System.Drawing.Point(16, 98);
            this.BrowseButton.Name = "BrowseButton";
            this.BrowseButton.Size = new System.Drawing.Size(271, 23);
            this.BrowseButton.TabIndex = 3;
            this.BrowseButton.Text = "Browse for add-in...";
            this.BrowseButton.UseVisualStyleBackColor = true;
            this.BrowseButton.Click += new System.EventHandler(this.BrowseButton_Click);
            //
            //AddinListBox
            //
            this.AddinListBox.FormattingEnabled = true;
            this.AddinListBox.HorizontalScrollbar = true;
            this.AddinListBox.Location = new System.Drawing.Point(16, 151);
            this.AddinListBox.Name = "AddinListBox";
            this.AddinListBox.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple;
            this.AddinListBox.Size = new System.Drawing.Size(259, 56);
            this.AddinListBox.TabIndex = 4;
            //
            //LoadAddin
            //
            this.LoadAddin.Location = new System.Drawing.Point(16, 230);
            this.LoadAddin.Name = "LoadAddin";
            this.LoadAddin.Size = new System.Drawing.Size(259, 23);
            this.LoadAddin.TabIndex = 5;
            this.LoadAddin.Text = "Install add-in";
            this.LoadAddin.UseVisualStyleBackColor = true;
            this.LoadAddin.Click += new System.EventHandler(this.LoadAddin_Click);
            //
            //AddinOpenFileDialog
            //
            this.AddinOpenFileDialog.Multiselect = true;
            this.AddinOpenFileDialog.Title = "Browse for add-ins";
            //
            //Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(317, 277);
            this.Controls.Add(this.LoadAddin);
            this.Controls.Add(this.AddinListBox);
            this.Controls.Add(this.BrowseButton);
            this.Controls.Add(this.VaultsComboBox);
            this.Controls.Add(this.VaultsLabel);
            this.Name = "Form1";
            this.Text = "Install add-in";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();
 
        }
 
        #endregion
 
        private System.Windows.Forms.OpenFileDialog AddinOpenFileDialog;
        private System.Windows.Forms.Label VaultsLabel;
        private System.Windows.Forms.ComboBox VaultsComboBox;
        private System.Windows.Forms.Button BrowseButton;
        private System.Windows.Forms.ListBox AddinListBox;
        private System.Windows.Forms.Button LoadAddin;
    }
}
 

 

Back to top



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Install Add-in Example (C#)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.