Cancel
Showing results for 
Search instead for 
Did you mean: 

Part Modeling Example Problem

Valued Contributor
Valued Contributor

Hi I'm running the Modeling a Part(Visual Basic .NET) example from the ".NET Programmer's guide" for SolidEdge and I get no errors but the processe stops after creating the part document..then nothing happens.

Imports System.Runtime.InteropServices
Imports SolidEdgeConstants


Module Module1

    Sub Main()
        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 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 aProfiles As Array
        Try
            objApplication = Marshal.GetActiveObject("SolidEdge.Application")
            objDocuments = objApplication.Documents
            objDocuments = objApplication.Documents.Add("SolidEdge.PartDocument")
            objProfileSets = objPart.ProfileSets
            objProfileSet = objProfileSets.Add()
            objProfiles = objProfileSet.Profiles
            objRefplanes = objPart.RefPlanes
            objProfile = objProfiles.Add(objRefplanes.Item(3))
            objLines2d = objProfile.Lines2d
            objLine2d = objLines2d.AddBy2Points(0, 0, 0.08, 0)
            objLine2d = objLines2d.AddBy2Points(0.08, 0, 0.08, 0.06)
            objLine2d = objLines2d.AddBy2Points(0.08, 0.06, 0.064, 0.06)
            objLine2d = objLines2d.AddBy2Points(0.064, 0.06, 0.064, 0.02)
            objLine2d = objLines2d.AddBy2Points(0.064, 0.02, 0.048, 0.02)
            objLine2d = objLines2d.AddBy2Points(0.048, 0.02, 0.048, 0.06)
            objLine2d = objLines2d.AddBy2Points(0.048, 0.06, 0.032, 0.06)
            objLine2d = objLines2d.AddBy2Points(0.032, 0.06, 0.032, 0.02)
            objLine2d = objLines2d.AddBy2Points(0.032, 0.02, 0.016, 0.02)
            objLine2d = objLines2d.AddBy2Points(0.016, 0.02, 0.016, 0.06)
            objLine2d = objLines2d.AddBy2Points(0.016, 0.06, 0, 0.06)
            objLine2d = objLines2d.AddBy2Points(0, 0.06, 0, 0)
            objRelations2d = objProfile.Relations2d
            objRelation2d = objRelations2d.AddKeypoint( _
            objLines2d.Item(1), _
            KeypointIndexConstants.igLineEnd, _
            objLines2d.Item(2), _
            KeypointIndexConstants.igLineStart)
            objRelation2d = objRelations2d.AddKeypoint( _
            objLines2d.Item(2), _
            KeypointIndexConstants.igLineEnd, _
            objLines2d.Item(3), _
            KeypointIndexConstants.igLineStart)
            objRelation2d = objRelations2d.AddKeypoint( _
            objLines2d.Item(3), _
            KeypointIndexConstants.igLineEnd, _
            objLines2d.Item(4), _
            KeypointIndexConstants.igLineStart)
            objRelation2d = objRelations2d.AddKeypoint( _
            objLines2d.Item(4), _
            KeypointIndexConstants.igLineEnd, _
            objLines2d.Item(5), _
            KeypointIndexConstants.igLineStart)
            objRelation2d = objRelations2d.AddKeypoint( _
            objLines2d.Item(5), _
            KeypointIndexConstants.igLineEnd, _
            objLines2d.Item(6), _
            KeypointIndexConstants.igLineStart)
            objRelation2d = objRelations2d.AddKeypoint( _
            objLines2d.Item(6), _
            KeypointIndexConstants.igLineEnd, _
            objLines2d.Item(7), _
            KeypointIndexConstants.igLineStart)
            objRelation2d = objRelations2d.AddKeypoint( _
            objLines2d.Item(7), _
            KeypointIndexConstants.igLineEnd, _
            objLines2d.Item(8), _
            KeypointIndexConstants.igLineStart)
            objRelation2d = objRelations2d.AddKeypoint( _
            objLines2d.Item(8), _
            KeypointIndexConstants.igLineEnd, _
            objLines2d.Item(9), _
            KeypointIndexConstants.igLineStart)
            objRelation2d = objRelations2d.AddKeypoint( _
            objLines2d.Item(9), _
            KeypointIndexConstants.igLineEnd, _
            objLines2d.Item(10), _
            KeypointIndexConstants.igLineStart)
            objRelation2d = objRelations2d.AddKeypoint( _
            objLines2d.Item(10), _
            KeypointIndexConstants.igLineEnd, _
            objLines2d.Item(11), _
            KeypointIndexConstants.igLineStart)
            objRelation2d = objRelations2d.AddKeypoint( _
            objLines2d.Item(11), _
            KeypointIndexConstants.igLineEnd, _
            objLines2d.Item(12), _
            KeypointIndexConstants.igLineStart)
            objRelation2d = objRelations2d.AddKeypoint( _
            objLines2d.Item(12), _
            KeypointIndexConstants.igLineEnd, _
            objLines2d.Item(1), _
            KeypointIndexConstants.igLineStart)

            ' Close the profile
            objProfile.End( _
            SolidEdgePart.ProfileValidationType.igProfileClosed)
            ' Hide the profile
            objProfile.Visible = False
            ' Create a new array of profile objects
            aProfiles = Array.CreateInstance(GetType(SolidEdgePart.Profile), 1)
            aProfiles.SetValue(objProfile, 0)
            ' Get a reference to the models collection
            objModels = objPart.Models
            ' Create the extended protrusion.
            objModel = objModels.AddFiniteExtrudedProtrusion( _
            aProfiles.Length, _
            aProfiles, _
            SolidEdgePart.FeaturePropertyConstants.igRight, _
            0.05)
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        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
    End Sub
End Module

I seem to have this problem constantly with the examples.

Any one else have this problem ,Thanks.

Again , trying to learn here . Smiley Happy

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

Re: Part Modeling Example Problem

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

I tried the example by copy-pasting the code posted with one change:

objPart = objApplication.ActiveDocument (instead of add a new part document)

It worked fine.

Add document was not working for me.

 

extrude1.png

 

~Tushar

www.SurfAndCode.in

Re: Part Modeling Example Problem

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

Looks like someone else has too posted the same question earlier which remains unanswered.

Re: Part Modeling Example Problem

Experimenter
Experimenter

Hello, This seems like quite and old thread but it does not seem to have been answered fully. I am new to using SE but have used VB for quite some time. 

 

Pedneault75 I think the first thing that might be causing you a problem is -

 

objDocuments = objApplication.Documents
objDocuments = objApplication.Documents.Add("SolidEdge.PartDocument")

the second line should either be objPart or objDocument (no 's') this means you can reuse objDocuments if you wished to create more documents. This is still wrong as you are just doing the same thing twice in the space of two lines. 

 

and should be -  

 

objDocuments = objApplication.Documents
objDocument = objDocuments.Add("SolidEdge.PartDocument")

 

for some reason in the guid objDocumnets is created then never used and the add method is used on objApplication (which does not have a add method) not objApplication.documents (which does) 

 

However this might not work anyway. From what I can gather this has been copied from an older version of the programmers guid.

 

to add a document properly the following functions should be created/used - 

 

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

 

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

 

then the part created within sub Main -

 

objPart = CreateSolidEdgeDocument(objApplication, GetType(SolidEdgePart.PartDocument)) 

 

This is my first time posting hope it helps anyone who was stuck like I was.

Re: Part Modeling Example Problem

Experimenter
Experimenter

Sorry about my formating, in the CreateSolidEdgeDocument function the comments and the code should obviously be on separate lines.