明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3654|回复: 1

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

[复制链接]
发表于 2008-6-23 20:36:00 | 显示全部楼层 |阅读模式

Sub XS()
Dim RowNum As Integer
Dim Header As Boolean
Dim elem As AcadEntity
Dim Array1 As Variant
Dim Count As Integer
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument
Dim MSP As AcadEntity
Dim WenZi As String
On Error Resume Next
RowNum = 1
Header = False
For Each elem In ThisDrawing.ModelSpace
With elem
If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then
If .HasAttributes Then
Array1 = .GetAttributes
RowNum = RowNum + 1
    For Count = LBound(Array1) To UBound(Array1)
    WenZi = WenZi + Array1(Count).TextString + "\/"
    Next Count
    WenZi = WenZi + Chr$(13) + Chr$(10)
Header = True
End If
End If
End With
Next elem
   FileName = "C:\XS.XS"
   FileNum = 1
   Open FileName For Output As FileNum
   Print #FileNum, WenZi
   Close #FileNum
End Sub

这段程序可以将CAD图形中的块属性值提取出来,但是只能在CAD里边做为宏执行,那位大侠能帮帮帮忙移植到VB里边,用VB程序提取当前打开的CAD图形块信息,

感激不尽,谢谢了

发表于 2010-6-24 10:26:00 | 显示全部楼层

Sub XS()
    Dim RowNum As Integer
    Dim Header As Boolean
    Dim elem As Object  'AcadEntity
    Dim Array1 As Variant
    Dim Count As Integer
   
    Dim acadApp As Object  'AcadApplication
    Dim acadDoc As Object  'AcadDocument
    Dim MSP As Object  'AcadEntity
    Dim WenZi As String
    On Error Resume Next
   
    '---------------------------------------------------

    '新增部分
    Set acadApp = GetObject(, "AutoCAD.Application")
    If Err Then
        Err.Clear
        Set acadApp = CreateObject("AutoCAD.Application")
        If Err Then
            MsgBox Err.Description
            End
            Exit Sub
        End If
    End If
    acadApp.Visible = True
    Set acadDoc = acadApp.ActiveDocument
    '-----------------------------------------------------
   
    RowNum = 1
    Header = False
    For Each elem In acadDoc.ModelSpace 'ThisDrawing.ModelSpace
        With elem
        If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then
        If .HasAttributes Then
        Array1 = .GetAttributes
        RowNum = RowNum + 1
            For Count = LBound(Array1) To UBound(Array1)
            WenZi = WenZi + Array1(Count).TextString + "\/"
            Next Count
            WenZi = WenZi + Chr$(13) + Chr$(10)
        Header = True
        End If
        End If
        End With
    Next elem
       FileName = "C:\XS.XS"
       FileNum = 1
       Open FileName For Output As FileNum
       Print #FileNum, WenZi
       Close #FileNum
End Sub

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 14:33 , Processed in 0.153572 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表