andries41
Mechanical
- Oct 29, 2012
- 6
Hello,
I made the following code with visual basic 2003 to make curves in solid edge.
The problem is that the program doest draw anything in solid edge. Every variable i got, what is read from a text file, is used. The arrays for making the curves with the BSplinecurve2d.addbypoints method are also stored.
But nothing happens, only a part window gets opened.
Anyone knows why this is?
The code is a bit long so sorry if it is getting a bit too much.
Thanks in advance.
I made the following code with visual basic 2003 to make curves in solid edge.
The problem is that the program doest draw anything in solid edge. Every variable i got, what is read from a text file, is used. The arrays for making the curves with the BSplinecurve2d.addbypoints method are also stored.
But nothing happens, only a part window gets opened.
Anyone knows why this is?
The code is a bit long so sorry if it is getting a bit too much.
Thanks in advance.
Code:
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Collections
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 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 Double
Dim EQ As Double
Dim EH As Double
Dim DWL As Double
Dim DHL As Double
Dim C1 As Decimal
Dim C2 As Decimal
Dim C3 As Decimal
Dim C4 As Decimal
Dim C5 As Decimal
Dim QFACTOR As Double
Dim q As Double
Dim h As Double
Dim qx As Double
Dim hx As Double
Dim qa As Double
Dim ha As Double
Dim qeind As Double
Dim qeind2 As Double
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))
'Get a reference to spline curve collection
objBsplines = objProfile.BSplineCurves2d
'Get a reference to the lines2d collection
objLines2d = objProfile.Lines2d
Dim nfi As Globalization.NumberFormatInfo = New Globalization.CultureInfo("en-US", False).NumberFormat
nfi.NumberGroupSeparator = " "
nfi.NumberDecimalSeparator = ","
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(1, 19)
N1 = CDbl(strEmpRecord.Substring(20, 9))
QT = CDbl(strEmpRecord.Substring(30, 9))
DW1 = CDbl(strEmpRecord.Substring(40, 9))
EQ = CDbl(strEmpRecord.Substring(50, 9))
EH = CDbl(strEmpRecord.Substring(60, 9))
DHL = CDbl(strEmpRecord.Substring(70, 9))
DWL = CDbl(strEmpRecord.Substring(80, 9))
C1 = CDbl(strEmpRecord.Substring(90, 19))
C2 = CDbl(strEmpRecord.Substring(110, 19))
C3 = CDbl(strEmpRecord.Substring(130, 19))
C4 = CDbl(strEmpRecord.Substring(150, 19))
C5 = CDbl(strEmpRecord.Substring(170, 19))
QFACTOR = CDbl(strEmpRecord.Substring(190, 3))
Catch ex As System.InvalidCastException
End Try
Loop
'Dmax
Dim i As Double
Dim listofdata As New ArrayList
For i = 0.2 To QFACTOR Step 0.1
q = (i * QT)
h = ((((q ^ 4) * C1) + ((q ^ 3) * C2) + ((q ^ 2) * C3) + (q * C4) + C5))
listofdata.Add(q)
listofdata.Add(h)
Next
Dim dataArray() As Double
dataArray = DirectCast(listofdata.ToArray(GetType(Double)), Double())
objBspline = objBsplines.AddByPoints(4, 13, dataArray)
'Dmin
qx = ((DWL / DW1) ^ EQ)
hx = ((DWL / DW1) ^ EH)
Dim listofdata2 As New ArrayList
For i = 0.2 To 1.5 Step 0.1
q = (i * QT)
qa = (qx * q)
ha = (hx * (((q ^ 4) * C1) + ((q ^ 3) * C2) + ((q ^ 2) * C3) + (q * C4) + C5))
listofdata2.Add(qa)
listofdata2.Add(ha)
Next
Dim data2Array() As Double
data2Array = DirectCast(listofdata2.ToArray(GetType(Double)), Double())
objBspline = objBsplines.AddByPoints(4, 13, data2Array)
'make connection lines
qeind = QFACTOR * QT
qeind2 = qx * qeind
objLine2d = objLines2d.AddBy2Points(qeind2, (hx * (((qeind2 ^ 4) * C1) + ((qeind2 ^ 3) * C2) + ((qeind2 ^ 2) * C3) + (qeind2 * C4) + C5)), qeind, (((qeind ^ 4) * C1) + ((qeind ^ 3) * C2) + ((qeind ^ 2) * C3) + (qeind * C4) + C5))
' Close the profile
objProfile.End( _
SolidEdgePart.ProfileValidationType.igProfileClosed)
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 (objBsplines Is Nothing) Then
Marshal.ReleaseComObject(objBsplines)
objBsplines = 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
objSR.Close()
Console.WriteLine("")
Console.WriteLine("Press Enter to close this window.")
Console.ReadLine()
End Sub
End Module