Option Explicit
Dim xlApp As Object
Dim xlBook As Object
Dim xlSheet As Object
'将CAD的图形数据写入Excel
Public Sub CadToExcel()
Dim sset As AcadSelectionSet
Dim filterType(0) As Integer, filterData(0) As Variant
On Error Resume Next
Set sset = ThisDrawing.SelectionSets.Add("ToExcel")
If Err.Number <> 0 Then
Err.Clear
Set sset = ThisDrawing.SelectionSets.Item("ToExcel")
sset.Clear
End If
Set xlApp = CreateObject("Excel.Application")
If Err.Number <> 0 Then
Err.Clear
MsgBox "Excel软件没有正确打开。", vbOKOnly + 16, "提示:"
Exit Sub
End If
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
filterType(0) = 0
filterData(0) = "line,circle,arc"
sset.SelectOnScreen filterType, filterData
If sset.Count = 0 Then Exit Sub
xlSheet.Range("A1") = "ObjectCount"'写入标题
xlSheet.Range("B1") = sset.Count '写入数据
Dim Obj As AcadEntity, i As Long, varCP As Variant
i = 2
For Each Obj In sset
Select Case Obj.ObjectName
Case "AcDbCircle"
varCP = Obj.Center
xlSheet.Range(("A" & i)) = "AcDbCircle"'写入对象名
xlSheet.Range(("B" & i)) = Obj.Radius'写入半径数据
xlSheet.Range(("C" & i)) = varCP(0) & "," & varCP(1) & "," & varCP(2)'写入圆心坐标数据
Case "AcDbLine"
xlSheet.Range(("A" & i)) = "AcDbLine"'写入对象名
varCP = Obj.StartPoint
xlSheet.Range(("B" & i)) = varCP(0) & "," & varCP(1) & "," & varCP(2)'写入起点坐标数据
varCP = Obj.EndPoint
xlSheet.Range(("C" & i)) = varCP(0) & "," & varCP(1) & "," & varCP(2)'写入终点坐标数据
Case "AcDbArc"
varCP = Obj.Center
xlSheet.Range(("A" & i)) = "AcDbArc"'写入对象名
xlSheet.Range(("B" & i)) = Obj.Radius'写入半径数据
xlSheet.Range(("C" & i)) = varCP(0) & "," & varCP(1) & "," & varCP(2)'写入圆心坐标数据
xlSheet.Range(("D" & i)) = Obj.StartAngle'写入起始角数据
xlSheet.Range(("E" & i)) = Obj.EndAngle '写入终止角数据
End Select
i = i + 1
Next
xlApp.Visible = True
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
'提取Excel数据升成CAD图形
Public Sub ExcelToCAD()
Dim ObjectCount As Long, strTemp() As String, i As Long, strFileName As String
On Error Resume Next
Set xlApp = CreateObject("Excel.Application")
If Err.Number <> 0 Then
Err.Clear
MsgBox "Excel软件没有正确打开。", vbOKOnly + 16, "提示:"
Exit Sub
End If
strFileName = InputBox("输入保存CAD图形数据的Excel文件.", "打开文件:")
If Dir(strFileName) = "" Then
MsgBox "文件未找到。"
Exit Sub
End If
Set xlBook = xlApp.Workbooks.Open(strFileName)
Set xlSheet = xlBook.Worksheets(1)
Dim dblRadius As Double, dblCenter(2) As Double, j As Integer
ObjectCount = Val(xlSheet.Range("B1"))
For i = 2 To (ObjectCount + 1)
Select Case xlSheet.Range(("A" & i))
Case "AcDbCircle"
dblRadius = xlSheet.Range(("B" & i)) '读入半径数据
strTemp = Split(xlSheet.Range(("C" & i)), ",")'读入圆心坐标数据
For j = 0 To 2: dblCenter(j) = Val(strTemp(j)): Next j#p#分页标题#e#
ThisDrawing.ModelSpace.AddCircle dblCenter, dblRadius
Case "AcDbLine"
Dim dblStartP(2) As Double, dblEndP(2) As Double
strTemp = Split(xlSheet.Range(("B" & i)), ",") '读入起点坐标数据
For j = 0 To 2: dblStartP(j) = Val(strTemp(j)): Next j
strTemp = (Split(xlSheet.Range(("C" & i)), ","))'读入终点坐标数据
For j = 0 To 2: dblEndP(j) = Val(strTemp(j)): Next j
ThisDrawing.ModelSpace.AddLine dblStartP, dblEndP
Case "AcDbArc"
Dim dblStartAngle As Double, dblEndAngle As Double
dblRadius = Val(xlSheet.Range(("B" & i))) '读入半径数据
strTemp = Split(xlSheet.Range(("C" & i)), ",")'读入圆心坐标数据
For j = 0 To 2: dblCenter(j) = Val(strTemp(j)): Next j
dblStartAngle = Val(xlSheet.Range(("D" & i))) '读入起始角数据
dblEndAngle = Val(xlSheet.Range(("E" & i))) '读入终止角数据
ThisDrawing.ModelSpace.AddArc dblCenter, dblRadius, dblStartAngle, dblEndAngle
End Select
Next i
xlBook.Close
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
相关文章
- 2021-09-08BIM技术丛书Revit软件应用系列Autodesk Revit族详解 [
- 2021-09-08全国专业技术人员计算机应用能力考试用书 AutoCAD2004
- 2021-09-08EXCEL在工作中的应用 制表、数据处理及宏应用PDF下载
- 2021-08-30从零开始AutoCAD 2014中文版机械制图基础培训教程 [李
- 2021-08-30从零开始AutoCAD 2014中文版建筑制图基础培训教程 [朱
- 2021-08-30电气CAD实例教程AutoCAD 2010中文版 [左昉 等编著] 20
- 2021-08-30电影风暴2:Maya影像实拍与三维合成攻略PDF下载
- 2021-08-30高等院校艺术设计案例教程中文版AutoCAD 建筑设计案例
- 2021-08-29环境艺术制图AutoCAD [徐幼光 编著] 2013年PDF下载
- 2021-08-29机械AutoCAD 项目教程 第3版 [缪希伟 主编] 2012年PDF