Solid Edge SDK


Edit

Solid Edge Type Libraries

Type LibraryDescription
assemblysync.tlbSolid Edge Assembly Sync Type Library
assembly.tlbSolid Edge Assembly Type Library
constant.tlbSolid Edge Constants Type Library
draft.tlbSolid Edge Draft Type Library
PropAuto.dllSolid Edge File Properties Object Library
framewrk.tlbSolid Edge Framework Type Library
fwksupp.tlbSolid Edge FrameworkSupport Type Library
geometry.tlbSolid Edge Geometry Type Library
SEInstallData.dllSolid Edge Install Data Library
PartSync.tlbSolid Edge Part Sync Type Library
Part.tlbSolid Edge Part Type Library
RevMgr.tlbSolid Edge Revision Manager Object Library

Edit

Solid Edge ProgID's

ProgIDDescription
SolidEdge.ApplicationSolid Edge
SolidEdge.AssemblyDocumentSolid Edge Assembly Document
SolidEdge.ConfigFileExtensionSolid Edge Assembly Configuration File
SolidEdge.DMAssemblyDocumentSolid Edge Synchronous Assembly Document
SolidEdge.DMPartDocumentSolid Edge Synchronous Part Document
SolidEdge.DMSheetMetalDocumentSolid Edge Synchronous Sheet Metal Document
SolidEdge.DraftDocumentSolid Edge Draft Document
SolidEdge.FilePropertiesSolid Edge File Properties Automation
SolidEdge.InstallDataSolid Edge File Properties Automation
SolidEdge.PartDocumentSolid Edge Part Document
SolidEdge.SheetMetalDocumentSolid Edge Sheet Metal Document
SolidEdge.WeldmentDocumentSolid Edge Weldment Document

Edit

Articles

Solid Edge ST Addins - Part I

Edit

Examples

Edit

Connecting to Solid Edge

Visual Basic .NET
Imports System.Runtime.InteropServices

Module Module1
  Sub Main()
      Dim objApp As SolidEdgeFramework.Application = Nothing
      Try
          ' Connect to a running instance of Solid Edge 
          objApp = Marshal.GetActiveObject("SolidEdge.Application")
      Catch ex As Exception
          Console.WriteLine(ex.Message)
      Finally
          If Not (objApp Is Nothing) Then
              Marshal.ReleaseComObject(objApp)
              objApp = Nothing
          End If
      End Try
  End Sub
End Module

C#
using System;
using System.Runtime.InteropServices;

namespace MyMacro
{
  class Program
  {
    static void Main(string[] args)
    {
      SolidEdgeFramework.Application application = null;
      try
      {
        // Connect to a running instance of Solid Edge 
        application = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");
      }
      catch (System.Exception ex)
      {
        Console.WriteLine(ex.Message);
      }
      finally
      {
        if (application != null)
        {
          Marshal.ReleaseComObject(application);
          application = null;
        }
      }
    }
  }
}

Edit

Starting Solid Edge

Visual Basic .NET
Imports System.Runtime.InteropServices

Module Module1
  Sub Main()
    Dim objApp As SolidEdgeFramework.Application = Nothing
    Dim objType As Type
    Try
      ' Get the type from the Solid Edge ProgID 
      objType = Type.GetTypeFromProgID("SolidEdge.Application")
      ' Start Solid Edge 
      objApp = Activator.CreateInstance(objType)
      ' Make Solid Edge visible 
      objApp.Visible = True
    Catch ex As Exception
      Console.WriteLine(ex.Message)
    Finally
      If Not (objApp Is Nothing) Then
        Marshal.ReleaseComObject(objApp)
        objApp = Nothing
      End If
    End Try
  End Sub
End Module

C#
using System;
using System.Runtime.InteropServices;

