.NET programmers Guide Creating Documents Exemple (VB.net) , I need explanation

Valued Contributor
Valued Contributor

Hi,

Doing my best to learn from the examples in the Programmers Guide,the startsolid edge example works fine and I understand what it does. When I get around to the Creating Documents Example, I am able to run it every thing seems logical but all it does is open a new solid edge.

Imports System.Runtime.InteropServices
Module Module1

    Sub Main()

        Dim objApp As SolidEdgeFramework.Application = Nothing
        Dim objDocuments As SolidEdgeFramework.Application = Nothing
        Dim ObjAssembly As SolidEdgeAssembly.AssemblyDocument = Nothing
        Dim objDraft As SolidEdgeDraft.DraftDocument = Nothing
        Dim objPart As SolidEdgePart.PartDocument = Nothing
        Dim ObjSheetMetal As SolidEdgePart.SheetMetalDocument = Nothing
        Dim objType As Type

        Try
            objType = Type.GetTypeFromProgID("SolidEdge.Application")
            objApp = Activator.CreateInstance(objType)
            objApp.Visible = True
            objDocuments = objApp.Documents
            objAssembly = objDocuments.Add("SolidEdge.AssemblyDocument")
            objDraft = objDocuments.Add("SolidEdge.DraftDocument")
            objPart = objDocuments.Add("SolidEdge.PartDocument")
            objSheetMetal = ObjDocuments.Add("SolidEdge.SheetMetalDocument")

        Catch ex As Exception
            Console.WriteLine(ex.Message)
        Finally
            If Not (ObjAssembly Is Nothing) Then
                Marshal.ReleaseComObject(ObjAssembly)
                objAssembly = 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 (ObjSheetMetal Is Nothing) Then
                Marshal.ReleaseComObject(ObjSheetMetal)
                objSheetMetal = 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

I Need explanation, trying to learn here.

Thanks

ST9
Conveyor and industrial equipment designer.
Giving SE a chance.
5 REPLIES

Re: .NET programmers Guide Creating Documents Exemple (VB.net) , I need explanation

Phenom
Phenom

That's right. In the line

objApp = Activator.CreateInstance(objType)

CreateInstance creates a new instance of Solid Edge each time you run the program followed by creating the new documents.

 

To create new documents in an existing Solid Edge, need to use

objApp = Marshal.GetActiveObject("SolidEdge.Application")

 

~Tushar

 

Re: .NET programmers Guide Creating Documents Exemple (VB.net) , I need explanation

Valued Contributor
Valued Contributor

Problems is, it doesnt go on to

creating the new documents.

 

 
ST9
Conveyor and industrial equipment designer.
Giving SE a chance.

Re: .NET programmers Guide Creating Documents Exemple (VB.net) , I need explanation

Phenom
Phenom

In your post, objDocuments is declared as Application.

It should be declared as Documents:

Dim objDocuments As SolidEdgeFramework.Documents = Nothing

 

~Tushar

www.SurfAndCode.in

 

Re: .NET programmers Guide Creating Documents Exemple (VB.net) , I need explanation

Valued Contributor
Valued Contributor

Oops!That's embarrassing. Thank you very much, I'll try to make sure I write the right thing before posting next time!

ST9
Conveyor and industrial equipment designer.
Giving SE a chance.

Re: .NET programmers Guide Creating Documents Exemple (VB.net) , I need explanation

Phenom
Phenom

Smiley Happy

I am in knowledge you have started learning SE programming recently.

These mistakes are not uncommon.

 

~Tushar