乐筑天下

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

[转帖]谁要是把这些库用好了,可就是VBA大侠了.

[复制链接]

32

主题

52

帖子

6

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
180
发表于 2009-2-26 13:02:00 | 显示全部楼层 |阅读模式
转帖=
此函数库节选
'**************************************
' Name: Create New Layer and Set Current VBA
' Description:Another AutoCAD VBA example. This is a subroutine that will take a
'     string that is the layer name and create the layer if it doesn't exist, then make
'     that layer current. You can add more inputs to this like color, linetype, etc.
Private Sub MakeSetLayer(strLayer As String)
    Dim layCurrent As AcadLayer
    On Error Resume Next
    Set layCurrent = ThisDrawing.Layers(strLayer)
    If layCurrent Is Nothing Then
        Set layCurrent = ThisDrawing.Layers.Add(strLayer)
        If layCurrent Is Nothing Then
            MsgBox "Error creating layer " & strLayer & "."
            Exit Sub
        End If
    End If
    ThisDrawing.ActiveLayer = layCurrent
End Sub
'输出wmf文件,再导入新的cad文件中
'
Sub WMFOut()
    '插入wmf之前应该使用明天wmfopts命令设置导入的wmf是否填充和显示线宽
    ThisDrawing.SendCommand "wmfopts "
     On Error Resume Next
    '创建空选择集
    Dim SSet As AcadSelectionSet
    Set SSet = ThisDrawing.SelectionSets.Add("XXX")
    If Err Then
        ThisDrawing.SelectionSets("XXX").Delete
        Set SSet = ThisDrawing.SelectionSets.Add("XXX")
        Err.Clear
    End If
    '为选择集添加对象
    SSet.SelectOnScreen
    '将选择集中对象传递给Obj对象数组
    Dim Obj() As Object
    Dim i As Long
    ReDim Obj(0 To SSet.count - 1) As Object
    For i = 0 To SSet.count - 1
        Set Obj(i) = SSet.Item(i)
    Next i
   
    Dim Pmax As Variant
    Dim Pmin As Variant
    SSet.Item(0).GetBoundingBox Pmin, Pmax
   
    Dim B As acadBlock
    Set B = ThisDrawing.Blocks.Add(Pmin, NiMingKuai("WMF")) ' 将数组中的实体复制到块定义中
    ThisDrawing.CopyObjects Obj, B
   
   
    '插入块
    Dim EBRef As AcadBlockReference
    Set EBRef = ThisDrawing.ModelSpace.InsertBlock(Pmin, B.Name, 1, 1, 1, 0)
   
    EBRef.GetBoundingBox Pmin, Pmax
    Dim x As Double
    Dim y As Double
    x = Abs(Pmin(0) - Pmax(0)) '图形宽度
    y = Abs(Pmin(1) - Pmax(1)) '图形高度
   
    Dim Xy As Double
   
    Xy = x / y '图形宽高比
   
    x = 600 '文档视口宽度
   
    y = 600 / Xy '文档视口高度
   
    ThisDrawing.width = x
    ThisDrawing.Height = y
   
    ThisDrawing.Application.ZoomWindow Pmin, Pmax
   
    '导出wmf文件
    Dim P As String
    P = "c:/temp"
    ThisDrawing.Export P, "WMF", SSet
    '打开新图形
    ThisDrawing.Application.Documents.Add "acad.dwt"
   
    ThisDrawing.Import P & ".wmf", Point3D(0, 0, 0), 1
    '充满窗口
    ThisDrawing.Application.ZoomExtents
   
End Sub

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

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

使用道具 举报

0

主题

2

帖子

2

银币

初来乍到

Rank: 1

铜币
2
发表于 2009-3-22 08:02:00 | 显示全部楼层
谢谢楼主 :)
回复

使用道具 举报

6

主题

22

帖子

3

银币

初来乍到

Rank: 1

铜币
46
发表于 2009-4-2 19:22:00 | 显示全部楼层
比较  深奥!
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
1
发表于 2009-4-11 11:11:00 | 显示全部楼层
好东西。初学者有用
回复

使用道具 举报

0

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
3
发表于 2009-4-20 21:35:00 | 显示全部楼层
学习学习
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-2 05:40 , Processed in 0.367236 second(s), 79 queries .

© 2020-2025 乐筑天下

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