- UID
- 76071
- 积分
- 1505
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-8-30
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Private pFileName As String
Private objDbx As AxDbDocument
Public Names As New Collection
Private Sub Class_Initialize()
Set objDbx = GetInterfaceObject("ObjectDBX.AxDbDocument.16")
End Sub
Public Function GetBlock(ByVal BlockName As String) As AcadBlock
'将文件中的块读入当前图形
Dim pBlock As AcadBlock
Dim pnt(2) As Double
Dim pObjs() As AcadEntity
Set pBlock = objDbx.Blocks(BlockName)
ReDim pObjs(pBlock.Count - 1) As AcadEntity
For i = 0 To pBlock.Count - 1
Set pObjs(i) = pBlock(i)
Next i
Set GetDbxBlock = ThisDrawing.Blocks.Add(pnt, "*U")
objDbx.CopyObjects pObjs, GetDbxBlock
End Function
Public Function GetBlockImage(ByVal BlockName As String) As IPictureDisp
'获取块的预览图像
Dim pObj(0) As AcadEntity
Dim pnt(2) As Double
Dim ss As AcadSelectionSet
Set pObj(0) = objDbx.ModelSpace.InsertBlock(pnt, BlockName, 1, 1, 1, 0)
objDbx.CopyObjects pObj, ThisDrawing.ModelSpace
Set pObj(0) = ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1)
pObj(0).GetBoundingBox d1, d2
ThisDrawing.Application.ZoomWindow d1, d2
On Error Resume Next
ThisDrawing.SelectionSets("*TlsDbx*").Delete
Set ss = ThisDrawing.SelectionSets.Add("*TlsDbx*")
ss.AddItems pObj
ThisDrawing.Export "c:\Temp", "wmf", ss
ss.Delete
pObj(0).Delete
ThisDrawing.Blocks(BlockName).Delete
ThisDrawing.Application.ZoomPrevious
Set GetBlockImage = LoadPicture("c:\temp.wmf")
Kill "c:\temp.wmf"
End Function
Public Property Let FileName(ByVal str As String)
'打开文件
Dim i As AcadBlock
pFileName = str
objDbx.Open str
Set Names = New Collection
For Each i In objDbx.Blocks
If Not (i.IsLayout Or i.IsXRef) Then
Names.Add i.Name
End If
Next i
End Property
上述代码存为TlsDbx类
插入一个窗体
加入ListBox控件和Image控件
在窗体加入下列代码
Dim a As New TlsDbx
Private Sub ListBox1_Click()
Set Me.Image1.Picture = a.GetBlockImage(ListBox1.Text)
End Sub
Private Sub UserForm_Activate()
a.FileName = "d:\ccd.dwg"
For Each i In a.Names
Me.ListBox1.AddItem i
Debug.Print i
Next i
End Sub
谢谢efan斑竹的提议,已修正过 |
|