namespace MyMacro
{
  class Program
  {
    static void Main(string[] args)
    {
      SolidEdgeFramework.Application application = null;
      Type type = null;
      try
      {
        // Get the type from the Solid Edge ProgID 
        type = Type.GetTypeFromProgID("SolidEdge.Application");
        // Start Solid Edge 
        application = (SolidEdgeFramework.Application)Activator.CreateInstance(type);
        // Make Solid Edge visible 
        application.Visible = true;
      }
      catch (System.Exception ex)
      {
        Console.WriteLine(ex.Message);
      }
      finally
      {
        if (application != null)
        {
          Marshal.ReleaseComObject(application);
          application = null;
        }
      }
    }
  }
}

Edit

Creating Documents

Visual Basic .NET
Imports System.Runtime.InteropServices

Module Module1
  Sub Main()
    Dim objApp As SolidEdgeFramework.Application = Nothing
    Dim objDocuments As SolidEdgeFramework.Documents = Nothing
    Dim objAssembly As SolidEdgeAssembly.AssemblyDocument = Nothing
    Dim objAssemblySync As SolidEdgeAssemblySync.AssemblyDocument = Nothing
    Dim objDraft As SolidEdgeDraft.DraftDocument = Nothing
    Dim objPart As SolidEdgePart.PartDocument = Nothing
    Dim objPartSync As SolidEdgePartSync.PartDocument = Nothing
    Dim objSheetMetal As SolidEdgePart.SheetMetalDocument = Nothing
    Dim objWeldment As SolidEdgePart.WeldmentDocument = Nothing
    Dim objType As Type
    Try
      ' Get the type from the Solid Edge ProgID 
      objType = Type.GetTypeFromProgID("SolidEdge.Application")
      ' Start Solid Edge 
      objApp = Activator.CreateInstance(objType)
      ' Make Solid Edge visible 
      objApp.Visible = True
      ' Turn off alerts. Weldment environment will display a warning 
      objApp.DisplayAlerts = False
      ' Get a reference to the Documents collection 
      objDocuments = objApp.Documents
      ' Create an instance of each document environment 
      objAssembly = objDocuments.Add("SolidEdge.AssemblyDocument")
      objAssemblySync = objDocuments.Add("SolidEdge.DMAssemblyDocument")
      objDraft = objDocuments.Add("SolidEdge.DraftDocument")
      objPart = objDocuments.Add("SolidEdge.PartDocument")
      objPartSync = objDocuments.Add("SolidEdge.DMPartDocument")
      objSheetMetal = objDocuments.Add("SolidEdge.SheetMetalDocument")
      objWeldment = objDocuments.Add("SolidEdge.WeldmentDocument")
      ' Turn alerts back on 
      objApp.DisplayAlerts = True
    Catch ex As Exception
      Console.WriteLine(ex.Message)
    Finally
      If Not (objAssembly Is Nothing) Then
        Marshal.ReleaseComObject(objAssembly)
        objAssembly = Nothing
      End If
      If Not (objAssemblySync Is Nothing) Then
        Marshal.ReleaseComObject(objAssemblySync)
        objAssemblySync = Nothing
      End If
      If Not (objDraft Is Nothing) Then
        Marshal.ReleaseComObject(objDraft)
        objDraft = Nothing
      End If
      If Not (objPart Is Nothing) Then
        Marshal.ReleaseComObject(objPart)
        objPart = Nothing
      End If
      If Not (objPartSync Is Nothing) Then
        Marshal.ReleaseComObject(objPartSync)
        objPartSync = Nothing
      End If
      If Not (objSheetMetal Is Nothing) Then
        Marshal.ReleaseComObject(objSheetMetal)
        objSheetMetal = Nothing
      End If
      If Not (objWeldment Is Nothing) Then
        Marshal.ReleaseComObject(objWeldment)
        objWeldment = Nothing
      End If
      If Not (objDocuments Is Nothing) Then
        Marshal.ReleaseComObject(objDocuments)
        objDocuments = Nothing
      End If
      If Not (objApp Is Nothing) Then
        Marshal.ReleaseComObject(objApp)
        objApp = Nothing
      End If
    End Try
  End Sub
End Module

C#
using System;
using System.Reflection;
using System.Runtime.InteropServices;

