Beginner Programmer Help

 

Hi,

I am a beginner programmer trying to learn VB.net. I have no prior experience with VB so I am going through the Solid Edge's Programming help booklet that accompanies the software but I'm running into an issue. Here is my Code:

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 objDraft As SolidEdgeDraft.DraftDocument = Nothing                                       

        Dim objPart As SolidEdgePart.PartDocument = Nothing                                           

        Dim objSheetMetal As SolidEdgePart.SheetmetalDocument = Nothing                

        Dim objWeldment As SolidEdgePart.WeldmentDocument = Nothing                     

        Dim objType As Type

 

        Try

            'Old VB

            objApp = CreateObject("SolidEdge.Application")

            'New VisualBasic.net Syntax

            objApp = Type.GetTypeFromProgID("SolidEdge.application")

            'Starting Solid Edge

            objApp.Activator.CreateInstance(objType)

            'Make Solid Edge visible

            objApp.Visible = True

            'Turn off Alers (Weldment will display alert)

            objApp.DisplayAlerts = False

            'Get reference to the documents collection

            objDocuments = objApp.Documents

            'Create an instance of each document environment

            objAssembly = objDocuments.Add("SolidEdge.AssemblyDocument")

            objDraft = objDraft.Add("SolidEdge.DraftDocument")

            objPart = objDocuments.Add("SolidEdge.PartDocument")

            objSheetMetal = objDocuments.Add("SolidEdge.SheetmetalDocument")

            objWeldment = objDocuments.Add("SolidEdge.Weldmentdocument")

 

            'Turn on Alerts

            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 (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 (objWeldment Is Nothing) Then

                Marshal.ReleaseComObject(objWeldment)

                objWeldment = Nothing

            End If

 

        End Try

 

    End Sub

 

End Module

 

 

My first question is are those things that I need to define or are they something that should be defined in the SolidEdgeFramework file?

My second is what can I do to fix this?

Thanks,

 

Patrick Roche

 

Posted by: Patrick Roche
Post date: 11/23/2008 8:53:35 AM

3 REPLIES

RE: Beginner Programmer Help

Hi Patrick

 

Have you added references to the Solid Edge Assembly Type Library, Solid Edge Part Type Library and Solid Edge Geometry Type Library?

 

If you haven't you should be able to under Project Properties -> References

 

Posted by: Nick Whitehead
Post date: 11/23/2008 10:18:55 PM

RE: Beginner Programmer Help

 

Thank you that resolved the issue.

 

-Patrick Roche

 

Posted by: Patrick Roche
Post date: 11/26/2008 11:22:28 AM

RE: Beginner Programmer Help

I have another question. I have gotten my program to open Solid Edge ST, create a part file but it does not seem to draw either the profile or protrude the part. Below is my code. Has anyone else ever experienced this and what was the solution to the problem?

 

Imports SolidEdgeFramework

Imports System.Runtime.InteropServices

Imports SolidEdgeConstants

 

Module Module1

Private Sub Form_Load()

 

End Sub

Sub Main()

 

Dim objApp As SolidEdgeFramework.Application = Nothing

Dim objApplication As SolidEdgeFramework.Application = Nothing

Dim objDocuments As SolidEdgeFramework.Documents = Nothing

Dim objPart As SolidEdgePart.PartDocument = Nothing

Dim objProfileSets As SolidEdgePart.ProfileSets = Nothing

Dim objProfileSet As SolidEdgePart.ProfileSet = Nothing

Dim objProfiles As SolidEdgePart.Profiles = Nothing

Dim objProfile As SolidEdgePart.Profile = Nothing

Dim objRefPlanes As SolidEdgePart.RefPlanes = Nothing

Dim objRefPlane As SolidEdgePart.RefPlane = Nothing

Dim objRelations2d As SolidEdgeFrameworkSupport.Relations2d = Nothing

Dim objRelation2d As SolidEdgeFrameworkSupport.Relation2d = Nothing

Dim objLines2d As SolidEdgeFrameworkSupport.Lines2d = Nothing

Dim objLine2d As SolidEdgeFrameworkSupport.Line2d = Nothing

Dim objModels As SolidEdgePart.Models = Nothing

Dim ObjModel As SolidEdgePart.Model = Nothing

Dim objDimensions As SolidEdgeFrameworkSupport.Dimensions = Nothing

Dim objDimension As SolidEdgeFrameworkSupport.Dimension = Nothing

Dim objDimStyle As SolidEdgeFrameworkSupport.DimStyle = Nothing

Dim aProfiles As Array

Dim objType As Type

 

Try

'Old VB

objApp = CreateObject("SolidEdge.application")

'New VisualBasic.net Syntax

objType = Type.GetTypeFromProgID("SolidEdge.application")

'Make Solid Edge visible

objApp.Visible = True

'Turn off Alerts (Weldment will display alert)

objApp.DisplayAlerts = False

'Get reference to the documents collection

objDocuments = objApp.Documents

'Create Part

objPart = objDocuments.Add("SolidEdge.PartDocument")

'Turn on Alerts

objApp.DisplayAlerts = True

 

Catch ex As Exception

Console.WriteLine(ex.Message)

Finally

If Not (objPart Is Nothing) Then

Marshal.ReleaseComObject(objPart)

objPart = Nothing

End If

 

End Try

 

'Take a quick break to make sure everything is up to speed

 

Try

'Connect to SolidEdge. Activated earlier in program.

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

 

'Get Collection of Documents

objDocuments = objApplication.Documents

 

'Create new Part

objPart = objApplication.Add("SolidEdge.PartDocument")

 

'Reference profile sets collection

objProfileSets = objPart.ProfileSets

 

'Add new profile

objProfileSet = objprofileSets.Add()

 

'Get reference to profiles

objProfiles = objProfileSet.Profiles

 

'Ref Reference Planes

objRefPlanes = objPart.RefPlanes

 

'Add new Profile

objProfile = objProfileSet.Profiles

 

'Reference lines2d

objLines2d = objProfile.Lines2d

 

'This is where we start defining our geometry

'Draw Profile

objLine2d = objLines2d.AddBy2Points(0, 0, 0, 1)

objLine2d = objLines2d.AddBy2Points(0, 1, 0.125, 1)

objLine2d = objLines2d.AddBy2Points(0.125, 1, 0.125, 0.125)

objLine2d = objLines2d.AddBy2Points(0.125, 0.125, 1, 0.125)

objLine2d = objLines2d.AddBy2Points(1, 0.125, 1, 0)

objLine2d = objLines2d.AddBy2Points(1, 0, 0, 0)

 

'Connect Lines together via relationships

objRelation2d = objProfile.Relation2d

objRelation2d = objRelation2d.AddKeypoint(objLines2d.Item(1), KeypointIndexConstants.igLineEnd, objLines2d.Item(2), KeypointIndexConstants.igLineStart)

objRelation2d = objProfile.Relation2d

objRelation2d = objRelation2d.AddKeypoint(objLines2d.Item(2), KeypointIndexConstants.igLineEnd, objLines2d.Item(3), KeypointIndexConstants.igLineStart)

objRelation2d = objProfile.Relation2d

objRelation2d = objRelation2d.AddKeypoint(objLines2d.Item(3), KeypointIndexConstants.igLineEnd, objLines2d.Item(4), KeypointIndexConstants.igLineStart)

objRelation2d = objProfile.Relation2d

objRelation2d = objRelation2d.AddKeypoint(objLines2d.Item(4), KeypointIndexConstants.igLineEnd, objLines2d.Item(5), KeypointIndexConstants.igLineStart)

objRelation2d = objProfile.Relation2d

objRelation2d = objRelation2d.AddKeypoint(objLines2d.Item(5), KeypointIndexConstants.igLineEnd, objLines2d.Item(6), KeypointIndexConstants.igLineStart)

objRelation2d = objProfile.Relation2d

objRelation2d = objRelation2d.AddKeypoint(objLines2d.Item(6), KeypointIndexConstants.igLineEnd, objLines2d.Item(1), KeypointIndexConstants.igLineStart)

 

'Close Profile

objProfile.End(SolidEdgePart.ProfileValidationType.igProfileClosed)

 

'Hide Profile

objProfile.Visible = True

 

'Create an array of profile objects

aProfiles = Array.CreateInstance(GetType(SolidEdgePart.Profile), 1)

aProfiles.SetValue(objProfile, 0)

 

'Reference to model

ObjModel = objPart.Models

 

'Protrude

ObjModel = objModels.AddFiniteExtrudedProtrusion(aProfiles.Length, aProfiles, SolidEdgePart.FeaturePropertyConstants.igRight, 6)

 

Catch ex As Exception

Finally

If Not (ObjModel Is Nothing) Then

Marshal.ReleaseComObject(ObjModel)

ObjModel = Nothing

End If

If Not (objModels Is Nothing) Then

Marshal.ReleaseComObject(objModels)

objModels = Nothing

End If

If Not (objRelations2d Is Nothing) Then

Marshal.ReleaseComObject(objRelations2d)

objRelations2d = Nothing

End If

If Not (objLine2d Is Nothing) Then

Marshal.ReleaseComObject(objLine2d)

objLine2d = Nothing

End If

If Not (objLines2d Is Nothing) Then

Marshal.ReleaseComObject(objLines2d)

objLines2d = Nothing

End If

If Not (objRelation2d Is Nothing) Then

Marshal.ReleaseComObject(objRelation2d)

objRelation2d = Nothing

End If

If Not (objRefPlanes Is Nothing) Then

Marshal.ReleaseComObject(objRefPlanes)

objRefPlanes = Nothing

End If

If Not (objProfile Is Nothing) Then

Marshal.ReleaseComObject(objProfile)

objProfile = Nothing

End If

If Not (objProfiles Is Nothing) Then

Marshal.ReleaseComObject(objProfiles)

objProfiles = Nothing

End If

If Not (objProfileSet Is Nothing) Then

Marshal.ReleaseComObject(objProfileSet)

objProfileSet = Nothing

End If

If Not (objProfileSets Is Nothing) Then

Marshal.ReleaseComObject(objProfileSets)

objProfileSets = Nothing

End If

If Not (objPart Is Nothing) Then

Marshal.ReleaseComObject(objPart)

objPart = Nothing

End If

If Not (objDocuments Is Nothing) Then

Marshal.ReleaseComObject(objDocuments)

objDocuments = Nothing

End If

If Not (objApplication Is Nothing) Then

Marshal.ReleaseComObject(objApplication)

objApplication = Nothing

End If

End Try

Console.Write("Press Enter to Continue")

Console.ReadLine()

End Sub

End Module

 

Posted by: Patrick Roche
Post date: 12/1/2008 3:33:49 PM