本文主要是介绍碰到一个问题,不解决不爽,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题的要素
- 随机生成一些长度、直径、位置、方向都不同的圆柱体;
- 数据文件需要是solid model格式,以便能导入到Fluent/ANSYS/Abaqus之类的软件中进行网格化和有限元或有限体积分析。
当前状态
已经解决。
解决了文件的生成和格式转换,但是要生成网格和进行分析,类似问题,从算法上的难度实际上仍然很大。可能需要巨大的内存和计算量。
两两不相交
进一步
把计算好的点放在TXT文件中用VBA读入,而后显示出来?
http://www.vbaexpress.com/forum/showthread.php?18957-Solved-VBA-and-AutoCAD-reading-points-from-a-txt-file
Public Sub DrawPointsFromTextFile() Dim fd As Long Dim sline As String Dim ar As Variant fd = FreeFile Open "C:\Temp\Coordinates.txt" For Input Access Read Shared As fd Do Until EOF(fd) Line Input #fd, sline ar = Split(sline, ",") ReDim pt(UBound(ar)) As Double Dim i As Integer For i = 0 To UBound(ar) pt(i) = CDbl(ar(i)) Next i ThisDrawing.ModelSpace.AddPoint pt Loop Close fd
End Sub
来自
http://www.vbaexpress.com/forum/showthread.php?2647-Solved-Text-file-to-drawing
Sub DrawFromTxt() Dim intFile As Integer Dim mPoints Dim HldPoints() As String Dim LinPlace() As String Dim MyString As String Dim OutArr As Variant Dim OutPt(0 To 2) As Double Dim OutPtA(0 To 2) As Double Dim Lend As Integer Dim LStart As Integerm Dim pointObj As AcadPoint Dim lineObj As AcadLine Dim I As Integer ReDim HldPoints(0) ReDim LinPlace(0) intFile = FreeFile Open "C:\Acad\file.txt" For Input As intFile While Not EOF(intFile) Line Input #intFile, MyString If InStr(1, MyString, " !Define key points ") > 0 Or _ InStr(1, MyString, "! Define Keypoints") > 0 Then Line Input #intFile, MyString While InStr(1, MyString, "Keypoints") = 0 If Left$(MyString, 1) = "K" Then ReDim Preserve HldPoints(UBound(HldPoints) + 1) HldPoints(UBound(HldPoints)) = Right(MyString, _ Len(MyString) - InStr(3, MyString, ",")) End If Line Input #intFile, MyString Wend End If If InStr(1, MyString, " !Define line ") > 0 Or InStr(1, _ MyString, "! Define Lines Linking") > 0 Then Line Input #intFile, MyString While InStr(1, MyString, "! element definition") = 0 And _ InStr(1, MyString, " !Element Definition") = 0 If Left$(MyString, 1) = "L" Then ReDim Preserve LinPlace(UBound(LinPlace) + 1) LinPlace(UBound(LinPlace)) = Right$(MyString, Len(MyString) - 2) End If If Not EOF(intFile) Then Line Input #intFile, MyString Else MyString = "! element definition" End If Wend End If Wend Close (intFile) 'i have the pointsFor I = 1 To UBound(HldPoints) OutArr = Split(HldPoints(I), ",") OutPt(0) = Val(OutArr(0)) OutPt(1) = Val(OutArr(1)) OutPt(2) = 0 Set pointObj = ThisDrawing.ModelSpace.AddPoint(OutPt) pointObj.Color = acCyan ThisDrawing.Regen acActiveViewport Next For I = 1 To UBound(LinPlace) OutArr = Split(LinPlace(I), ",") LStart = Val(OutArr(0)) Lend = Val(OutArr(1)) OutArr = Split(HldPoints(LStart), ",") OutPt(0) = Val(OutArr(0)) OutPt(1) = Val(OutArr(1)) OutPt(2) = 0 OutArr = Split(HldPoints(Lend), ",") OutPtA(0) = Val(OutArr(0)) OutPtA(1) = Val(OutArr(1)) OutPtA(2) = 0 Set lineObj = ThisDrawing.ModelSpace.AddLine(OutPt, OutPtA) lineObj.Color = acCyan ThisDrawing.Regen acActiveViewport Next
End Sub
这篇关于碰到一个问题,不解决不爽的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!