获取CAD中线的每个节点坐标,线包括polyline、3D polyline、Spline等等!
程序代码如下:
Imports System
Imports System.IO
Imports System.Math
Public Class 获取CAD中点坐标
Public AcadApp As AutoCAD.AcadApplication
Public xx(), yy(), zz() As Double
Public Count As Integer
Public returnObj As Object
Public FolderPath As String = "C:/"
Public StepNum As Integer = 0
Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As Boolean
Public Sub SetProcessWorkingSetSize() '节约系统内存
Try
Dim Mem As Process
Mem = Process.GetCurrentProcess()
SetProcessWorkingSetSize(Mem.Handle, -1, -1)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub 启动CAD()
On Error Resume Next
AcadApp = GetObject(, "AutoCAD.Application")
If Err.Number Then
Err.Clear()
AcadApp = CreateObject("AutoCAD.Application")
End If
AcadApp.Visible = True
AcadApp.WindowState = AutoCAD.AcWindowState.acMax
AppActivate(AcadApp.Caption)
End Sub
Public Sub 获取样条线节点坐标()
Dim i As Integer
For i = 0 To 10000 Step StepNum
On Error GoTo handle01
Count = i
ReDim Preserve xx(i)
ReDim Preserve yy(i)
ReDim Preserve zz(i)
xx(i) = returnObj.Coordinate(i)(0)
yy(i) = returnObj.Coordinate(i)(1)
zz(i) = returnObj.elevation
Next
handle01:
Count = Count - 1
End Sub
Public Sub 获取Spline线节点坐标()
Dim fitPoints As Object
Dim i As Integer
For i = 0 To returnObj.NumberOfControlPoints - 1 Step StepNum
fitPoints = returnObj.GetControlPoint(i)
Count = i
ReDim Preserve xx(i)
ReDim Preserve yy(i)
ReDim Preserve zz(i)
xx(i) = fitPoints(0)
yy(i) = fitPoints(1)
zz(i) = fitPoints(2)
Next
End Sub
Public Sub 获取Spline线拟合点坐标()
Dim fitPoints As Object
Dim pp As AutoCAD.AcadSpline
Dim i As Integer
For i = 0 To returnObj.NumberOfFitPoints - 1 Step StepNum
fitPoints = returnObj.GetFitPoint(i)
Count = i
ReDim Preserve xx(i)
ReDim Preserve yy(i)
ReDim Preserve zz(i)
xx(i) = fitPoints(0)
yy(i) = fitPoints(1)
zz(i) = fitPoints(2)
Next
End Sub
Public Sub 获取line线节点坐标()
Dim StartPoints As Object
Dim EndPoints As Object
ReDim Preserve xx(1)
ReDim Preserve yy(1)
ReDim Preserve zz(1)
Count = 1
returnObj.highlight(True)
StartPoints = returnObj.StartPoint
EndPoints = returnObj.EndPoint
xx(0) = StartPoints(0)
yy(0) = StartPoints(1)
zz(0) = StartPoints(2)
xx(1) = EndPoints(0)
yy(1) = EndPoints(1)
zz(1) = EndPoints(2)
End Sub
Public Sub 获取2DPolyline节点坐标()
'Dim sss As AutoCAD.AcadLWPolyline
returnObj.highlight(True)
Dim i As Integer
For i = 0 To 10000 Step StepNum
On Error GoTo handle01
Count = i
ReDim Preserve xx(i)
ReDim Preserve yy(i)
ReDim Preserve zz(i)
xx(i) = returnObj.Coordinate(i)(0)
yy(i) = returnObj.Coordinate(i)(1)
zz(i) = returnObj.elevation
Next
handle01:
Count = Count - 1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
On Error GoTo handle01
Call 启动CAD()
Dim basePnt As Object
AcadApp.ActiveDocument.Utility.GetEntity(returnObj, basePnt)
returnObj.highlight(True)
'判断线的类型
Dim LineTypenName As String
LineTypenName = returnObj.ObjectName.ToString()
If LineTypenName = "AcDbLine" Then
Call 获取line线节点坐标()
ElseIf LineTypenName = "AcDbSpline" Then
Call 获取Spline线节点坐标()
ElseIf LineTypenName = "AcDbPolyline" Then
Call 获取样条线节点坐标()
Else : Exit Sub
End If
If TextBox1.Text <> 0 Or TextBox2.Text <> 0 Or TextBox4.Text <> 0 Then
Call CalculateCoordinate()
End If
Dim i As Integer
Dim s As String = ""
For i = 0 To Count
s = s + xx(i).ToString() + "," + yy(i).ToString() + "," + zz(i).ToString() + Chr(13)
Next
RichTextBox1.Text = s
Button3.Enabled = True
AppActivate(Me.Text)
Exit Sub
handle01:
MsgBox(Err.Description)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
On Error GoTo handle01
Dim dg As New OpenFileDialog
dg.Filter = "CAD files (*.dwg)|*.dwg|All files (*.*)|*.*"
dg.ShowDialog()
Dim s As String = dg.FileName
If s = "" Then Exit Sub
启动CAD()
AcadApp.Application.Documents.Open(s)
AcadApp.ActiveDocument.WindowState = AutoCAD.AcWindowState.acMax
AppActivate(Me.Text)
Button1.Enabled = True
Exit Sub
handle01:
MsgBox(Err.Description)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
On Error GoTo handle01
Dim dg As New SaveFileDialog
dg.Filter = "txt files (*.txt)|*.txt|dat files (*.dat)|*.dat"
dg.ShowDialog()
Dim s As String = dg.FileName
Dim i As Integer
Dim s1 As String = ""
Using sw As StreamWriter = New StreamWriter(s)
For i = 0 To Count
s1 = xx(i).ToString() + "," + yy(i).ToString() + "," + zz(i).ToString()
sw.WriteLine(s1)
Next
sw.Close()
End Using
Exit Sub
handle01:
MsgBox(Err.Description)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
AcadApp.ActiveDocument.Regen(AutoCAD.AcRegenType.acActiveViewport)
End Sub
Public Sub CalculateCoordinate()
On Error GoTo handle01
Dim x0, y0, Rotangle As Double
x0 = TextBox1.Text
y0 = TextBox2.Text
Rotangle = (TextBox4.Text) * 3.1415926 / 180
Dim i As Integer
Dim x1, y1 As Double
If Cos(Rotangle) = 0 Then
For i = 0 To Count
x1 = xx(i)
xx(i) = yy(i) - y0
yy(i) = x0 - x1
Next
Exit Sub
End If
For i = 0 To Count
y1 = (yy(i) - y0 - (xx(i) - x0) * Tan(Rotangle)) * Cos(Rotangle)
x1 = (xx(i) - x0) / Cos(Rotangle) + y1 * Tan(Rotangle)
If Abs(x1) < 0.00001 Then x1 = 0 '设置精度
If Abs(y1) < 0.00001 Then y1 = 0
xx(i) = x1
yy(i) = y1
Next
Exit Sub
handle01:
MsgBox(Err.Description)
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub 批量获取节点坐标Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 批量获取节点坐标Button.Click
Static ExitNum As Integer
On Error GoTo handle01
Static SaveNum As Integer
Call 启动CAD()
Dim basePnt As Object
AcadApp.ActiveDocument.Utility.GetEntity(returnObj, basePnt)
returnObj.highlight(True)
AcadApp.ActiveDocument.SendCommand("@选取下一条线!连续在空白地方点击两次将会自动退出批量存储状态!" + vbCr)
'判断线的类型
Dim LineTypenName As String
LineTypenName = returnObj.ObjectName.ToString()
If LineTypenName = "AcDbLine" Then
Call 获取line线节点坐标()
ElseIf LineTypenName = "AcDbSpline" Then
Call 获取Spline线节点坐标()
ElseIf LineTypenName = "AcDbPolyline" Then
Call 获取样条线节点坐标()
End If
If TextBox1.Text <> 0 Or TextBox2.Text <> 0 Or TextBox4.Text <> 0 Then
Call CalculateCoordinate()
End If
Dim j As Integer
Dim s1 As String = ""
Using sw As StreamWriter = New StreamWriter(FolderPath + SaveNum.ToString() + ".txt")
For j = 0 To Count
s1 = xx(j).ToString() + "," + yy(j).ToString() + "," + zz(j).ToString()
sw.WriteLine(s1)
Next
sw.Close()
SaveNum = SaveNum + 1
End Using
ExitNum = 0
Call 批量获取节点坐标Button_Click(sender, e)
Exit Sub
handle01:
ExitNum = ExitNum + 1
If ExitNum = 2 Then
ExitNum = 0
Exit Sub
Else : Call 批量获取节点坐标Button_Click(sender, e)
End If
End Sub
Private Sub 设置文件保存路径Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 设置文件保存路径Button5.Click
Dim fdg As FolderBrowserDialog
fdg = New FolderBrowserDialog
fdg.ShowDialog()
If fdg.SelectedPath = "" Then Exit Sub
FolderPath = fdg.SelectedPath
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
On Error GoTo Handle01
Call 启动CAD()
Dim sset As AutoCAD.AcadSelectionSet
sset = AcadApp.ActiveDocument.SelectionSets.Add("NewSelectionSet")
' 提示用户选择对象
sset.SelectOnScreen()
Dim ent As Object
Dim sss As AutoCAD.AcadPoint
Count = -1
For Each ent In sset
If ent.Objectname = "AcDbPoint" Then
Count = Count + 1
ReDim Preserve xx(Count)
ReDim Preserve yy(Count)
ReDim Preserve zz(Count)
xx(Count) = ent.Coordinates(0)
yy(Count) = ent.Coordinates(1)
zz(Count) = ent.Coordinates(2)
End If
Next ent
If TextBox1.Text <> 0 Or TextBox2.Text <> 0 Or TextBox4.Text <> 0 Then
Call CalculateCoordinate()
End If
Dim i As Integer
Dim s As String = ""
For i = 0 To Count
s = s + xx(i).ToString() + "," + yy(i).ToString() + "," + zz(i).ToString() + Chr(13)
Next
RichTextBox1.Text = s
AcadApp.ActiveDocument.SelectionSets.Item("NewSelectionSet").Delete()
AppActivate(Me.Text)
Button3.Enabled = True
Exit Sub
Handle01:
AcadApp.ActiveDocument.SelectionSets.Item("NewSelectionSet").Delete()
Button5_Click(sender, e)
MsgBox(Err.Description)
End Sub
Private Sub Button6_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
On Error GoTo Handle01
AcadApp.ActiveDocument.Save()
Handle01:
MsgBox(Err.Description)
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Call 启动CAD()
Dim basePnt As Object
AcadApp.ActiveDocument.Utility.GetEntity(returnObj, basePnt)
returnObj.highlight(True)
AppActivate(AcadApp.Caption)
Dim i As Integer
For i = 0 To 500
On Error GoTo handle01
Count = i
ReDim Preserve xx(i)
ReDim Preserve yy(i)
ReDim Preserve zz(i)
xx(i) = returnObj.Coordinate(i)(0)
yy(i) = returnObj.Coordinate(i)(1)
zz(i) = returnObj.Coordinate(i)(2)
Next
handle01:
Count = Count - 1
Dim j As Integer
Dim s As String = ""
For j = 0 To Count
s = s + xx(j).ToString() + "," + yy(j).ToString() + "," + zz(j).ToString() + Chr(13)
Next
RichTextBox1.Text = s
Button3.Enabled = True
AppActivate(Me.Text)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call SetProcessWorkingSetSize()
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
On Error GoTo handle01
Call 启动CAD()
Dim basePnt As Object
AcadApp.ActiveDocument.Utility.GetEntity(returnObj, basePnt)
returnObj.highlight(True)
Call 获取2DPolyline节点坐标()
If TextBox1.Text <> 0 Or TextBox2.Text <> 0 Or TextBox4.Text <> 0 Then
Call CalculateCoordinate()
End If
Dim i As Integer
Dim s As String = ""
For i = 0 To Count
s = s + xx(i).ToString() + "," + yy(i).ToString() + "," + zz(i).ToString() + Chr(13)
Next
RichTextBox1.Text = s
Button3.Enabled = True
AppActivate(Me.Text)
Exit Sub
handle01:
MsgBox(Err.Description)
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Call 启动CAD()
Dim basePnt As Object
basePnt = AcadApp.ActiveDocument.Utility.GetPoint()
MsgBox("当前点击坐标位置为:X=" + basePnt(0).ToString() + ",Y=" + basePnt(1).ToString())
End Sub
Private Sub 打开CAD文件OToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开CAD文件OToolStripMenuItem.Click
On Error GoTo handle01
Dim dg As New OpenFileDialog
dg.Filter = "CAD files (*.dwg)|*.dwg|All files (*.*)|*.*"
dg.ShowDialog()
Dim s As String = dg.FileName
If s = "" Then Exit Sub
启动CAD()
AcadApp.Application.Documents.Open(s)
AcadApp.ActiveDocument.WindowState = AutoCAD.AcWindowState.acMax
AppActivate(Me.Text)
Button1.Enabled = True
Exit Sub
handle01:
MsgBox(Err.Description)
End Sub
Private Sub 保存CAD文件CToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 保存CAD文件CToolStripMenuItem.Click
On Error GoTo Handle01
AcadApp.ActiveDocument.Save()
Exit Sub
Handle01:
MsgBox(Err.Description)
End Sub
<!--v:3.2-->
分享到:
相关推荐
提取CAD坐标至Excel 提取CAD坐标至Excel 提取CAD坐标至Excel
中线逐桩坐标计算原理很好用的看一下你就会了解的。
中线CAD使用步骤
cad编辑时经常遇到线不共面的情况,该小程序可以轻松解决cad中线不共面问题
中线CAD基础操作流程.pdf
CAD二次开发的插件,可以生成平行线的中线,可以辅助建立PKPM模型。
汽车线束设计软件及中线CAD应用简介.pdf
齿轮传动CAD开发中线图程序化处理方法.pdf
ArcGIS中导出线的坐标值,将shp文件的坐标点导出来
汽车线束行业软件,唯一获得国家发明专利的软件。可以快速计算线长,导出各种工艺数据和1:1工装板。
汽车线束设计软件及中线CAD应用简介 (1).pdf
中线逐桩坐标计算原理PPT学习教案.pptx
可计算任意角度的边桩,同时系统在加桩时可一次计算多个边桩,桩间米数为自动计算时桩的间距,支持“桩间米数”与“加桩桩号”同时输入计算,逐桩计算时系统会将各主点坐标一并输出,支持多个“加桩桩号”一次输入...
偏中线标定工作是矿山测量的一项日常性工作,中线执行便是偏中线工作的内业解算成果。本文解释了中线执行的含义,并提出了几种解算中线执行的方法。
CAD学习全套,制图更容易,工程制图教程附加软件,简易专业。
每一个点有一个横纵坐标,单位为像素,根据感光阵列的大小(若干毫米)将坐标变换到实际摄像头上,单位变为米,根据每个点的X、Y坐标计算出Z(深度)将每个点的坐标代入逆透视变换公式中得到实际坐标系下的坐标.
在程序中即为输入已知数据,程序中要把数据赋给相应的变量!我们这时需要设置数组!数组的设置要根据需要来设置,由于我们进行的是坐标计算,坐标是两个值,所以我们在程序中把坐标设为二维数组。
高速公路测量中线放样过程及方法,介绍了高速公路测量的几种常用的方法。
1、让用户以横断面计算函数+工作表的形式按横断面几何关系来编制横断面计算表,用户相当于拥有了一个强大的横断面编辑器,可适应各种复杂断面形式,同时也便于作为模板保存,再配合本软件提供的CAD自动绘图工具实时...