Random Posts

How to Add System Drawing Reference in C# TUTORIAL

Add together Custom File Reference Example (C#)

This example shows how to add a custom file reference to a file in the vault.

NOTE: If using the primary interop associates provided with SOLIDWORKS PDM Professional person, see Using .NET Framework 4.0 in Stand-lone Applications.

//----------------------------------------------------------------------------
// Preconditions:
// i. Beginning Microsoft Visual Studio.
//    a. ClickFile > New > Project > Visual C# > Windows Forms Application.
//    b. BlazonCustRefCSharp inProper noun.
//    c. ClickScan and navigate to the binder where to create
//       the project.
//    d. ClickOK.
//    e. ClickShow 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:
//       ane. Top characterization toVaultsLabel.
//       2. Combo box toVaultsComboBox.
//       iii. Scan push toBrowseButton.
//       4. List box toCustRefListBox.

//       five.Add custom file reference button toAddCustomFileReference.
//    g. Supersede the code inForm1.cs with this code.
//    h. Replace the code inForm1.Designer.cs with this lawmaking.
// 2. AddEPDM.Interop.epdm.dll equally a reference (right-click the projection
//    proper noun in the Solution Explorer, clickAdd Reference, click
//Assemblies > Framework in the left-side panel, scan to the top folder of
//    your SOLIDWORKS PDM Professional installation, locate and click
//EPDM.Interop.epdm.dll, clickOpen, clickAdd, and clickShut).
// 3. Right-clickEPDM.Interop.epdm in References, clickProperties, and set
//Embed Interop Types toFalse to handle methods that pass arrays of
//    structures.
// 4. ClickDebug > Start Debugging or press F5.
//
// Postconditions:
//  1. The Add together custom references dialog displays.
// 2. Select a vault.
//  3. ClickBrowse for file to which to add custom reference,
//     locate and click a file in the vault, and clickOpen.
//     The file is checked out.
// 4. In a view of the selected vault, right-click a file and click Copy.

//  five. In the Add custom references dialog, clickAdd together custom file reference.
//     The file that was copied to the clipboard is added as a custom
//     reference to the checked-out file.
//  6. In the Create File References dialog, clickOK.
//     The file is checked in.
//  seven. In the Edit User-Divers File References dialog, clickOK.
//  8. Close the Add custom references dialog.

//----------------------------------------------------------------------------

//Form1.cs
using Arrangement.IO;
using System.Xml.Serialization;
using Organization;
using Organization.Collections;
using Arrangement.Collections.Generic;
using Organization.Data;
using Organisation.Diagnostics;
using System.Windows.Forms;
using Organisation.ComponentModel;
using EPDM.Interop.epdm;

namespace CustRefCSharp
{
publicpartialclassForm1 :Grade
{
public Form1()
{
InitializeComponent();
}

IEdmVault5 vault1 =null;

publicvoid FileReferencesCSharp_Load(System.Object sender, System.EventArgs e)
{

endeavor
{
IEdmVault5 vault1 =newEdmVault5();
IEdmVault8 vault = (IEdmVault8)vault1;
EdmViewInfo[] Views =zero;

                vault.GetVaultViews(out Views,false);
VaultsComboBox.Items.Articulate();
foreach (EdmViewInfo Viewin Views)
{
VaultsComboBox.Items.Add(View.mbsVaultName);
}
if (VaultsComboBox.Items.Count > 0)
{
VaultsComboBox.Text = (string)VaultsComboBox.Items[0];
}
}
grab (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("Ten") +"\n" + ex.Message);
}
catch (Exception ex)
{
MessageBox.Testify(ex.Message);
}
}

publicvoid BrowseButton_Click(Arrangement.Object sender, System.EventArgs e)
{
endeavour
{
CustRefListBox.Items.Articulate();

//Only create a new vault object
//if one hasn't been created yet
if (vault1 ==cipher)
vault1 =newEdmVault5();
if (!vault1.IsLoggedIn)
{
//Log into selected vault as the current user
vault1.LoginAuto(VaultsComboBox.Text,this.Handle.ToInt32());
}

//Set the initial directory in the File Open dialog
CustRefOpenFileDialog.InitialDirectory = vault1.RootFolderPath;
//Show the File Open dialog
System.Windows.Forms.DialogResult DialogResult =default(System.Windows.Forms.DialogResult);
DialogResult = CustRefOpenFileDialog.ShowDialog();
//If the user didn't click Open, exit the sub
if (!(DialogResult == System.Windows.Forms.DialogResult.OK))
return;

foreach (string FileNamein CustRefOpenFileDialog.FileNames)
{
CustRefListBox.Items.Add(FileName);
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Evidence("HRESULT = 0x" + ex.ErrorCode.ToString("10") +"\n" + ex.Message);
}
take hold of (Exception ex)
{
MessageBox.Bear witness(ex.Message);
}
}

 publicvoid AddCustomFileReference_Click(Arrangement.Object sender, System.EventArgs e)
{
try
{
//Only create a new vault object
//if i hasn't been created however
IEdmVault7 vault2 =nix;
if (vault1 ==null)
vault1 =newEdmVault5();
vault2 = (IEdmVault7)vault1;
if (!vault1.IsLoggedIn)
{
//Log into selected vault as the electric current user
vault1.LoginAuto(VaultsComboBox.Text,this.Handle.ToInt32());
}

IEdmAddCustomRefs addCustRefs = (IEdmAddCustomRefs)vault2.CreateUtility(EdmUtility.EdmUtil_AddCustomRefs);
Int32[] ppoFileIdArray =newInt32[CustRefListBox.Items.Count];
IEdmFile5 file =null;
IEdmFolder5 parentFolder =nix;
int i = 0;
foreach (cord FileNamein CustRefListBox.Items)
{
file = vault2.GetFileFromPath(FileName,out parentFolder);
if (!file.IsLocked) {
file.LockFile(parentFolder.ID,this.Handle.ToInt32(), (int)EdmLockFlag.EdmLock_Simple);
}
ppoFileIdArray[i] = file.ID;
i++;
}
Boolean retCode =false;

//Add the file that is copied to the clipboard as a custom reference to the selected file
foreach (int IDin ppoFileIdArray)
{
addCustRefs.AddReferencesClipboard(ID);
addCustRefs.CreateTree((int)EdmCreateReferenceFlags.Ecrf_Nothing);
addCustRefs.ShowDlg(this.Handle.ToInt32());
retCode = addCustRefs.CreateReferences();
}

// Cheque in the file
file.UnlockFile(this.Handle.ToInt32(),"Custom reference added");

//Brandish current custom file references
retCode = addCustRefs.ShowEditReferencesDlg(ref ppoFileIdArray,this.Handle.ToInt32());

            }
catch (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") +"\north" + ex.Message);
}
catch (Exception ex)
{
MessageBox.Bear witness(ex.Message);
}
}

    }
}

Back to top

//Form1.Designer.cs

namespace CustRefCSharp
{
fractionalformForm1
{
/// <summary>
///  Required designer variable.
/// </summary>
private Arrangement.ComponentModel.IContainer components =null;

/// <summary>
///  Clean up any resource being used.
/// </summary>
/// <param name="disposing"> true if managed resources should be disposed; otherwise, imitation. </param>
protectedoverridevoid Dispose(bool disposing)
{
if (disposing && (components !=zilch))
{
components.Dispose();
}
base.Dispose(disposing);
}

        #region Windows Form Designer generated code

/// <summary>
///  Required method for Designer support - exercise not modify
///  the contents of this method with the lawmaking editor.
/// </summary>
privatevoid InitializeComponent()
{
this.VaultsLabel =new Arrangement.Windows.Forms.Label();
this.VaultsComboBox =new System.Windows.Forms.ComboBox();
this.BrowseButton =new Organisation.Windows.Forms.Button();
this.CustRefListBox =new Organisation.Windows.Forms.ListBox();
this.AddCustomFileReference =new System.Windows.Forms.Button();
this.CustRefOpenFileDialog =new System.Windows.Forms.OpenFileDialog();
this.SuspendLayout();
//
// VaultsLabel
//
this.VaultsLabel.AutoSize =truthful;
this.VaultsLabel.Location =new Arrangement.Drawing.Signal(13, 26);
this.VaultsLabel.Name ="VaultsLabel";
this.VaultsLabel.Size =new Arrangement.Drawing.Size(244, thirteen);
this.VaultsLabel.TabIndex = 0;
this.VaultsLabel.Text ="Copy a file to the clipboard, then select vault view:";
//
// VaultsComboBox
//
this.VaultsComboBox.FormattingEnabled =true;
this.VaultsComboBox.Location =new System.Drawing.Point(sixteen, 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.Betoken(16, 98);
this.BrowseButton.Proper name ="BrowseButton";
this.BrowseButton.Size =new Organisation.Drawing.Size(271, 23);
this.BrowseButton.TabIndex = iii;
this.BrowseButton.Text ="Scan for file to which to add together a custom reference...";
this.BrowseButton.UseVisualStyleBackColor =truthful;
this.BrowseButton.Click +=new Arrangement.EventHandler(this.BrowseButton_Click);
//
// CustRefListBox
//
this.CustRefListBox.FormattingEnabled =true;
this.CustRefListBox.Location =new Organization.Drawing.Point(xvi, 150);
this.CustRefListBox.Name ="CustRefListBox";
this.CustRefListBox.Size =new System.Cartoon.Size(259, 95);
this.CustRefListBox.TabIndex = 4;
//
// AddCustomFileReference
//
this.AddCustomFileReference.Location =new System.Drawing.Point(16, 273);
this.AddCustomFileReference.Name ="AddCustomFileReference";
this.AddCustomFileReference.Size =new Organisation.Drawing.Size(259, 23);
this.AddCustomFileReference.TabIndex = five;
this.AddCustomFileReference.Text ="Add custom file reference";
this.AddCustomFileReference.UseVisualStyleBackColor =true;
this.AddCustomFileReference.Click +=new Organisation.EventHandler(this.AddCustomFileReference_Click);
//
// Form1
//
this.AutoScaleDimensions =new Organization.Cartoon.SizeF(6F, 13F);
this.AutoScaleMode = Organisation.Windows.Forms.AutoScaleMode.Font;
this.ClientSize =new System.Drawing.Size(317, 308);
this.Controls.Add(this.AddCustomFileReference);
this.Controls.Add(this.CustRefListBox);
this.Controls.Add(this.BrowseButton);
this.Controls.Add(this.VaultsComboBox);
this.Controls.Add(this.VaultsLabel);
this.Proper name ="Form1";
this.Text ="Add custom file references";
this.Load +=new System.EventHandler(this.FileReferencesCSharp_Load);
this.ResumeLayout(false);
this.PerformLayout();

        }

        

Related Posts

There is no other posts in this category.
Subscribe Our Newsletter