FiniteRevolvedProtrusion

Hello,

I am workin on a bit of code that would automate the creation of O-rings, but i am stuck on creating the revolved feature, and would appreciate any help. When running the code it works all the way to the model creation, then i get an error message. I am kind of new to SE automation so any suggestions are welcome.

arav.jpg

 

The code is below:

_____________________________________________

Imports SolidEdgeConstants
Imports System.Runtime.InteropServices
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 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 aLine(0 To 3) As SolidEdgeFrameworkSupport.Line2d
        Dim objModels As SolidEdgePart.Models = Nothing
        Dim objModel As SolidEdgePart.Model = Nothing
        Dim objRounds As SolidEdgePart.Rounds = Nothing
        Dim objRound As SolidEdgePart.Round = Nothing
        Dim objAxes As SolidEdgePart.RefAxes = Nothing
        Dim aProfile As Array
        Try
            objApplication = Marshal.GetActiveObject("SolidEdge.Application")
            objDocuments = objApplication.Documents
            objPart = objDocuments.Add("SolidEdge.PartDocument")
            objRefPlanes = objPart.RefPlanes
            objRefPlane = objRefPlanes.Item(3)
            objProfileSets = objPart.ProfileSets
            objProfileSet = objProfileSets.Add()
            objProfiles = objProfileSet.Profiles
            objProfile = objProfiles.Add(objRefPlane)

            objLines2d = objProfile.Lines2d
            objRelations2d = objProfile.Relations2d

            aLine(0) = objLines2d.AddBy2Points(0, 0.02, 0.0045, 0.02)
            aLine(1) = objLines2d.AddBy2Points(0.0045, 0.02, 0.0045, 0.0227)
            aLine(2) = objLines2d.AddBy2Points(0.0045, 0.0227, 0, 0.0227)
            aLine(3) = objLines2d.AddBy2Points(0, 0.0227, 0, 0.02)

            objRelations2d.AddKeypoint(aLine(0), KeypointIndexConstants.igLineEnd, aLine(1), KeypointIndexConstants.igLineStart)
            objRelations2d.AddKeypoint(aLine(1), KeypointIndexConstants.igLineEnd, aLine(2), KeypointIndexConstants.igLineStart)
            objRelations2d.AddKeypoint(aLine(2), KeypointIndexConstants.igLineEnd, aLine(3), KeypointIndexConstants.igLineStart)
            objRelations2d.AddKeypoint(aLine(3), KeypointIndexConstants.igLineEnd, aLine(0), KeypointIndexConstants.igLineStart)

            objAxes = objProfile.SetAxisOfRevolution(objLines2d.AddBy2Points(0, 0, 0.1, 0))

            aProfile = Array.CreateInstance(GetType(SolidEdgePart.Profile), 1)
            aProfile.SetValue(objProfile, 0)

            objModels = objPart.Models
            objModel = objModels.AddFiniteRevolvedProtrusion(aProfile.Length, aProfile, objAxes, SolidEdgePart.FeaturePropertyConstants.igLeft, Math.PI)

        Catch ex As Exception
            Console.WriteLine(ex.Message)
            Console.ReadKey()
        End Try
        If Not (objApplication Is Nothing) Then
            Marshal.ReleaseComObject(objApplication)
            objApplication = Nothing
        End If
        If Not (objDocuments Is Nothing) Then
            Marshal.ReleaseComObject(objDocuments)
            objDocuments = Nothing
        End If
        If Not (objPart Is Nothing) Then
            Marshal.ReleaseComObject(objPart)
            objPart = Nothing
        End If
        If Not (objProfileSets Is Nothing) Then
            Marshal.ReleaseComObject(objProfileSets)
            objProfileSets = Nothing
        End If
        If Not (objProfileSet Is Nothing) Then
            Marshal.ReleaseComObject(objProfileSet)
            objProfileSet = Nothing
        End If
        If Not (objProfiles Is Nothing) Then
            Marshal.ReleaseComObject(objProfiles)
            objProfiles = Nothing
        End If
        If Not (objProfile Is Nothing) Then
            Marshal.ReleaseComObject(objProfile)
            objProfile = Nothing
        End If
        If Not (objRefPlanes Is Nothing) Then
            Marshal.ReleaseComObject(objRefPlanes)
            objRefPlanes = Nothing
        End If
        If Not (objRelations2d Is Nothing) Then
            Marshal.ReleaseComObject(objRelations2d)
            objRelations2d = Nothing
        End If
        If Not (objRelation2d Is Nothing) Then
            Marshal.ReleaseComObject(objRelation2d)
            objRelation2d = Nothing
        End If
        If Not (objLines2d Is Nothing) Then
            Marshal.ReleaseComObject(objLine2d)
            objLines2d = Nothing
        End If
        If Not (objLine2d Is Nothing) Then
            Marshal.ReleaseComObject(objLine2d)
            objLine2d = Nothing
        End If
        If Not (objModels Is Nothing) Then
            Marshal.ReleaseComObject(objModels)
            objModels = Nothing
        End If
        If Not (objModel Is Nothing) Then
            Marshal.ReleaseComObject(objModel)
            objModel = Nothing
        End If
        If Not (objRounds Is Nothing) Then
            Marshal.ReleaseComObject(objRounds)
            objRounds = Nothing
        End If
        If Not (objRound Is Nothing) Then
            Marshal.ReleaseComObject(objRound)
            objRound = Nothing
        End If
        If Not (objAxes Is Nothing) Then
            Marshal.ReleaseComObject(objAxes)
            objAxes = Nothing
        End If

    End Sub

End Module

 

2 REPLIES

Re: FiniteRevolvedProtrusion

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Ah, you were so close!

 

Dim objAxes As SolidEdgePart.RefAxes = Nothing

 should be

 

Dim objAxis As SolidEdgePart.RefAxis = Nothing

Notice that it's "RefAxis", not "RefAxes"...

 

FYI, I referenced the SolidEdgeCommunity / Samples on GitHub to see working code to compare against. Specifically, I looked at the PartHerlp.vb class of the ApiDemos project and searched for keyword SetAxisOfRevolution.

 

I would also like to mention that all of the

 

If Not (objX Is Nothing) Then
	Marshal.ReleaseComObject(objX)
	objX = Nothing
End If

are not necesesary in this particular scenario. You have a console app that executes the code then exits immediately. The Runtime Callable Wrappers (RCW) live in a single AppDomain and get released automatically when the AppDomain is unloaded, which in this case is when the application exits.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: FiniteRevolvedProtrusion

Thank you for your help, and thank you even more for the links. The examples will help me learn a lot. I am kind of a copy/paste programmer since i didn't have any serious programming lessons beyond for loops, so i didn' really understand what ReleaseComObject does so i left it. I know it's a bad way to build proframs, but i work with what i have.

Anyway thanks for the help.

Regards,

Marko