namespace MyMacro
{
  class Program
  {
    static void Main(string[] args)
    {
      SolidEdgeFramework.Application application = null;
      SolidEdgeFramework.Documents documents = null;
      SolidEdgeAssembly.AssemblyDocument assembly = null;
      SolidEdgeAssemblySync.AssemblyDocument assemblySync = null;
      SolidEdgeDraft.DraftDocument draft = null;
      SolidEdgePart.PartDocument part = null;
      SolidEdgePartSync.PartDocument partSync = null;
      SolidEdgePart.SheetMetalDocument sheetmetal = null;
      SolidEdgePart.WeldmentDocument weldment = null;
      Type type = null;

      try
      {
        // Get the type from the Solid Edge ProgID 
        type = Type.GetTypeFromProgID("SolidEdge.Application");
        // Start Solid Edge 
        application = (SolidEdgeFramework.Application)
        Activator.CreateInstance(type);
        // Make Solid Edge visible 
        application.Visible = true;
        // Turn off alerts. Weldment environment will display a warning 
        application.DisplayAlerts = false;
        // Get a reference to the Documents collection 
        documents = application.Documents;
        // Create an instance of each document environment 
        assembly = (SolidEdgeAssembly.AssemblyDocument)documents.Add("SolidEdge.AssemblyDocument", Missing.Value);
        assemblySync = (SolidEdgeAssemblySync.AssemblyDocument)documents.Add("SolidEdge.DMAssemblyDocument", Missing.Value);
        draft = (SolidEdgeDraft.DraftDocument)documents.Add("SolidEdge.DraftDocument", Missing.Value);
        part = (SolidEdgePart.PartDocument)documents.Add("SolidEdge.PartDocument", Missing.Value);
        partSync = (SolidEdgePartSync.PartDocument)documents.Add("SolidEdge.DMPartDocument", Missing.Value);
        sheetmetal = (SolidEdgePart.SheetMetalDocument)documents.Add("SolidEdge.SheetMetalDocument", Missing.Value);
        weldment = (SolidEdgePart.WeldmentDocument)documents.Add("SolidEdge.WeldmentDocument", Missing.Value);
        // Turn alerts back on 
        application.DisplayAlerts = true;
      }
      catch (System.Exception ex)
      {
        Console.WriteLine(ex.Message);
      }
      finally
      {
        if (assembly != null)
        {
          Marshal.ReleaseComObject(assembly);
          assembly = null;
        }
        if (assemblySync != null)
        {
          Marshal.ReleaseComObject(assemblySync);
          assemblySync = null;
        }
        if (draft != null)
        {
          Marshal.ReleaseComObject(draft);
          draft = null;
        }
        if (part != null)
        {
          Marshal.ReleaseComObject(part);
          part = null;
        }
        if (partSync != null)
        {
          Marshal.ReleaseComObject(partSync);
          partSync = null;
        }
        if (sheetmetal != null)
        {
          Marshal.ReleaseComObject(sheetmetal);
          sheetmetal = null;
        }
        if (weldment != null)
        {
          Marshal.ReleaseComObject(weldment);
          weldment = null;
        }
        if (documents != null)
        {
          Marshal.ReleaseComObject(documents);
          documents = null;
        }
        if (application != null)
        {
          Marshal.ReleaseComObject(application);
          application = null;
        }
      }
    }
  }
}

Edit

Determining Document Type

