我想看一级黄色大片_久久亚洲国产精品一区二区_久久精品免视看国产明星_91久久青青青国产免费

您的位置:網站首頁 > CAD教程 > 常見問題

如何在cad中畫出多條折線的圖文說明

時間:2014-10-30 09:08:15 來源:未知

 

發現在cad中畫出多點是很容易的,菜單中有相關的命令,輸入命令后,在下面的文本框復制出以回車換行為分割的多個點就可以一次性畫出多個點。但是一次性畫圖很多條不同的折線就很難,比如下面的文本中的3條線段:

'c:aa.txt中的原始格式 '第一列如果是0表示線的起點; 如果是255,表示連接上一個點
'0,700.000,103.500
'255,804.126,103.500
'255,1305.051,893.959
'255,4002.830,1993.054
'0,700.000,118.500
'255,795.874,118.500
'0,700.000,111.000
'255,800.000,111.000
'255,1300.000,900.000
'255,4000.000,2000.000

 

后來研究了1個小時,總算弄好了。需要注意的是,x和y如果是測量坐標,應該反這輸入。

 

具體的方法是:cad主界面 "工具" - "宏" - "VB編輯器",以可以Alt + F11 一步到位。

雙擊左邊欄的"ThisDrawing",然后出現代碼輸入框,復制下面的代碼到框中:

 

Sub drawMultiLines()
'Call addLineXY(2, 2, 90, 90)
If Dir("c:aa.txt", vbNormal) <> "" Then '如果文件存在
Dim fileNumber As Integer
fileNumber = FreeFile
Dim strLine As String

Dim arr() As String
Dim xStart As Double '起點
Dim yStart As Double

Open "c:aa.txt" For Input As #fileNumber
Do While Not EOF(fileNumber)
Line Input #fileNumber, strLine
arr = Split(strLine, ",")
If arr(0) = "0" Then '如果是0表示線的起點
xStart = arr(1)
yStart = arr(2)
ElseIf arr(0) = "255" Then '如果是255,表示連接上一個點(xStart, yStart)
Call addLineXY(yStart, xStart, arr(2), arr(1)) '連接上一個點成為直線
xStart = arr(1)
yStart = arr(2)
Else
'dd
End If
Loop
Close #fileNumber
End If
End Sub

 

Public Function addLineXY(ByVal x1 As Double, ByVal y1 As Double, ByVal x2 As Double, ByVal y2 As Double) As AcadLine
Dim pt1(2) As Double
Dim pt2(2) As Double
pt1(0) = x1: pt1(1) = y1: pt1(2) = 0
pt2(0) = x2: pt2(1) = y2: pt2(2) = 0
Set addLineXY = ThisDrawing.ModelSpace.AddLine(pt1, pt2)
End Function
 


相關文章