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.
2 REPLIES

Re: Part Modeling Example Problem

Phenom
Phenom

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

Phenom
Phenom

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