Repair or fix old files (2009 to 2018) to capture iproperties (example: project, revision, description) using ilogic to create batch pdf.

Repair or fix old files (2009 to 2018) to capture iproperties (example: project, revision, description) using ilogic to create batch pdf.

edward.bolanos
Explorer Explorer
630 Views
3 Replies
Message 1 of 4

Repair or fix old files (2009 to 2018) to capture iproperties (example: project, revision, description) using ilogic to create batch pdf.

edward.bolanos
Explorer
Explorer

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!

 

 

pdf.pngpdf1.pngpdf2.pngpdf3.png

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


 

 

0 Likes
Accepted solutions (1)
631 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

The first thing I noticed, while looking through the code you posted, within the first section, was at this line:

oDataMedium.FileName = oFolder & "\" & oFileName & " Description" & oDescription & ".pdf"

I don't see where you created the variable "oDescription", or where you set its value, above that place in the code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 4

edward.bolanos
Explorer
Explorer
Accepted solution

Hi!

 

Thanks for the observation. I was finally able to solve the problem!
I found the error using visual basic.

iProperties.Value(pathName, "Summary", "Comments")

in the comments field I had an "enter" creating two lines and I fixit by removing the "enter" with a space.

 

To create individual pdf, I create an ilogic rule to extract "project", "description" and "comments" from the models to the idw.
This rule also automatically calls the update of the iproperties and calls a visual basic macro to save pdf by invoking iproperties from the idw "project", "description" and "comments"

 

 

Thank you all, and I hope it can be of use to you.

 

This is the rule:

 

'extraer iproperties del modelo iam o ipt (2020-sep-23)

oPath = ThisDoc.Path
	oFolder = "C:\WF MEPAL - CARVAJAL\03 PROYECTOS Y LINEAS\PDF INDIVIDUAL"
	oPath = System.IO.Directory.GetParent(oPath).FullName
	
	
	If System.IO.Directory.Exists(oFolder) = False Then
		System.IO.Directory.CreateDirectory(oFolder)
	End If


oRefDoc = ThisDrawing.ModelDocument
	Dim oPropValue As String
	'On Error Resume Next

oPropValue = oRefDoc.PropertySets("Summary Information").Item("Comments").value
	iProperties.Value("Summary", "Comments") = oPropValue

oPropValue = oRefDoc.PropertySets("Design Tracking Properties").Item("Description").value
	iProperties.Value("Project", "Description") = oPropValue
	
oPropValue = oRefDoc.PropertySets("Design Tracking Properties").Item("Project").value
	iProperties.Value("Project", "Project") = oPropValue	

'Actualiza iProperties del idw 
Dim oControlDef As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("UpdateCopiedModeliPropertiesCmd") 
oControlDef.Execute2(True)	

InventorVb.RunMacro ("Crear_pdf_descripcion_y_comments", "Exportar_pdf_descripcion", "SaveAsPDF" )

MessageBox.Show("Nuevos archivos creados en: " & vbLf & oFolder, "iLogic")
	Shell("explorer.exe " & oFolder,vbNormalFocus)

 

And this is the macro:

 

Public Sub SaveAsPDF()


' Get the active document.
Dim invDoc As Document
Set invDoc = ThisApplication.ActiveDocument

' Get the design tracking property set.
Dim invDesignInfo As PropertySet
Set invDesignInfo = invDoc.PropertySets.Item("Design Tracking Properties")
Set invSummInfo = invDoc.PropertySets.Item("Inventor Summary Information")

' Get the part number property.
'Dim invPartNumberProperty As Property
'Set invPartNumberProperty = invDesignInfo.Item("Part Number")
Dim Project As Property
Set Project = invDesignInfo.Item("Project")
Dim Descripcion As Property
Set Descripcion = invDesignInfo.Item("Description")
Dim Comments As Property
Set Comments = invSummInfo.Item("Comments")


Dim Nombre As String
'Dim parte1 As String

Nombre = Project.Value & " - " & Descripcion.Value & " " & Comments.Value & ".pdf"

 

' Get the PDF translator Add-In.
Dim oPDFTrans As TranslatorAddIn
Set oPDFTrans = ThisApplication.ApplicationAddIns.ItemById( _
"{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
If oPDFTrans Is Nothing Then
MsgBox "Could not access PDF translator."
Exit Sub
End If

' Create some objects that are used to pass information to
'the translator Add-In.
Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
If oPDFTrans.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, _
oContext, oOptions) Then
' Set to print all sheets. This can also have the value
' kPrintCurrentSheet or kPrintSheetRange. If kPrintSheetRange
' is used then you must also use the CustomBeginSheet and
' Custom_End_Sheet to define the sheet range.
oOptions.Value("Sheet_Range") = kPrintAllSheets

' Other possible options...
'oOptions.Value("Custom_Begin_Sheet") = 1
'oOptions.Value("Custom_End_Sheet") = 5
oOptions.Value("All_Color_AS_Black") = False
oOptions.Value("Remove_Line_Weights") = True
oOptions.Value("Vector_Resolution") = 1200

' Define various settings and input to provide the translator.
oContext.Type = kFileBrowseIOMechanism
Dim oData As DataMedium
Set oData = ThisApplication.TransientObjects.CreateDataMedium

oData.FileName = "C:\WF MEPAL - CARVAJAL\03 PROYECTOS Y LINEAS\PDF INDIVIDUAL\" & Nombre

' Call the translator.
Call oPDFTrans.SaveCopyAs(ThisApplication.ActiveDocument, _
oContext, oOptions, oData)
End If
End Sub

 

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Good to hear! 🙂  When I posted originally, I was starting to work on your project and was maybe 1/3 to 1/2 way through it.  Then after going home for the day and coming back to work, I must have either forgot about it, got involved with something else, too busy, or all of the above.  Fortunately there are plenty of resources here on the forum dealing with exporting PDF's, dealing with iProperties, and other related issues.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)