iLogic, Publish PDF error.

iLogic, Publish PDF error.

PumaBH
Contributor Contributor
422 Views
7 Replies
Message 1 of 8

iLogic, Publish PDF error.

PumaBH
Contributor
Contributor

Hello All, 

 

I have an iLogic Rule as shown below that will publish a PDF document of the saved manufacturing drawing. 

When i create manufacturing drawings i have it so the .idw drawing is auto saved as a .pdf as well via the iLogic. 

i do this for all my drawings and on occasions the drawing that was auto saved would sometimes be incorrect.

 

For example the drawing will save as a .pdf under the correct file name but the contents of this file will be something else that was open at the time of the save. often another drawing or part model in a random view orientation. 

 

it is not a regular occurrence and would happen once in every 20 or so drawings. probably when i have more than 10 different file types open in inventor it will confuse itself during operation. 

 

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("project", "revision number")
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(oDocument, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2'oOptions.Value("Custom_End_Sheet") = 4
End If 


'get PDF target folder path
oFolder = ThisDoc.Path & "\pdf" 'instead of "k:\dwg\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" 
'_" rev" & oRevNum & ".pdf" 


'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 
'------end of iLogic-------

Cheers! 

 

0 Likes
423 Views
7 Replies
Replies (7)
Message 2 of 8

WCrihfield
Mentor
Mentor

Hi @PumaBH.  It sounds like it is getting different documents mixed up.  And since this is the case, we have to take a very close look at how we are getting a document for this code to work with.  In your code, you are using the 'ThisDoc' term in several places, but then you are also using the 'ThisApplication.ActiveDocument' term, which could be retrieving a different document object than what the 'ThisDoc' term is pointing to.  So, I would suggest that you replace 'ThisApplication.ActiveDocument' with 'ThisDoc.Document', instead.  That way all of those terms should be pointing to the same document.  The term 'ThisApplication.ActiveDocument' will always capture the document that is currently, visibly showing on your Inventor screen at the moment that code is encountered.  If that code gets ran by events or gets ran remotely, then the wrong document may be showing on your Inventor screen at that time, causing the problem.  The term 'ThisDoc' has pretty dynamic functionality, and works differently in different situations, in an attempt to point to the most relevant document, and is the term I use most within most of my iLogic rules.  It was not always that way though.  I had to learn about this situation myself at one point, then made the change because of it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 8

berry.lejeune
Advocate
Advocate

Hi, 

 

I'm using a code that I activate when I want to make a pdf

The code creates two pdf's. One on a specific location in our network and one in the folder where the IDW is. In that folder a new folder is made "PDF" and the folder will also open automatically after the pdf has been created

 

Here's the code:

On Error Resume Next

'define the folder where you want to save the files
oFolder = "g:\pdf\2024\"

'grab the filename
oFileName = ThisDoc.FileName(False) 'without extension

'create the folder if it doesn't exist
If Not System.IO.Directory.Exists(oFolder) Then 
    System.IO.Directory.CreateDirectory(oFolder)
End If


'save as a pdf
ThisDoc.Document.SaveAs(oFolder & oFileName & - 1 & ".pdf", True)

oPath = ThisDoc.Path
'get STEP target folder path
oFolder = oPath & "\" & oAsmName & " PDF"
'Check for the step folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
ThisDoc.Document.SaveAs(oFolder & "\" & oFileName & " - 1" &(".pdf"), True)

'open the folder where the new files are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)

Message 4 of 8

PumaBH
Contributor
Contributor

Thank you for the help. I've modified the code and will trial it for a few weeks to see if i have any documents being mixed up. 

0 Likes
Message 5 of 8

PumaBH
Contributor
Contributor

Thanks for the code! i will more than likely end up using this as we have a central area for certified drawings on our network. would be useful to have my drawing saved there automatically. 

Message 6 of 8

berry.lejeune
Advocate
Advocate

In the code there are some lines with the word "step" but this doesn't change anything about the use of the code.

I copied this code from the one that also makes steps in a  similar way as the pdf's

0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor

Hi @berry.lejeune.  I see something in your code example above that looks like it might need to be changed, or maybe needs an additional line of code somewhere to support.  The following line of code:

oFolder = oPath & "\" & oAsmName & " PDF"

...contains the variable 'oAsmName', but that variable has not been declared or any value set to it anywhere else in that code.  Should that maybe be replaced with the 'oFileName' variable, or should there be another line of code somewhere that sets its value a certain way?

 

Also, your code example does not allow for any 'options' to be specified about the PDF export process, so the export will most likely just attempt to use options that you used the last time you manually exported a PDF.  Sometimes those options are not super important, but if they are important, or you want more consistent results, you could include a little more code in your rule to use the TranslatorAddIn resource, and its SaveCopyAs method for the exports, to enable being able to specify the options within the rule, similar to @PumaBH 's original example if you wanted.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 8

berry.lejeune
Advocate
Advocate

Hi @WCrihfield 

The code I use is something what I threw together from some existing codes which I found online and here in the forum. I'm pretty much illiterate when it comes to coding 🙂 

The "options" also do not need to change for what I'm using the code, but thanks for the suggestion

0 Likes