Visual Basic .NET
Imports System.Runtime.InteropServices
Imports SolidEdgeFramework
Module Module1
  Sub Main()
    Dim objApplication As SolidEdgeFramework.Application = Nothing
    Dim objDocument As SolidEdgeFramework.SolidEdgeDocument = Nothing

    Try
      ' Connect to a running instance of Solid Edge. 
      objApplication = Marshal.GetActiveObject("SolidEdge.Application")
      ' Get a reference to the active document 
      objDocument = objApplication.ActiveDocument
      ' Using Type property, determine document type 
      Select Case objDocument.Type
        Case DocumentTypeConstants.igAssemblyDocument
          Console.WriteLine("Assembly Document")
        Case DocumentTypeConstants.igDraftDocument
          Console.WriteLine("Draft Document")
        Case DocumentTypeConstants.igPartDocument
          Console.WriteLine("Part Document")
        Case DocumentTypeConstants.igSheetMetalDocument
          Console.WriteLine("SheetMetal Document")
        Case DocumentTypeConstants.igSyncAssemblyDocument
          Console.WriteLine("Synchronous Assembly Document")
        Case DocumentTypeConstants.igSyncPartDocument
          Console.WriteLine("Synchronous Part Document")
        Case DocumentTypeConstants.igSyncSheetMetalDocument
          Console.WriteLine("Synchronous Sheet Metal Document")
        Case DocumentTypeConstants.igUnknownDocument
          Console.WriteLine("Unknown Document")
        Case DocumentTypeConstants.igWeldmentAssemblyDocument
          Console.WriteLine("Weldment Assembly Document")
        Case DocumentTypeConstants.igWeldmentDocument
          Console.WriteLine("Weldment Document")
      End Select
    Catch ex As Exception
      Console.WriteLine(ex.Message)
    Finally
      If Not (objDocument Is Nothing) Then
        Marshal.ReleaseComObject(objDocument)
        objDocument = Nothing
      End If
      If Not (objApplication Is Nothing) Then
        Marshal.ReleaseComObject(objApplication)
        objApplication = Nothing
      End If
    End Try
  End Sub
End Module

C#
using SolidEdgeFramework;
using System;
using System.Runtime.InteropServices;
namespace MyMacro
{
  class Program
  {
    static void Main(string[] args)
    {
      SolidEdgeFramework.Application application = null;
      SolidEdgeFramework.SolidEdgeDocument document = null;

      try
      {
        // Connect to a running instance of Solid Edge. 
        application = (SolidEdgeFramework.Application)
        Marshal.GetActiveObject("SolidEdge.Application");
        // Get a reference to the active document 
        document = (SolidEdgeFramework.SolidEdgeDocument)
        application.ActiveDocument;
        // Using Type property, determine document type 
        switch (document.Type)
        {
          case DocumentTypeConstants.igAssemblyDocument:
            Console.WriteLine("Assembly Document");
            break;
          case DocumentTypeConstants.igDraftDocument:
            Console.WriteLine("Draft Document");
            break;
          case DocumentTypeConstants.igPartDocument:
            Console.WriteLine("Part Document");
            break;
          case DocumentTypeConstants.igSheetMetalDocument:
            Console.WriteLine("SheetMetal Document");
            break;
          case DocumentTypeConstants.igSyncAssemblyDocument:
            Console.WriteLine("Synchronous Assembly Document");
            break;
          case DocumentTypeConstants.igSyncPartDocument:
            Console.WriteLine("Synchronous Part Document");
            break;
          case DocumentTypeConstants.igSyncSheetMetalDocument:
            Console.WriteLine("Synchronous Sheet Metal Document");
            break;
          case DocumentTypeConstants.igUnknownDocument:
            Console.WriteLine("Unknown Document");
            break;
          case DocumentTypeConstants.igWeldmentAssemblyDocument:
            Console.WriteLine("Weldment Assembly Document");
            break;
          case DocumentTypeConstants.igWeldmentDocument:
            Console.WriteLine("Weldment Document");
            break;
        }
      }
      catch (System.Exception ex)
      {
        Console.WriteLine(ex.Message);
      }
      finally
      {
        if (document != null)
        {
          Marshal.ReleaseComObject(document);
          document = null;
        }
        if (application != null)
        {
          Marshal.ReleaseComObject(application);
          application = null;
        }
      }
    }
  }
}

Edit

Working with File Properties (PropAuto.dll)

Visual C++

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

// The following macros define the minimum required platform.  The minimum required platform
// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 
// your application.  The macros work by enabling all features available on platform versions up to and 
// including the version specified.

// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER                  // Specifies that the minimum required platform is Windows Vista.
#define WINVER 0x0600           // Change this to the appropriate value to target other versions of Windows.
#endif

#ifndef _WIN32_WINNT            // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600     // Change this to the appropriate value to target other versions of Windows.
#endif

#ifndef _WIN32_WINDOWS          // Specifies that the minimum required platform is Windows 98.
#define _WIN32_WINDOWS 0x0410   // Change this to the appropriate value to target Windows Me or later.
#endif

#ifndef _WIN32_IE               // Specifies that the minimum required platform is Internet Explorer 7.0.
#define _WIN32_IE 0x0700        // Change this to the appropriate value to target other versions of IE.
#endif

#include 
#include 


#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // some CString constructors will be explicit

#include 
#include 

#define IfFailGo(x) { hr=(x); if (FAILED(hr)) goto Error; }
#define IfFailGoCheck(x, p) { hr=(x); if (FAILED(hr)) goto Error; if(!p) {hr = E_FAIL; goto Error; } }

#import "libid:AED8FE52-3129-11D1-BC83-0800360E1E02"
using namespace SolidEdgeFileProperties;



// PropAutoExample.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

void ModifyCustomProperty(SolidEdgeFileProperties::IJPropertiesPtr pProperties, _bstr_t Name, const _variant_t & Value);

int _tmain(int argc, _TCHAR* argv[])
{
    if (argc <= 1) return -1;

    HRESULT hr = S_OK;

    CoInitialize(NULL);

    /* Note the [Type]Ptr.  These are smart-pointers */
    SolidEdgeFileProperties::IJPropertySetsPtr pPropertySets = NULL;
    SolidEdgeFileProperties::IJPropertiesPtr pProperties = NULL;
    SolidEdgeFileProperties::IJPropertyPtr pProperty = NULL;

    /* Create an instance of SolidEdge.FileProperties */
    IfFailGo(pPropertySets.CreateInstance(_T("SolidEdge.FileProperties")));

    /* Open document for read/write */
    IfFailGo(pPropertySets->Open(argv[1], VARIANT_FALSE));

    /* Example of how to loop through PropertySets */
    for (LONG i = 0; i < pPropertySets->Count; i++)
    {
        pProperties = pPropertySets->GetItem(_variant_t(i));
        CString strPropertySetName = pProperties->Name;

        /* Example of how to loop through Properties */
        for (LONG j = 0; j < pProperties->Count; j++)
        {
            pProperty = pProperties->GetItem(_variant_t(j));
            CString strPropertyName = pProperty->Name;
        }
    }

    /* Get custom properties */
    pProperties = pPropertySets->GetItem(_variant_t(_T("Custom")));

    /* ModifyCustomProperty will either modify or add the custom property */
    ModifyCustomProperty(pProperties, _T("My Custom String Property"), _variant_t(_T("Hello")));
    ModifyCustomProperty(pProperties, _T("My Custom Number Property"), _variant_t((LONG)123));
    ModifyCustomProperty(pProperties, _T("My Custom Boolean Property"), _variant_t(VARIANT_TRUE, VT_BOOL));

    /* Save Custom PropertySet */
    IfFailGo(pProperties->Save());

    /* Save document */
    IfFailGo(pPropertySets->Save());

Error:
    /* Close document */
    if (pPropertySets != NULL) hr = pPropertySets->Close();

    /* Release smart-pointers */
    pProperty = NULL;
    pProperties = NULL;
    pPropertySets = NULL;

    CoUninitialize();
    return 0;
}

void ModifyCustomProperty(SolidEdgeFileProperties::IJPropertiesPtr pProperties, _bstr_t Name, const _variant_t & Value)
{
    SolidEdgeFileProperties::IJPropertyPtr pProperty = NULL;

    /* GetItem will throw an exception if item does not exist */
    _ATLTRY
    {
        pProperty = pProperties->GetItem(Name);
        pProperty->Value = Value;
    }
    _ATLCATCHALL()
    {
        pProperty = pProperties->Add(Name, Value);
    }

    pProperty = NULL;
}