zm8391473 发表于 2008-6-23 20:36:00

[求助] VB提取当前所打开的CAD文件的块属性

<p>Sub XS()<br/>Dim RowNum As Integer<br/>Dim Header As Boolean<br/>Dim elem As AcadEntity<br/>Dim Array1 As Variant<br/>Dim Count As Integer<br/>Dim acadApp As AcadApplication<br/>Dim acadDoc As AcadDocument<br/>Dim MSP As AcadEntity<br/>Dim WenZi As String<br/>On Error Resume Next<br/>RowNum = 1<br/>Header = False<br/>For Each elem In ThisDrawing.ModelSpace<br/>With elem<br/>If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then<br/>If .HasAttributes Then<br/>Array1 = .GetAttributes<br/>RowNum = RowNum + 1<br/>&nbsp;&nbsp;&nbsp; For Count = LBound(Array1) To UBound(Array1)<br/>&nbsp;&nbsp;&nbsp; WenZi = WenZi + Array1(Count).TextString + "\/"<br/>&nbsp;&nbsp;&nbsp; Next Count<br/>&nbsp;&nbsp;&nbsp; WenZi = WenZi + Chr$(13) + Chr$(10)<br/>Header = True<br/>End If<br/>End If<br/>End With<br/>Next elem<br/>&nbsp;&nbsp; FileName = "C:\XS.XS"<br/>&nbsp;&nbsp; FileNum = 1<br/>&nbsp;&nbsp; Open FileName For Output As FileNum<br/>&nbsp;&nbsp; Print #FileNum, WenZi<br/>&nbsp;&nbsp; Close #FileNum<br/>End Sub</p><p>这段程序可以将CAD图形中的块属性值提取出来,但是只能在CAD里边做为宏执行,那位大侠能帮帮帮忙移植到VB里边,用VB程序提取当前打开的CAD图形块信息,</p><p>感激不尽,谢谢了</p>

zhejiang000 发表于 2010-6-24 10:26:00

<p><font face="Verdana">Sub XS()<br/>&nbsp;&nbsp;&nbsp; Dim RowNum As Integer<br/>&nbsp;&nbsp;&nbsp; Dim Header As Boolean<br/>&nbsp;&nbsp;&nbsp; Dim elem As Object&nbsp; 'AcadEntity<br/>&nbsp;&nbsp;&nbsp; Dim Array1 As Variant<br/>&nbsp;&nbsp;&nbsp; Dim Count As Integer<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim acadApp As Object&nbsp; 'AcadApplication<br/>&nbsp;&nbsp;&nbsp; Dim acadDoc As Object&nbsp; 'AcadDocument<br/>&nbsp;&nbsp;&nbsp; Dim MSP As Object&nbsp; 'AcadEntity<br/>&nbsp;&nbsp;&nbsp; Dim WenZi As String<br/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '---------------------------------------------------</font></p>
<p><font face="Verdana">&nbsp;&nbsp;&nbsp;&nbsp;'新增部分<br/>&nbsp;&nbsp;&nbsp; Set acadApp = GetObject(, "AutoCAD.Application")<br/>&nbsp;&nbsp;&nbsp; If Err Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Clear<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set acadApp = CreateObject("AutoCAD.Application")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Err Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox Err.Description<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; acadApp.Visible = True<br/>&nbsp;&nbsp;&nbsp; Set acadDoc = acadApp.ActiveDocument<br/>&nbsp;&nbsp;&nbsp; '-----------------------------------------------------<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; RowNum = 1<br/>&nbsp;&nbsp;&nbsp; Header = False<br/>&nbsp;&nbsp;&nbsp; For Each elem In acadDoc.ModelSpace 'ThisDrawing.ModelSpace<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; With elem<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If .HasAttributes Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Array1 = .GetAttributes<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RowNum = RowNum + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Count = LBound(Array1) To UBound(Array1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WenZi = WenZi + Array1(Count).TextString + "\/"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next Count<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WenZi = WenZi + Chr$(13) + Chr$(10)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Header = True<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End With<br/>&nbsp;&nbsp;&nbsp; Next elem<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileName = "C:\XS.XS"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileNum = 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Open FileName For Output As FileNum<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Print #FileNum, WenZi<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Close #FileNum<br/>End Sub</font></p>
页: [1]
查看完整版本: [求助] VB提取当前所打开的CAD文件的块属性