Message 1 of 16
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, new to a lot of this, and trying to expedite some of my common mundane processes. In this code, the end goal is to get a working rule to allow me to print each individual part that already had an associated part .dwg, without printing the assemblies. Later on, the goal is to set up a form to print the options of: Print all part .dwg's on letter paper, and print .iam's on ledger paper. Attached is the current code, it errors out on the attempt to exclude line. Any help appreciated!
'Check that the active document is an assembly file If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MessageBox.Show("Please run this rule from the assembly file.", "iLogic") Exit Sub End If 'Define the active document as an assembly file Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4) 'get user input userConfirm = MessageBox.Show ( _ "This will print the dwg for all of the assembly components that have" _ & vbLf & "drawings files. This rule expects that the drawing file shares the same" _ & vbLf & " name and location as the component." _ & vbLf & "" _ & vbLf & "Make sure the file extensions are set to Visible in Windows Explorer." _ & vbLf & "" _ & vbLf & "This could take a while. Are you sure you want to do this?" _ & vbLf & "" _ & vbLf & "", "iLogic - Batch Output dwgs ",MessageBoxButtons.YesNo) If userConfirm = vbNo Then Return Else End If '- - - - - - - - - - - - -Print setup - - - - - - - - - - - - If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MsgBox ("This is NOT an assembly document!") Exit Sub End If Dim oPrintMgr As PrintManager oPrintMgr = ThisApplication.ActiveDocument.PrintManager Dim oRefDocs As DocumentsEnumerator oRefDocs = oAsmDoc.AllReferencedDocuments Dim oRefDoc As Document numFiles = 0 '- - - - - - - -- - -Component Drawings - - - - - - - - For Each oRefDoc In oRefDocs oFileType = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName)) If oFileType.Contains("iam") Component.InventorComponent(oFileType).ExcludeFromPrinting = True Else If oFileType.Contains("ipt") Component.InventorComponent(oFileType).ExcludeFromPrinting = False End If partDrawings = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "dwg" If (System.IO.File.Exists(partDrawings)) Then numFiles = numFiles + 1 Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.Documents.Open(partDrawings, True) oDrawDoc.Activate oDrawDoc = ThisApplication.ActiveDocument oDrgPrintMgr = oDrawDoc.PrintManager oDrgPrintMgr.AllColorsAsBlack = True oDrgPrintMgr.ScaleMode = kPrintBestFitScale oPrintMgr = ThisApplication.ActiveDocument.PrintManager ' Printer setup, default printer 'oPrintMgr.ColorMode = kPrintDefaultColorMode ' Set to default. Uses printer settings oPrintMgr.PrintRange = kPrintAllSheets 'Prints all sheets in the dwg. oPrintMgr.NumberOfCopies = 1 ' Set to print one copies. oPrintMgr.Orientation = kLandscapeOrientation ' Set to print using landscape orientation. oPrintMgr.PaperSize = kPaperSizeLetter 'Set the paper size. oPrintMgr.SubmitPrint ' Submit the print. oDrawDoc.Close (True) End If Next MessageBox.Show ("There were " & numFiles & " files sent to the printer."," Job Complete ")
Solved! Go to Solution.