Solid Edge macro doest do anything.

hello,

Im trying to make a visual basic console application for Solid Edge, in this console application i want visual basic to make curves in Solid Edge. These curves had data stored in a space dilimited text file. I tried to make the program but it got stuck at making the lines, the console just stays blck and there's just an opened part file.

Does anyone knows what i'm doing wrong, or what i should do? I'm using visual basic 2003 standart, and i am trying this with Solid Edge ST2.

I'm not a programmer, so help i much appriciated.

Heres my code: ( I made this code with stuff i found on the internet, form the solid edge programmers guide and made some by my self.

[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 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 <> -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

' 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 <= (QT * QFACTOR)

objBSpline = objBSplines.objsr.AddByPoints(q, h, 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, 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 (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]

 

Posted by: Andries
Post date: 11/14/2012 8:04:20 AM