职业IT人-IT人生活圈

 找回密码
 成为会员
搜索
查看: 2577|回复: 1

在VBA中调用AUTOCAD打印文件

[复制链接]
梦段桥 发表于 2007-9-2 20:42 | 显示全部楼层 |阅读模式
花了一下午完成了一个初步的示范的例子,看来解决图纸统一管理有了解决的办法了.下一步用jacob封装在java中调用,在服务器上控制打印管理.做个记号再慢慢完善.

'取得当前文档对象(vba中的方法,如果是在VB中时需要从顶层对象开始引用取得)
Dim currentDoc As AcadDocument
Set currentDoc = ThisDrawing

'文档的模型空间
Dim sp As AcadModelSpace
Set sp = currentDoc.modelspace

'取得模型空间中的块属性
Dim index As Integer
For index = 0 To sp.Count - 1
  Dim name As String
  name = sp.Item(index).ObjectName
  
  '判断模型空间中的项目是否是一个块引用
  If name Like \"*Ac*\" Then
   
    Dim blockRef As AcadBlockReference
    Set blockRef = sp.Item(index)
   
    '块引用的插入点
    Dim insertPoint As Variant
    insertPoint = blockRef.InsertionPoint
   
    '放大比例
    Dim xScale, yScale As Integer
    xScale = blockRef.XScaleFactor
    yScale = blockRef.YScaleFactor
   
   
    '宽高基数
    Dim width, height As Double
    width = 297
    height = 210
   
    '打印区域
    Dim UpperRight(0 To 1) As Double, LowerLeft(0 To 1) As Double
    UpperRight(0) = insertPoint(0)
    UpperRight(1) = insertPoint(1)
    LowerLeft(0) = insertPoint(0) + width * xScale
    LowerLeft(1) = insertPoint(1) - height * yScale
   

   
    list.AddItem \"inserPoint:X=\" & UpperRight(0) & \" Y:\" & UpperRight(1)
    list.AddItem \"lowerLeft :X=\" & LowerLeft(0) & \" Y:\" & LowerLeft(1)
   
   
    Dim plotConfs As AcadPlotConfigurations
    Set plotConfs = ThisDrawing.PlotConfigurations
    list.AddItem plotConfs.Count
   
  
    Dim plotconf As AcadPlotConfiguration
    Set plotconf = plotConfs.Add(\"plot\")
    'list.AddItem plotconf.GetPlotDeviceNames(5)
   
    'Set plotConf = ThisDrawing.PlotConfigurations.Add
   
   
    '设置定义要打印的布局范围的坐标
    ThisDrawing.ActiveLayout.SetWindowToPlot LowerLeft, UpperRight
    '指定布局或打印配置的类型
    ThisDrawing.ActiveLayout.PlotType = acWindow
    '按局部或完整视图预览方式显示打印预览对话框
    ThisDrawing.Plot.DisplayPlotPreview acFullPreview
    '打印布局到设备
    ThisDrawing.Plot.PlotToDevice
   
  End If

  
Next index
蓝色梦幻 发表于 2007-9-3 12:48 | 显示全部楼层
VB的语法很久没用,打印功能似乎被扩展了,不过让我比较懒得写这么多代码,会引用一个onclick="javascript:printPage();"
您需要登录后才可以回帖 登录 | 成为会员

本版积分规则

QQ|手机版|小黑屋|网站帮助|职业IT人-IT人生活圈 ( 粤ICP备12053935号-1 )|网站地图
本站文章版权归原发布者及原出处所有。内容为作者个人观点,并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是信息平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽造成漏登,请及时联系我们,我们将根据著作权人的要求立即更正或者删除有关内容。

GMT+8, 2024-5-15 14:51 , Processed in 0.147946 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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