Hi,
I already posted in the Discussion Groups VAULT, but this place is perhaps better for my problem.
I want to create a .pdf according to a rule who is :
IF “iProperty Design State" = “Released” then ".idw is exported to .pdf in "C:/...
Thanks,
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Please see the code lines below -
If iProperties.Value("Status", "Design State")=3 Then ThisDoc.Document.SaveAs(ThisDoc.FileName(False)& ".pdf", True) End If
'3 is "releaased" for design status, 2 is "pending" and 1 is "WorkInProgress"
' When using this code lines, the PDF file will be generated in the same location with IDW.
Thank you very much. It's good now.
I found this code, and I wish to use also, but It's not working. A tips ?
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_As_Black") = True End If
My rule
strFolder = "C:\...\" & ThisDoc.FileName(False) If iProperties.Value("Status", "Design State")=3 Then ThisDoc.Document.SaveAs(strFolder & (".pdf") , True) If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 1
Thanks,
Hi amartin.r,
Here's a quick example that checks the Design State and then writes out a PDF if it's set to Released:
If iProperties.Value("Status", "Design State") <> 3 Then MessageBox.Show("File is NOT Released, so no PDF was created.", "iLogic") Return 'exit rule Else GoTo PDFOUT End If '- - - - - write PDF - - - - - PDFOUT: oPath = ThisDoc.Path oFileName = ThisDoc.FileName(False) 'without extension oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _ ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oDocument = ThisApplication.ActiveDocument oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oDataMedium = ThisApplication.TransientObjects.CreateDataMedium If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 1 End If 'get PDF target folder path 'example: C:\Temp\1234.idw oFolder = oPath & "\PDF" 'returns C:\Temp\PDF\1234.pdf 'Check for the PDF folder and create it if it does not exist If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & oFileName & ".pdf" MessageBox.Show("File Saved to: " & oDataMedium.FileName, "iLogic") 'Publish document oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
Here's another example that looks to see if the Design State is not set to Released and then then gives the user a chance to release it:
If iProperties.Value("Status", "Design State") <> 3 Then
oQuestion = MessageBox.Show("This file is not released." _
& vblf & "Do you want to release it and create a PDF?", _
"iLogic",MessageBoxButtons.YesNo)
If oQuestion = vbNo then
Return 'exit rule
Else
iProperties.Value("Status", "Design State") = 3
GoTo PDFOUT
End If
Else
GoTo PDFOUT
End If
'- - - - - write PDF - - - - -
PDFOUT:
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
End If
'get PDF target folder path
'example: C:\Temp\1234.idw
oFolder = oPath & "\PDF" 'returns C:\Temp\PDF\1234.pdf
'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & ".pdf"
MessageBox.Show("File Saved to: " & oDataMedium.FileName, "iLogic")
'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
For existing files I created a macro button, and I do changes for to get document's name.
But following Windows configuration (show extension or not), the filename is "xxxx.idw.pdf" or "xxxx.pdf"
I tried to replace "DisplayName" by "FullFileName" but this doesn't work.
Sub PublishPDF() 'Get the PDF translator Add-In. Dim PDFAddin As TranslatorAddIn Set PDFAddin = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") 'Set a reference to the active document (the document to be published). Dim oDocument As Document Set oDocument = ThisApplication.ActiveDocument Dim oContext As TranslationContext Set oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = kFileBrowseIOMechanism 'Create a NameValueMap object. Dim oOptions As NameValueMap Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap 'Create a DataMedium object. Dim oDataMedium As DataMedium Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium 'Check whether the translator has 'SaveCopyAs' options. If PDFAddin.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then If TypeOf oDocument Is DrawingDocument Then oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Sheet_Range") = kPrintAllSheets oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Vector_Resolution") = 400 End If End If 'Set filename as original document filename. Dim FileName As String FileName = oDocument.DisplayName 'Set the destination to save files. oDataMedium.FileName = "C:\...\" & FileName & ".pdf" 'Publish document. Call PDFAddin.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) End Sub
The value of document.displayname is related to the settings in folder options -> Hidden extension for known file type. If you turn this option on, the value should work fine. Please see the attached image too.
But when turning this option off, we need to add one code line in red backgroud to handle the file name -
Dim FileName As String
FileName = oDocument.DisplayName
FileName=Left(FileName, Len(FileName)-4)
Please add the code lines below and have a try -
Dim FileName As String
FileName = oDocument.FullFileName
Dim Temp() As String
Temp = Split(FileName, "\")
FileName = Left(Temp(UBound(Temp)), Len(Temp(UBound(Temp))) - 4)
These are used to handle the string to get the expected file name.