AutoCAD VBA根據影像資料重建輪廓模型。
通過MATLAB程式生成一個影像輪廓,保存輪廓資料之后使用AutoCADVBA來重建模型。但運行之后一直報錯 :
運行之后提示錯誤:

困擾四個月了,四處尋找一直無果。
求大神!
Sub QSGS()
Open "D:\Matlab\R2012b\work\QSGS\porous.txt" For Input As #1
Input #1, Sumpoints:
'Inout #1 means read single char
ReDim points(0 To Sumline * 3 - 1) As Double
'line here means row
Dim plineObj As AcadPolyline
npoints = 0
For i = 1 To Sumpoints 'Loop through all points
Input #1, x, y 'get coordinate of x,y
points(npoints) = x 'x coordinate of point i
points(npoints + 1) = y 'y coordinate of point i
points(npoints + 2) = 0 'z coordinate of point i
npoints = npoints + 3
Next i
Set plineObj = ThisDrawing.ModelSpace.AddPolyline(points)
ZoomAll
Close
End Sub
資料來源:
李仁民等,采用隨機生長四引數生成法構造黏土微觀結構
uj5u.com熱心網友回復:
運行一下這個代碼,如果彈出的是“位置一,Sumline<=0!” 你要檢查一下Sumline的初始值,這個值不在你這個函式里,當值小于等于0的時候會報錯
如果彈出的是“位置二,i的取值過大,檢查一下 1~Sumpoints是不是正確!” 你要注意一下你的For回圈, For i = 1 To Sumpoints
這里的Sumpoints 的值也沒有給明Sumpoints 和 Sumline 之間的關系值是不是對
Sub QSGS()
Open "D:\Matlab\R2012b\work\QSGS\porous.txt" For Input As #1
Input #1, Sumpoints:
'Inout #1 means read single char
if Sumline<=0 then msgbox "位置一,Sumline<=0!" '
ReDim points(0 To Sumline* 3 - 1) As Double
'line here means row
Dim plineObj As AcadPolyline
npoints = 0
For i = 1 To Sumpoints 'Loop through all points
Input #1, x, y 'get coordinate of x,y
if npoints+2>ubound(points) then msgbox “位置二,i的取值過大,檢查一下 1~Sumpoints是不是正確!” & vbcrlf & "Sumpoints=" & cstr(Sumpoints) & " , Sumline="& cstr(Sumline) &" 這兩個資料的關系應該不對。"
points(npoints) = x 'x coordinate of point i
points(npoints + 1) = y 'y coordinate of point i
points(npoints + 2) = 0 'z coordinate of point i
npoints = npoints + 3
Next i
Set plineObj = ThisDrawing.ModelSpace.AddPolyline(points)
ZoomAll
Close
End Sub
uj5u.com熱心網友回復:
引號打錯了,免得你說運行報錯,我自己改了
Sub QSGS()
Open "D:\Matlab\R2012b\work\QSGS\porous.txt" For Input As #1
Input #1, Sumpoints:
'Inout #1 means read single char
if Sumline<=0 then msgbox "位置一,Sumline<=0!" '
ReDim points(0 To Sumline* 3 - 1) As Double
'line here means row
Dim plineObj As AcadPolyline
npoints = 0
For i = 1 To Sumpoints 'Loop through all points
Input #1, x, y 'get coordinate of x,y
if npoints+2>ubound(points) then msgbox "位置二,i的取值過大,檢查一下 1~Sumpoints是不是正確!" & vbcrlf & "Sumpoints=" & cstr(Sumpoints) & " , Sumline="& cstr(Sumline) &" 這兩個資料的關系應該不對。"
points(npoints) = x 'x coordinate of point i
points(npoints + 1) = y 'y coordinate of point i
points(npoints + 2) = 0 'z coordinate of point i
npoints = npoints + 3
Next i
Set plineObj = ThisDrawing.ModelSpace.AddPolyline(points)
ZoomAll
Close
End Sub
uj5u.com熱心網友回復:
輕拍……
就是不明白這里的Sumpoints和Sumline是怎么來的。因為看論文里面只給了這么一個程式,得到的porous.txt資料里面也沒有資料……
uj5u.com熱心網友回復:
不知你的問題解決沒啊uj5u.com熱心網友回復:
沒有啊,一直沒有弄出來,就放棄了~uj5u.com熱心網友回復:
樓主您好,請問matlab部分的程式您有么 可否加一個qq交流一下870971873轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/52801.html
標籤:VBA
下一篇:急
