title: Stuck in programming this Console application for Solid Edge
body: <p>I'm trying to make a visual basic console application for a 3D CAD program Solid Edge, in this console application I want visual basic to make curves in it. I want to make these curves with an 4th degree equation.The data used for the equation is stored in a space dilimited text file. In the text file there are several rows with different data, every row is used to make the 4th degree equation. Now, I tried to make the program but it got stuck at making the curve lines, the console just stays black and doesn't close. The program does make a connection to the program and opens up a 3d modeling environment.</p>
  
  <p>Does anyone knows what I'm doing wrong in my code, or what I should do instead? I'm using visual basic 2003 standart.
  I'm not a programmer, but I try this to automate things in the 3D CAD program.</p>
  
  <p>Heres my code:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Imports System.IO
  Imports System.Runtime.InteropServices
  Module Module1
      Sub Main()
  
          Dim strFileName As String = "U:\pompen.prn"
          Dim objFS As New FileStream(strFileName, FileMode.Open, FileAccess.Read)
          Dim objSR As New StreamReader(objFS)
  
          Dim objApp 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 objdraft2d As SolidEdgeDraft.CoordinateSystem2d = Nothing
          Dim objBSpline As SolidEdgeFrameworkSupport.BSplineCurve2d = Nothing
          Dim objBSplines As SolidEdgeFrameworkSupport.BSplineCurves2d = Nothing
          Dim objLines2d As SolidEdgeFrameworkSupport.Lines2d = Nothing
          Dim objLine2d As SolidEdgeFrameworkSupport.Line2d = Nothing
          Dim objsketch As SolidEdgePart.Sketch = Nothing
  
          Dim strEmpRecord As String
          Dim type As String
          Dim N1 As Double
          Dim QT As Double
          Dim DW1 As Decimal
          Dim EQ As Decimal
          Dim EH As Decimal
          Dim DWL As Decimal
          Dim DHL As Decimal
          Dim C1 As Decimal
          Dim C2 As Decimal
          Dim C3 As Decimal
          Dim C4 As Decimal
          Dim C5 As Decimal
          Dim QFACTOR As Decimal
  
  
          Do While objSR.Peek &lt;&gt; -1
              ' read the current record (line) into the variable strEmpRecord
              strEmpRecord = objSR.ReadLine
              Try
                  ' break up the record into separate variables
                  type = strEmpRecord.Substring(0, 20)
                  N1 = CDbl(strEmpRecord.Substring(20, 10))
                  QT = CDbl(strEmpRecord.Substring(30, 10))
                  DW1 = CDec(strEmpRecord.Substring(40, 10))
                  EQ = CDec(strEmpRecord.Substring(50, 10))
                  EH = CDec(strEmpRecord.Substring(60, 10))
                  DHL = CDec(strEmpRecord.Substring(70, 10))
                  DWL = CDec(strEmpRecord.Substring(80, 10))
                  C1 = CDec(strEmpRecord.Substring(90, 20))
                  C2 = CDec(strEmpRecord.Substring(110, 20))
                  C3 = CDec(strEmpRecord.Substring(130, 20))
                  C4 = CDec(strEmpRecord.Substring(150, 20))
                  C5 = CDec(strEmpRecord.Substring(170, 20))
                  QFACTOR = CDec(strEmpRecord.Substring(190, 10))
              Catch ex As System.InvalidCastException
              End Try
  
              'connect to a Solid Edge file.
              ' Connect to a running instance of Solid Edge 
              objApp = Marshal.GetActiveObject("SolidEdge.Application")
              ' Get a reference to the documents collection 
              objDocuments = objApp.Documents
              ' Create a new part document 
              objPart = objDocuments.Add("SolidEdge.PartDocument")
              ' Get a reference to the profile sets collection 
              objProfileSets = objPart.ProfileSets
              ' Add a new profile set 
              objProfileSet = objProfileSets.Add()
              ' Get a reference to the profiles collection 
              objProfiles = objProfileSet.Profiles
              ' Get a reference to the ref planes collection 
              objRefplanes = objPart.RefPlanes
              'open a new sketch
              objsketch = objPart.Sketches.Add
              ' Add a new profile 
              objProfile = objProfiles.Add(objRefplanes.Item(3))
              'Gat a reference to spline curve collection
              objBSplines = objProfile.BSplineCurves2d
              ' Get a reference to the lines2d collection 
              objLines2d = objProfile.Lines2d
  
              Try
                  'Draw the curves with 4th degree equation, DMax
                  Dim q As Decimal = (QT * 0.2)
                  Dim h As Decimal = (((q ^ 4) * C1) + ((q ^ 3) * C2) + ((q ^ 2) * C3) + (q * C4) + C5)
                  Do
                      q = (q + 0.5)
                  Loop Until q &lt;= (QT * QFACTOR)
                  objBSpline = objBSplines.objsr.AddByPoints(q, h)
  
                  'Draw the curves with 4th degree equation, DMin
                  Dim qx As Decimal = ((DWL / DW1) ^ EQ)
                  Dim hx As Decimal = ((DWL / DW1) ^ EH)
                  Dim qa As Decimal = (qx * q)
                  Dim ha As Decimal = (hx * (((q ^ 4) * C1) + ((q ^ 3) * C2) + ((q ^ 2) * C3) + (q * C4) + C5))
                  Do
                      qa = (qa + 0.5)
                  Loop Until qa = (qx * (QT * QFACTOR))
                  objBSpline = objBSplines.objsr.addbypoints(qa, ha)
  
                  'make connection lines
                  objLine2d = objLines2d.AddBy2Points((qx * (QT * QFACTOR)), (QFACTOR * (hx * (((q ^ 4) * C1) + ((q ^ 3) * C2) + ((q ^ 2) * C3) + (q * C4) + C5))), (QT * QFACTOR), (QFACTOR * (((q ^ 4) * C1) + ((q ^ 3) * C2) + ((q ^ 2) * C3) + (q * C4) + C5)))
  
                  ' Close the profile 
                  objProfile.End( _
                      SolidEdgePart.ProfileValidationType.igProfileClosed)
  
              Catch ex As Exception
  
              Finally
                  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 (objBSpline Is Nothing) Then
                      Marshal.ReleaseComObject(objBSpline)
                      objBSpline = 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 (objsketch Is Nothing) Then
                      Marshal.ReleaseComObject(objsketch)
                      objsketch = Nothing
                  End If
                  If Not (objApp Is Nothing) Then
                      Marshal.ReleaseComObject(objApp)
                      objApp = Nothing
                  End If
              End Try
          Loop
  
          objSR.Close()
          Console.WriteLine("")
          Console.WriteLine("Press Enter to close this window.")
          Console.ReadLine()
  
      End Sub
  End Module
  </code></pre>