乐筑天下

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

[编程交流] VB。Net SelectFilter from Excel

[复制链接]

1

主题

1

帖子

0

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 22:14:10 | 显示全部楼层 |阅读模式
尊敬的各位:,
在Excel VBA中,我有一个宏,可以检索选定块的所有属性(选择也在Excel VBA中完成),并循环到Excel工作表中列出的所有文件。现在,我正在尝试将VBA迁移到VB。网
 
这里是我使用代码的地方,但它不起作用,我不知道为什么(当然,否则,我不会在这里;)
 
我正在使用Autocad 2013和Visual Studio 2010。
 
我试图选择C2单元中的块,
块位于单元格C1的布局上
在细胞C3层
 
我想宣言就是问题所在。。。。但我想不出。。。
 
PS:我不想使用NETLOAD命令,因为Autocad文件在操作过程中不应可见。
 
谢谢你的帮助。
赫维
 
 
  1. Imports Microsoft.Office.Interop Imports System.Data.SqlClient Imports System.Data.OleDb Imports System.IO Imports Autodesk.AutoCAD.Interop Imports System Imports System.Runtime.InteropServices Imports Excel = Microsoft.Office.Interop.Excel        Sub Import()         xlsApp = New Excel.Application         xlsApp.Visible = True         xlsWB = xlsApp.Workbooks.Open(Frm_Main.LblFile1.Text)         xlsSheetTwo = xlsWB.Worksheets("Import")          Dim a As Integer         a = 5         Dim dirInfo As New DirectoryInfo(Frm_Main.LblFolder1.Text)         Dim fileInfo As FileInfo         For Each fileInfo In dirInfo.GetFiles("*.dwg") 'dwg for Autocad             xlsSheetTwo.Cells(a, 1) = fileInfo.Name             a = a + 1         Next          Dim AcadApp As AutoCAD.AcadApplication         Dim SelSet As AutoCAD.AcadSelectionSet         Dim Entity As AutoCAD.AcadEntity         Dim BlocRef As AutoCAD.AcadBlockReference         Dim filterType As Object         Dim filterData As Object          Dim p1(0 To 2) As Double         Dim p2(0 To 2) As Double          Dim grpCode(0 To 2) As Integer         Dim grpValue(0 To 2) As String          Dim i, Row, j, Column As Integer         Dim Attributes As Object         Dim ColumnExist As Boolean          xlsSheetTwo.Select()         ' Delete Excel records         xlsSheetTwo.Range("B5:TZ65536").ClearContents()          xlsApp.Application.Visible = True          ' AutoCAD Connection         On Error Resume Next         AcadApp = GetObject(, "AutoCAD.Application")         On Error GoTo 0         If AcadApp Is Nothing Then             AcadApp = New AutoCAD.AcadApplication         End If         AcadApp.Visible = True          'Open the DWG         Dim Opened As Boolean         Opened = False          Dim k As Integer         k = 5         Row = 5         For k = 5 To xlsSheetTwo.Range("A65536").End(Excel.XlDirection.xlUp).Row              AcadApp.Documents.Open(Frm_Main.LblFolder1.Text & "" & xlsSheetTwo.Cells(k, 1).Text)              On Error Resume Next             SelSet = AcadApp.ActiveDocument.SelectionSets.Add("SELSET")             If ErrorToString() <> 0 Then                 SelSet = AcadApp.ActiveDocument.SelectionSets.Item("SELSET")                 SelSet.Clear()             End If              'Creation of Filter             grpCode(0) = 8   ' Layer             grpCode(1) = 2   ' Block Name             grpCode(2) = 410 ' Layout             filtertype = grpCode              ' Filter on Layout Name             grpValue(2) = xlsSheetTwo.Cells(1, 3).text              ' Filter on BLOCK Name             grpValue(1) = xlsSheetTwo.Cells(2, 3).text              ' Filter on LAYER Name             grpValue(0) = xlsSheetTwo.Cells(3, 3).text              filterData = grpValue              SelSet.Select(AutoCAD.AcSelect.acSelectionSetAll, , , filterType, filterData)              ' Go throuhg Selection             For i = 0 To SelSet.Count - 1                 Entity = SelSet.Item(i)                  If Entity.ObjectName = "AcDbBlockReference" Then                     BlocRef = Entity                      If BlocRef.HasAttributes Then                         Attributes = BlocRef.GetAttributes                         For j = LBound(Attributes) To UBound(Attributes)                             Column = 3                             ColumnExist = False                             While Not String.IsNullOrEmpty(xlsSheetTwo.Cells(4, Column))                                  If xlsSheetTwo.Cells(4, Column).Text = Attributes(j).TagString Then                                     xlsSheetTwo.Cells(Row, Column).Value = Attributes(j).TextString                                     ColumnExist = True                                 End If                                 Column = Column + 1 ' On passe à la colonne suivante                             End While                              If Not ColumnExist Then                                 xlsSheetTwo.Cells(4, Column).Value = Attributes(j).TagString                                 xlsSheetTwo.Cells(Row, Column).Value = Attributes(j).TextString                             End If                         Next ' Next Attribut                     End If                 End If             Next              AcadApp.ActiveDocument.Close()             Row = Row + 1   'Next Line         Next k         AcadApp.Quit()         MsgBox("Attributs of " & xlsSheetTwo.Cells(2, 1).Text & " have been retreived.")      End Sub End Module
回复

使用道具 举报

12

主题

175

帖子

77

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
149
发表于 2022-7-6 22:49:28 | 显示全部楼层
 
我没有(希望永远不会)使用。NET,所以我只能从VBA中猜测:filterType和filterData是否应该声明为变量(而不是对象)变量?
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 23:40:00 | 显示全部楼层
请看我的回答
http://forums.autodesk.com/t5/NET/VB...4652267#M37871
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 08:54 , Processed in 0.379861 second(s), 69 queries .

© 2020-2025 乐筑天下

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