Solid Edge ST7 SDK
Creating Documents

All Solid Edge document objects implement the SolidEdgeFramework.SolidEdgeDocument interface. This generic interface allows document ambiguity when you don't know what type of document that you're working with.

The following table lists the classes (also called ProgIDs) associated with Solid Edge and each type of document environment. These class names can be used in the Visual Basic function CreateObject and can also be used in the Add method of the Documents object.

ProgID Type Description
SolidEdge.AssemblyDocument AssemblyDocument Object Solid Edge Assembly Document
SolidEdge.DraftDocument DraftDocument Object Solid Edge Draft Document
SolidEdge.PartDocument PartDocument Object Solid Edge Part Document
SolidEdge.SheetMetalDocument SheetMetalDocument Object Solid Edge Sheet Metal Document
See Handling 'Application is Busy' and 'Call was Rejected By Callee' errors for information regarding the use of OleMessageFilter.
Creating Documents from Visual Basic .NET
Copy Code
Imports System.IO
Imports System.Runtime.InteropServices

Module Program
    <DllImport("ole32.dll", CharSet:=CharSet.Unicode, PreserveSig:=False)> _
    Function ProgIDFromCLSID(ByRef clsid As Guid) As String
    End Function

    <STAThread()> _
    Sub Main()
        Dim objApplication As SolidEdgeFramework.Application = Nothing
        Dim objAssemblyDocument As SolidEdgeAssembly.AssemblyDocument = Nothing
        Dim objDraftDocument As SolidEdgeDraft.DraftDocument = Nothing
        Dim objPartDocument As SolidEdgePart.PartDocument = Nothing
        Dim objSheetMetalDocument As SolidEdgePart.SheetMetalDocument = Nothing

        Try
            OleMessageFilter.Register()

            ' Connect to Solid Edge
            objApplication = Marshal.GetActiveObject("SolidEdge.Application")

            ' Create new SolidEdgeAssembly.AssemblyDocument.
            objAssemblyDocument = CreateSolidEdgeDocument(objApplication, GetType(SolidEdgeAssembly.AssemblyDocument))

            ' Create new SolidEdgeDraft.DraftDocument.
            objDraftDocument = CreateSolidEdgeDocument(objApplication, GetType(SolidEdgeDraft.DraftDocument))

            ' Create new SolidEdgePart.PartDocument.
            objPartDocument = CreateSolidEdgeDocument(objApplication, GetType(SolidEdgePart.PartDocument))

            ' Create new SolidEdgePart.SheetMetalDocument.
            objSheetMetalDocument = CreateSolidEdgeDocument(objApplication, GetType(SolidEdgePart.SheetMetalDocument))
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        Finally
            OleMessageFilter.Revoke()
        End Try
    End Sub

    Function CreateSolidEdgeDocument(objApplication As SolidEdgeFramework.Application, objType As Type) As Object
        Dim objGuid As Guid
        Dim strProgId As String
        Dim objDocuments As SolidEdgeFramework.Documents

        ' Get the Type GUID.
        objGuid = objType.GUID

        ' Get the ProgId for the specified Type.
        strProgId = ProgIDFromCLSID(objGuid)

        ' Get a reference to the Documents object.
        objDocuments = objApplication.Documents

        ' Add specified document.
        Return objDocuments.Add(strProgId)
    End Function


End Module
Creating Documents from C#
Copy Code
using System;
using System.Reflection;
using System.Runtime.InteropServices;

namespace SolidEdge.SDK
{
    class Program
    {
        [DllImport("ole32.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
        static extern string ProgIDFromCLSID([In()]ref Guid clsid);

        [STAThread]
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;
            SolidEdgeAssembly.AssemblyDocument assemblyDocument = null;
            SolidEdgeDraft.DraftDocument draftDocument = null;
            SolidEdgePart.PartDocument partDocument = null;
            SolidEdgePart.SheetMetalDocument sheetMetalDocument = null;

            try
            {
                OleMessageFilter.Register();

                // Connect to a running instance of Solid Edge.
                application = (SolidEdgeFramework.Application)
                    Marshal.GetActiveObject("SolidEdge.Application");

                // Create new SolidEdgeAssembly.AssemblyDocument.
                assemblyDocument = (SolidEdgeAssembly.AssemblyDocument)
                    CreateSolidEdgeDocument(application, typeof(SolidEdgeAssembly.AssemblyDocument));

                // Create new SolidEdgeDraft.DraftDocument.
                draftDocument = (SolidEdgeDraft.DraftDocument)
                    CreateSolidEdgeDocument(application, typeof(SolidEdgeDraft.DraftDocument));

                // Create new SolidEdgePart.PartDocument.
                partDocument = (SolidEdgePart.PartDocument)
                    CreateSolidEdgeDocument(application, typeof(SolidEdgePart.PartDocument));

                // Create new SolidEdgePart.SheetMetalDocument.
                sheetMetalDocument = (SolidEdgePart.SheetMetalDocument)
                    CreateSolidEdgeDocument(application, typeof(SolidEdgePart.SheetMetalDocument));
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                OleMessageFilter.Revoke();
            }
        }

        static object CreateSolidEdgeDocument(SolidEdgeFramework.Application application, Type t)
        {
            // Get the Type GUID.
            Guid guid = t.GUID;

            // Get the ProgId for the specified Type.
            string progId = ProgIDFromCLSID(ref guid);

            // Get a reference to the Documents object.
            SolidEdgeFramework.Documents documents = application.Documents;

            // Add specified document.
            return documents.Add(progId, Missing.Value);
        }
    }
}
See Also