Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all
At the moment I have a problem creating pdf batches, the current code works for me with new files (v2018) I even have failures with 2018 files (I attach files), but I have old files from 2008,2009,2013,2015.
The code extracts the iproperties to create the file name but with old files it doesn't work.
Can someone please help me
Attached example images, code and files
Thank you all!
Sub Main() Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) - 4) 'oRevNum = iProperties.Value("project", "revision number") 'Revisa que el documento activo es un ensamble If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MessageBox.Show("Por favor ejecute esta regla desde el archivo de ensamble.", "iLogic") Exit Sub End If 'obtener la aceptacion del usuario para ejecutar If MessageBox.Show ( _ "Esto creará un archivo pdf para todos los componentes del ensamble que tengan planos idw." _ & vbLf & "Esta regla espera que el archivo de dibujo comparta el mismo nombre y ubicación que el componente." _ & vbLf & " " _ & vbLf & "¿Está seguro de que desea crear planos PDF para todos los componentes del ensamble??" _ & vbLf & "Esto podría tomar un tiempo.", "iLogic - Batch Output PDFs ",MessageBoxButtons.YesNo) = vbNo Then Exit Sub End If Dim PDFAddIn As TranslatorAddIn Dim oContext As TranslationContext Dim oOptions As NameValueMap Dim oDataMedium As DataMedium Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium) oPath = ThisDoc.Path oFolder = oPath & "\" & oAsmName & " Archivos PDF\" oPath = System.IO.Directory.GetParent(oPath).FullName 'Establecer el nombre del archivo de destino PDF oDataMedium.FileName = oFolder & "\" & oFileName & " Description" & oDescription & ".pdf" If System.IO.Directory.Exists(oFolder) = False Then System.IO.Directory.CreateDirectory(oFolder) End If ''- - - - - - - - - - - - -Componentes de dibujo - - - - - - - - - - - -'mira los archivos a los que hace referencia el ensamble 'Dim oRefDoc As Document Dim fileName As String ' For Each oRefDoc In oRefDocs = oAsmDoc.AllReferencedDocuments ' Para cada oRefDoc En oRefDocs = oAsmDoc. Todos los documentos referenciados For Each oRefDoc In oAsmDoc.AllReferencedDocuments oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 3) iptPathName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 4) & ".ipt" iamPathName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 4) & ".iam" idwPathName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 4) & ".idw" 'Encontrar propiedades de IPT Dim oSPartNumber As String Dim oSDescription As String If(System.IO.File.Exists(iptPathName)) Then pathName = iptPathName ElseIf(System.IO.File.Exists(iamPathName)) Then pathName = iamPathName ElseIf(System.IO.File.Exists(idwPathName)) Then pathName = idwPathName End If If (System.IO.File.Exists(pathName)) Then oSPartNumber = iProperties.Value(pathName, "Project", "Project") oSDescription = iProperties.Value(pathName, "Project", "Description") oSComments = iProperties.Value(pathName, "Summary", "Comments") End If For Each fileName In System.IO.Directory.GetFiles(oPath, "*.idw", System.IO.SearchOption.AllDirectories) 'For Each fileName In System.IO.Directory.GetFiles(oPath, "*.idw",System.IO.SearchOption.AllDirectories) If fileName.EndsWith(oFileName + "idw") = True Then Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.Documents.Open(fileName, True) On Error Resume Next oDataMedium.FileName = oFolder & "\" & oSPartNumber & " - " & oSDescription & " - " & oSComments & ".pdf" Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium) oDrawDoc.Close On Error GoTo 0 End If Next Next '- - - - - - - - - - - - -Top Level Drawing (Armada general) - - - - - - - - - - - - Dim oAsmDrawingDoc As DrawingDocument oAsmDrawingDocName = ThisDoc.PathAndFileName(False) & ".idw" If(System.IO.File.Exists(oAsmDrawingDocName)) Then oAsmDrawingDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True) oAsmDrawingNameIAM = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -4) & ".iam" 'Encontrar propiedades de IPT Dim oAsmPartNumber As String Dim oAsmDescription As String Dim oAsmComments As String oAsmPartNumber = iProperties.Value(oAsmDoc, "Project", "Project") oAsmDescription = iProperties.Value(oAsmDoc, "Project", "Description") oAsmComments = iProperties.Value(oAsmDoc, "Summary", "Comments") 'define name of exported file oDataMedium.FileName = oFolder & "\" & oAsmPartNumber & " - " & oAsmDescription & " - " & oAsmComments &".pdf" Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium) oAsmDrawingDoc.Close End If MessageBox.Show("Nuevos archivos creados en: " & vbLf & oFolder, "iLogic") Shell("explorer.exe " & oFolder,vbNormalFocus) End Sub Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium) oPath = ThisDoc.Path PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oOptions.Value("All_Color_AS_Black") = 0 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 1200 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets oOptions.Value("Custom_Begin_Sheet") = 1 oOptions.Value("Custom_End_Sheet") = 1 oDataMedium = ThisApplication.TransientObjects.CreateDataMedium End Sub
Solved! Go to Solution.