乐筑天下

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

模拟原始批量打印

[复制链接]

8

主题

81

帖子

45

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
76
发表于 2018-1-19 13:07:49 | 显示全部楼层 |阅读模式
我决定将批处理/vba组合放在一起以模拟Microstation#039;的原始批量打印方法,因为我发现;“打印管理器”;与ProjectWise一起使用时动作迟缓。初步测试(使用批处理列表)只需打印组织者花费一半的时间即可打印出纸张。此外,批处理列表的加载速度比打印管理器pset文件快得多
临时删除PW中的写访问权限可以在不签出文件的情况下进行打印
一旦放置在正确的目录中,您可以使用“vba load ModuleName;vba运行模块名。searchandprint注意:此版本是为特定级别、打印驱动程序和笔表设置的
如果要将其修改为使用不同的ProjectWise打印驱动程序和/或笔表,请使用正确的本地文件夹路径和名称修改以下行。(我不确定“pw\u workdir”是标准变量还是在此处创建的。)
  1. CadInputQueue.SendKeyin "$ print driver $(pw_workdir)\dms08053\pdf - gs.pltcfg; print pentable attach $(pw_workdir)\dms08052\pen_txdot.tbl"
  1. Sub SearchAndPrint()
  2.   Dim Counter As Integer
  3.   Dim oEle As Element
  4.   Dim oLevel As Level
  5.   Dim LevelName As String
  6.   Dim oAtt As Attachment
  7.   Dim ee As ElementEnumerator
  8.   Dim esc As ElementScanCriteria
  9.   Dim oShape As ShapeElement
  10.   Dim oAttach As Attachment
  11.   Dim LNoAttach As Attachment 'Live Nested
  12.   Dim oView As View
  13.   Dim oFence As Fence
  14.   Dim fso As Object
  15.   Dim DatedFolder As String
  16.   
  17. Set fso = CreateObject("Scripting.FileSystemObject")
  18. If Not fso.FolderExists("C:\Temp") Then
  19.     fso.CreateFolder ("C:\Temp") 'Create Parent Directory if it doesn't exist
  20. End If
  21. DatedFolder = "C:\Temp" & Format(Now, "yyyy") & Format(Now, "mm") & Format(Now, "dd")
  22. If Not fso.FolderExists(DatedFolder) Then
  23. fso.CreateFolder (DatedFolder) 'Create dated Folder if it doesn't exist
  24. End If
  25.   Set oView = ActiveDesignFile.Views(1) 'Works ONLY with View 1
  26. Counter = 0 'Counter used to avoid overwriting files if multiple sheets are found
  27. Set esc = New ElementScanCriteria
  28. esc.ExcludeAllTypes
  29. esc.IncludeType msdElementTypeShape 'Only scans shapes
  30. If ActiveModelReference.Attachments.Count = 0 Then 'Scans active drawing levels if no reference file is detected
  31. Set ee = ActiveModelReference.Scan(esc)
  32. Do While ee.MoveNext
  33. Set oEle = ee.Current
  34. If Not oEle.Level Is Nothing Then
  35.     LevelName = oEle.Level.Name
  36.      If LevelName = "D_BATCH_PLOT" Then
  37.             Set oShape = oEle           'Pick Shape for fence if it resides on correct level
  38.   Set oFence = ActiveDesignFile.Fence
  39.   If oFence.IsDefined Then oFence.Undefine
  40.   oFence.DefineFromElement oView, oShape
  41.   Counter = Counter + 1
  42.   PrintPDF  'Print to pdf using predetermined settings in public function
  43.      End If
  44. End If
  45. Loop
  46. End If
  47.     For Each oAttach In ActiveModelReference.Attachments    'Scans Each Attachment in the active file
  48.         If oAttach.Attachments.Count > 0 And oShape Is Nothing Then       'Checks for live nesting and proceeds if no shape is found
  49.             For Each LNoAttach In oAttach.Attachments   'If nested attachments are found, they are also scanned
  50.                 Set ee = LNoAttach.Scan(esc)
  51.             Do While ee.MoveNext And oShape Is Nothing 'Scanning Continues until shape is found
  52.              Set oEle = ee.Current
  53.                 If Not oEle.Level Is Nothing Then
  54.                     LevelName = oEle.Level.Name
  55.                     If LevelName = "D_BATCH_PLOT" Then
  56.                         Set oShape = oEle          'Pick Shape for fence if it resides on correct level
  57.                          Set oFence = ActiveDesignFile.Fence
  58.                         If oFence.IsDefined Then oFence.Undefine
  59.                         oFence.DefineFromElement oView, oShape
  60.                         Counter = Counter + 1
  61.                         PrintPDF 'Print to pdf using predetermined settings in public function
  62.                     End If
  63.                 End If
  64.             Loop
  65.             Next
  66.         Else
  67.              Set ee = oAttach.Scan(esc) 'If no live nesting is detected, scan direct reference levels
  68.              Do While ee.MoveNext And oShape Is Nothing 'Until shape is found
  69.              Set oEle = ee.Current
  70.                 If Not oEle.Level Is Nothing Then
  71.                     LevelName = oEle.Level.Name
  72.                     If LevelName = "D_BATCH_PLOT" Then
  73.                         Set oShape = oEle         'Pick Shape for fence if it resides on correct level
  74.                          Set oFence = ActiveDesignFile.Fence
  75.                         If oFence.IsDefined Then oFence.Undefine
  76.                         oFence.DefineFromElement oView, oShape
  77.                         Counter = Counter + 1
  78.                         PrintPDF 'Print to pdf using predetermined settings in public function
  79.                     End If
  80.                 End If
  81.             Loop
  82.         End If
  83.         Set oShape = Nothing 'Sets Shape to nothing in case addtional border reference files are attached
  84.     Next
  85. Call OpenFolder(DatedFolder)    'Opens or brings focus to dated folder
  86. End Sub
  87. ' ---------------------------------------------------------------------
  88. '   PrintPDF
  89. '   Print using the pdf-gs.pltcfg
  90. '   Print using defined fence, view 1, pen_txdot.tbl
  91. '   Create a PDF document in a dated folder in c:\temp\
  92. ' ---------------------------------------------------------------------
  93. Public Sub PrintPDF()
  94.     '   Load the PLOTDLG application
  95.     CadInputQueue.SendKeyin "mdl load plotdlg"
  96.     Dim Path As String
  97.         Path = GetDgnFileName(ActiveModelReference)
  98.         Path = Replace(Path, ".dgn", "")
  99.         '   Set the PDF print driver and pen table
  100.         CadInputQueue.SendKeyin "$ print driver $(pw_workdir)\dms08053\pdf - gs.pltcfg; print pentable attach $(pw_workdir)\dms08052\pen_txdot.tbl"
  101.         '   Print with Active Fence
  102.         Dim oFence                          As Fence
  103.         Set oFence = ActiveDesignFile.Fence
  104.         If oFence.IsDefined Then
  105.             CadInputQueue.SendKeyin "print boundary fence"
  106.         Else
  107.             Const ViewNum                   As Integer = 1
  108.             CadInputQueue.SendKeyin "print boundary view " & CStr(ViewNum)
  109.         End If
  110.         'Const PaperSize As String = "11x17" '<--This is currently the only page size, so it has been commented out
  111.         'CadInputQueue.SendKeyin "print papername " & PaperSize
  112.         CadInputQueue.SendKeyin "print colormode color"
  113.         CadInputQueue.SendKeyin "print maximize"
  114.         '   Execute the print.  The PDF is sent to the dated folder in c:\temp
  115.         Path = "C:\Temp" & Format(Now, "yyyy") & Format(Now, "mm") & Format(Now, "dd") & "" & Path & "(" & Counter & ").pdf"
  116.         CadInputQueue.SendKeyin "print execute " & Path
  117. End Sub
  118. Public Function GetDgnFileName(ByVal modelRef As ModelReference) As String
  119.     GetDgnFileName = vbNullString
  120.     On Error GoTo err_GetDgnFileName
  121.     GetDgnFileName = modelRef.DesignFile.Name
  122.     Exit Function
  123. err_GetDgnFileName:
  124.     MsgBox "Error no. " & CStr(Err.Number) & ": " & Err.Description & vbNewLine & _
  125.     "Caused by " & Err.Source, vbOKOnly Or vbExclamation, "Get DGN File Name Error"
  126. End Function
  127. Private Sub OpenFolder(strDirectory As String)
  128. 'DESCRIPTION: Open folder if not already open. Otherwise, activate the already opened window
  129. 'DEVELOPER: Ryan Wells (wellsr.com)
  130. 'INPUT: Pass the procedure a string representing the directory you want to open
  131. Dim pID As Variant
  132. Dim sh As Variant
  133. On Error GoTo 102:
  134. Set sh = CreateObject("shell.application")
  135. For Each w In sh.Windows
  136.     If w.Name = "Windows Explorer" Or w.Name = "File Explorer" Then
  137.         If w.document.folder.self.Path = strDirectory Then
  138.             'if already open, bring it front
  139.             w.Visible = False
  140.             w.Visible = True
  141.             Exit Sub
  142.         End If
  143.     End If
  144. Next
  145. 'if you get here, the folder isn't open so open it
  146. pID = Shell("explorer.exe " & strDirectory, vbNormalFocus)
  147. 102:
  148. End Sub
一起被黑客攻击,但想分享。。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 08:52 , Processed in 0.545601 second(s), 54 queries .

© 2020-2025 乐筑天下

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