问题描述
我试图使一个三维CAD程序Solid Edge的一个Visual Basic控制台应用程序,在我想的Visual Basic,使曲线它这个控制台应用程序。欲与第四度方程。用于方程的数据存储在一个空间dilimited文本文件,使这些曲线。在文本文件中,有不同的数据多行,每行用于使第四度方程。现在,我试图让该程序,但它卡住了在做曲线线条,控制台只是停留黑,不会关闭。该方案确实对程序的连接,并打开了3D建模环境。
有谁知道我在做什么错在我的code,或者我应该怎么办呢?我使用的Visual Basic 2003非标准。我不是一个程序员,但我尝试这种自动化的东西,在3D CAD程序。
这是我的code:
进口System.IO进口了System.Runtime.InteropServices模块模块1 副主() 昏暗strFileName作为字符串=U:\ pompen.prn 昏暗OBJFS作为新的FileStream(strFileName,FileMode.Open,FileAccess.Read) 昏暗objSR作为新的StreamReader(OBJFS) 昏暗objApp作为SolidEdgeFramework.Application =无 昏暗objDocuments作为SolidEdgeFramework.Documents =无 昏暗objPart作为SolidEdgePart.PartDocument =无 昏暗objProfileSets作为SolidEdgePart.ProfileSets =无 昏暗objProfileSet作为SolidEdgePart.ProfileSet =无 昏暗objProfiles作为SolidEdgePart.Profiles =无 昏暗objProfile作为SolidEdgePart.Profile =无 昏暗objRefplanes作为SolidEdgePart.RefPlanes =无 昏暗objdraft2d作为SolidEdgeDraft.CoordinateSystem2d =无 昏暗objBSpline作为SolidEdgeFrameworkSupport.BSplineCurve2d =无 昏暗objBSplines作为SolidEdgeFrameworkSupport.BSplineCurves2d =无 昏暗objLines2d作为SolidEdgeFrameworkSupport.Lines2d =无 昏暗objLine2d作为SolidEdgeFrameworkSupport.Line2d =无 昏暗objsketch作为SolidEdgePart.Sketch =无 昏暗STREM precord作为字符串 昏暗的类型为String 昏暗N1作为双 昏暗QT作为双 昏暗DW1为十进制 昏暗EQ为十进制 昏暗EH为十进制 昏暗的DWL为十进制 昏暗DHL为十进制 昏暗C1为十进制 昏暗C2为十进制 昏暗C3为十进制 昏暗C4为十进制 昏暗C5为十进制 昏暗QFACTOR为十进制 做,而objSR.Peek<> -1 读取当前记录(行)到变量STREM precord STREM precord = objSR.ReadLine 尝试 打破纪录成独立的变量 TYPE = STREM precord.Substring(0,20) N1 = CDbl(STREM precord.Substring(20,10)) QT = CDbl(STREM precord.Substring(30,10)) DW1 = CDEC(STREM precord.Substring(40,10)) EQ = CDEC(STREM precord.Substring(50,10)) EH = CDEC(STREM precord.Substring(60,10)) DHL = CDEC(STREM precord.Substring(70,10)) DWL = CDEC(STREM precord.Substring(80,10)) C1 = CDEC(STREM precord.Substring(90,20)) C2 = CDEC(STREM precord.Substring(110,20)) C3 = CDEC(STREM precord.Substring(130,20)) C4 = CDEC(STREM precord.Substring(150,20)) C5 = CDEC(STREM precord.Substring(170,20)) QFACTOR = CDEC(STREM precord.Substring(190,10)) 抓住EX作为System.InvalidCastException 结束尝试 连接到Solid Edge的文件。 '连接到的Solid Edge的运行实例 objApp = Marshal.GetActiveObject(SolidEdge.Application) 获取引用的文件集合 objDocuments = objApp.Documents 创建一个新的零件文档 objPart = objDocuments.Add(SolidEdge.PartDocument) 得到一个参考的资料设定集 objProfileSets = objPart.ProfileSets 添加新的配置文件集 objProfileSet = objProfileSets.Add() 获取引用轮廓集合 objProfiles = objProfileSet.Profiles 有了一个指向裁判飞机集合 objRefplanes = objPart.RefPlanes 打开一个新的草图 objsketch = objPart.Sketches.Add 添加新的配置文件 objProfile = objProfiles.Add(objRefplanes.Item(3)) Gat的一个参考样条曲线集合 objBSplines = objProfile.BSplineCurves2d 获取引用lines2d集合 objLines2d = objProfile.Lines2d 尝试 战平4次方程,DMAX曲线 昏暗的Q表小数=(QT * 0.2) 昏暗的事项h作为小数=(((Q ^ 4)* C1)+((Q ^ 3)* C2)+((Q ^ 2)* C3)+(Q * C4)+ C5) 做 Q =(Q + 0.5) 循环,直到Q< =(QT * QFACTOR) objBSpline = objBSplines.objsr.AddByPoints(Q,H) 战平4次方程,DMIN曲线 昏暗QX为十进制=((DWL / DW1)^ EQ) 昏暗HX为十进制=((DWL / DW1)^ EH) 昏暗的QA为十进制=(QX * Q) 昏暗公顷为十进制=(HX *(((Q ^ 4)* C1)+((Q ^ 3)* C2)+((Q ^ 2)* C3)+(Q * C4)+ C5)) 做 QA =(QA + 0.5) 循环直到QA =(QX *(QT * QFACTOR)) objBSpline = objBSplines.objsr.addbypoints(QA,哈哈) 让连接线 objLine2d = objLines2d.AddBy2Points((QX *(QT * QFACTOR)),(QFACTOR *(HX *(((Q ^ 4)* C1)+((Q ^ 3)* C2)+((Q ^ 2)* C3)+(Q * -C 4)+ C5))),(QT * QFACTOR),(QFACTOR *(((Q ^ 4)* C1)+((Q ^ 3)* C2)+((Q ^ 2) * C 3)+(Q * -C 4)+ C 5))) 关闭个人资料 objProfile.End(_ SolidEdgePart.ProfileValidationType.igProfileClosed) 抓住EX为例外 最后 如果不是(objLine2d是Nothing),然后 对Marshal.ReleaseComObject(objLine2d) objLine2d =无 结束如果 如果不是(objLines2d是Nothing),然后 对Marshal.ReleaseComObject(objLines2d) objLines2d =无 结束如果 如果不是(objBSpline是Nothing),然后 对Marshal.ReleaseComObject(objBSpline) objBSpline =无 结束如果 如果不是(objRefplanes是Nothing),然后 对Marshal.ReleaseComObject(objRefplanes) objRefplanes =无 结束如果 如果不是(objProfile是Nothing),然后 对Marshal.ReleaseComObject(objProfile) objProfile =无 结束如果 如果不是(objProfiles是Nothing),然后 对Marshal.ReleaseComObject(objProfiles) objProfiles =无 结束如果 如果不是(objProfileSet是Nothing),然后 对Marshal.ReleaseComObject(objProfileSet) objProfileSet =无 结束如果 如果不是(objProfileSets是Nothing),然后 对Marshal.ReleaseComObject(objProfileSets) objProfileSets =无 结束如果 如果不是(objPart是Nothing),然后 对Marshal.ReleaseComObject(objPart) objPart =无 结束如果 如果不是(objDocuments是Nothing),然后 对Marshal.ReleaseComObject(objDocuments) objDocuments =无 结束如果 如果不是(objsketch是Nothing),然后 对Marshal.ReleaseComObject(objsketch) objsketch =无 结束如果 如果不是(objApp是Nothing),然后 对Marshal.ReleaseComObject(objApp) objApp =无 结束如果 结束尝试 循环 objSR.Close() Console.WriteLine() Console.WriteLine(preSS进入关闭该窗口。) 到Console.ReadLine() 结束小组前端模块
我要猜你应该移动的code此块是你的循环,即外界。在做的,而objSR.Peek<> -1
。在循环会做所有这些事情在你的文件的每一行。我想你只会想这样做的东西一次。
连接到Solid Edge的文件。
'连接到的Solid Edge的运行实例
objApp = Marshal.GetActiveObject(SolidEdge.Application)
获取引用的文件集合
objDocuments = objApp.Documents
创建一个新的零件文档
objPart = objDocuments.Add(SolidEdge.PartDocument)
得到一个参考的资料设定集
objProfileSets = objPart.ProfileSets
添加新的配置文件集
objProfileSet = objProfileSets.Add()
获取引用轮廓集合
objProfiles = objProfileSet.Profiles
有了一个指向裁判飞机集合
objRefplanes = objPart.RefPlanes
打开一个新的草图
objsketch = objPart.Sketches.Add
添加新的配置文件
objProfile = objProfiles.Add(objRefplanes.Item(3))
Gat的一个参考样条曲线集合
objBSplines = objProfile.BSplineCurves2d
获取引用lines2d集合
objLines2d = objProfile.Lines2d
然后,你可能会需要你的循环之后移动这,
关闭个人资料
objProfile.End(_
SolidEdgePart.ProfileValidationType.igProfileClosed)
只是一个提示,您应该删除此行
抓住EX为例外
如果你有一个空的抓
块,你只会从自己隐藏任何错误。
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.
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.
Heres my 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 <> -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 <= (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
I'm going to guess that you should move this block of code to be outside your loop, ie. before the Do While objSR.Peek <> -1
. In the loop it will do all these things for each line in your file. I would think you would only want to do this stuff once.
'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
Then you would probably have to move this to after your loop,
' Close the profile
objProfile.End( _
SolidEdgePart.ProfileValidationType.igProfileClosed)
Just a tip, you should remove this line
Catch ex As Exception
If you have an empty catch
block, you will just hide any errors from yourself.
这篇关于在编程滞留该控制台应用程序的Solid Edge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!