好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

获取CAD中线的每个节点坐标程序设计.doc

23页
  • 卖家[上传人]:M****1
  • 文档编号:483703989
  • 上传时间:2023-07-21
  • 文档格式:DOC
  • 文档大小:66KB
  • / 23 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 获取CAD中线的每个节点坐标,线包括polyline、3D polyline、Spline等等!程序代码如下:Imports SystemImports System.IOImports System.MathPublic 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        Nexthandle01:        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        Nexthandle01:        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 Subhandle01:        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 (*.*)|*.*"。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.