乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 47|回复: 3

从Excel更新属性

[复制链接]

4

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
25
发表于 2006-6-27 01:39:43 | 显示全部楼层 |阅读模式
您好:
有人会知道对我说我哪里有问题a。
1º 使用 Autodesk 中的宏“Exttr”从 AutoCAD 导入属性。
2º 要使用宏“RestoreByHand”导出在excel的worsheet中对AutoCAD图形所做的任何修改都不起作用
它是AutoCAD 2004。
我把代码留给它,以防他们可以帮助我,事先感谢。
  1. Public acad As Object
  2. Public mspace As Object
  3. Public Excel As Object
  4. Public AcadRunning As Integer
  5. Public excelSheet As Object
  6. '_______________________________________________________________________________________
  7. Sub Extract()
  8.     Dim sheet As Object
  9.     Dim shapes As Object
  10.     Dim elem As Object
  11.     Dim Excel As Object
  12.     Dim Max As Integer
  13.     Dim Min As Integer
  14.     Dim NoOfIndices As Integer
  15.     Dim excelSheet As Object
  16.     Dim RowNum As Integer
  17.     Dim Array1 As Variant
  18.     Dim Count As Integer
  19.     Dim SHand As String
  20.     Dim TStr As String
  21.      
  22.     Set Excel = GetObject(, "Excel.Application")
  23.     Worksheets("Attributes").Activate
  24.     Set excelSheet = Excel.ActiveWorkbook.Sheets("Attributes")
  25.     excelSheet.Range(Cells(1, 1), Cells(5000, 100)).Clear
  26.     excelSheet.Range(Cells(1, 1), Cells(1, 100)).Font.Bold = True
  27.     Set acad = Nothing
  28.     On Error Resume Next
  29.     Set acad = GetObject(, "AutoCAD.Application")
  30.     If Err  0 Then
  31.         Set acad = CreateObject("AutoCAD.Application")
  32.         MsgBox "Open the drawing file first and then rexecute!"
  33.         Exit Sub
  34.     End If
  35.     acad.Visible = True
  36.     Set doc = acad.ActiveDocument
  37.     Set mspace = doc.ModelSpace
  38.     RowNum = 1
  39.     Dim Header As Boolean
  40.     Header = False
  41.     For Each elem In mspace
  42.         With elem
  43.             If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then
  44.                 If .HasAttributes Then
  45.                     Array1 = .GetAttributes
  46.                     For Count = LBound(Array1) To UBound(Array1)
  47.                         If Header = False Then
  48.                             If StrComp(Array1(Count).EntityName, "AcDbAttribute", 1) = 0 Then
  49.                                 TStr = Array1(Count).TagString
  50.                                 excelSheet.Cells(RowNum, Count + 1).Value = TStr
  51.                             End If
  52.                         End If
  53.                     Next Count
  54.                     RowNum = RowNum + 1
  55.                     For Count = LBound(Array1) To UBound(Array1)
  56.                         TStr = Array1(Count).TextString
  57.                         excelSheet.Cells(RowNum, Count + 1).Value = TStr
  58.                     Next Count
  59.                     SHand = elem.Handle
  60.                     excelSheet.Cells(RowNum, Count + 1).NumberFormat = "@"
  61.                     excelSheet.Cells(RowNum, Count + 1).Value = SHand
  62.                     Header = True
  63.                 End If
  64.             End If
  65.         End With
  66.     Next elem
  67.     NumberOfAttributes = RowNum - 1
  68.     Set acad = Nothing
  69. End Sub
  70. '_______________________________________________________________________________________
  71. Sub RestoreByHand()
  72.     Dim sheet As Object
  73.     Dim shapes As Object
  74.     Dim elem As Object
  75.     Dim Excel As Object
  76.     Dim Max As Integer
  77.     Dim Min As Integer
  78.     Dim NoOfIndices As Integer
  79.     Dim excelSheet As Object
  80.     Dim RowNum As Integer
  81.     Dim Array1 As Variant
  82.     Dim Count As Integer
  83.     Dim SHand As String
  84.     Dim tempObj As Object
  85.      
  86.     Set Excel = GetObject(, "Excel.Application")
  87.    
  88.     Worksheets("Attributes").Activate
  89.     Set excelSheet = Excel.ActiveWorkbook.Sheets("Attributes")
  90.    
  91. Dim iLig As Integer
  92. Dim ColHand As Long, LigHand1 As Long, LigHand2 As Long
  93.         
  94.     Set acad = Nothing
  95.     On Error Resume Next
  96.     Set acad = GetObject(, "AutoCAD.Application")
  97.     If Err  0 Then
  98.         Set acad = CreateObject("AutoCAD.Application")
  99.         MsgBox "Open AutoCAD launch"
  100.         Exit Sub
  101.     End If
  102.     acad.Visible = True
  103.     Set doc = acad.ActiveDocument
  104.     Set mspace = doc.ModelSpace
  105.     RowNum = 1
  106.     Dim Header As Boolean
  107.     Header = False
  108.    
  109.     ColHand = 17
  110.     LigHand1 = 1
  111.     LigHand2 = 10000
  112.     Dim iArray As Long
  113.     Dim jL As Long
  114.    
  115.     iArray = 0
  116.     For iLig = LigHand1 To LigHand2
  117.        iArray = iArray + 1
  118.        SHand = excelSheet.Cells(iLig, ColHand).Value
  119.          If SHand  "" Then
  120.             Set tempObj = doc.HandleToObject(SHand)
  121.             Array1 = tempObj.GetAttributes
  122.                For jL = 0 To 40
  123.                TStr = excelSheet.Cells(iLig, jL + 1).Value
  124.                Array1(jL).TextString = TStr
  125.                Next jL
  126.          End If
  127.                                                                   
  128.     Next iLig
  129.    
  130.     Set acad = Nothing
  131. End Sub

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

85

主题

404

帖子

7

银币

中流砥柱

Rank: 25

铜币
751
发表于 2006-6-27 10:49:26 | 显示全部楼层
无代码宝贝!
我已经使用快速工具完成了这项工作。
您可以使用过滤器仅选择您感兴趣的块。
快速工具->块->导出属性信息
~在Excel中处理数据,保持列和行的完整性。完成后保存文件。~
快捷工具->块->导入属性信息
不是代码,但希望有用。
如果您仍然需要基于代码的解决方案,请告诉我们。
回复

使用道具 举报

85

主题

404

帖子

7

银币

中流砥柱

Rank: 25

铜币
751
发表于 2006-6-27 10:53:17 | 显示全部楼层
代码在什么方面是免费的?诚然,它使用预先提供的代码来完成任务,但代码仍然存在。
回复

使用道具 举报

85

主题

404

帖子

7

银币

中流砥柱

Rank: 25

铜币
751
发表于 2006-6-27 11:02:34 | 显示全部楼层
好吧,代码免费,因为不需要编写额外的
代码。
我想将计算机用于门挡以外的任何东西都不是免费的...
现在至少我们有免费的代码。但这是一个不同的话题。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-5 23:34 , Processed in 0.790459 second(s), 71 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表