田草博客

互联网田草博客


网友交流QQ群:11740834 需注明申请加入原因

微信 公众号:ByCAD

邮箱:tiancao1001x126.com
ByCAD,微信公众号
首页 | 普通 | 电脑 | AutoCAD | VB/VB.NET | FLash | 结构 | 建筑 | 电影 | BIM | 规范 | 软件 | ID
-随机-|-分布-
-博客论坛-|-﨣﨤﨧﨨-
-网站导航-|-规范下载-
-BelovedFLash欣赏-

用户登陆
用户:
密码:
 

站点日历
73 2024 - 4 48
 123456
78910111213
14151617181920
21222324252627
282930


站点统计

最新评论



混凝土回弹计算方法 CAD VBA 统一标注样式中的字体
未知 CAD VBA 输出WMF文件 和导入WMF文件   [ 日期:2008-05-27 ]   [ 来自:本站原创 ]  HTML
'输出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



[本日志由 田草 于 2008-07-17 10:22 AM 编辑]


引用这个评论 tiancao1001 于 2008-12-02 12:24 AM 发表评论: 
'输出wmf文件
Public Function WMFOut(P1 As Variant, P2 As Variant, FileName As String)
    ThisDrawing.Application.ZoomAll
    '创建空选择集
    Dim SSet As AcadSelectionSet
    Set SSet = CreateSelectionSet("XXX")

    '为选择集添加对象
    SSet.Select acSelectionSetWindow, P1, P2

    '将选择集中对象传递给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 X As Double
    Dim Y As Double
    X = Abs(P1(0) - P2(0)) '图形宽度
    Y = Abs(P1(1) - P2(1)) '图形高度
    
    Dim Xy As Double
    
    Xy = X / Y '图形宽高比
    
    X = 600 '文档视口宽度
    
    Y = 600 / Xy '文档视口高度
    
    ThisDrawing.Width = X
    ThisDrawing.Height = Y
    
    ThisDrawing.Application.ZoomWindow P1, P2
    
    '导出wmf文件
    If UCase(Right(FileName, 4)) = ".WMF" Then
       FileName = Left(FileName, Len(FileName) - 4)
    End If
    ThisDrawing.Export FileName, "WMF", SSet
End Function

引用这个评论 田草 于 2008-07-17 10:22 AM 发表评论: 
Function ImportWMF(P As String)
    '输入文件
    If Dir(P) <> "" Then    '判断文件是否存在
        ThisDrawing.Import P, Point3D(0, 0, 0), 2
    Else
        Prompt "程序使用的临时文件不存在,请重新运行程序!"
        Exit Function
    End If
End Function 

发表评论 - 不要忘了输入验证码哦!
作者: 用户:  密码:   注册? 验证:  防止恶意留言请输入问题答案:2*2=?  
评论:

禁止表情
禁止UBB
禁止图片
识别链接
识别关键字

字体样式 文字大小 文字颜色
插入粗体文本 插入斜体文本 插入下划线
左对齐 居中对齐 右对齐
插入超级链接 插入邮件地址 插入图像
插入 Flash 插入代码 插入引用
插入列表 插入音频文件 插入视频文件
插入缩进符合
点击下载按钮 下标 上标
水平线 简介分割标记
表  情
 
Tiancao Blog All Rights Reserved 田草博客 版权所有
Copyright ©