Inventor will not update PDF Rev.Number on save and export

Inventor will not update PDF Rev.Number on save and export

maskintegning_dk
Contributor Contributor
796 Views
7 Replies
Message 1 of 8

Inventor will not update PDF Rev.Number on save and export

maskintegning_dk
Contributor
Contributor
Hello.
Help me please. When I save .idw I have an iLogic rule which exports to PDF.
The problem is that in the browser, it overwrites the already saved PDF and does not update the Rev.Number.
So it keeps saving as Rev.F.
It should have been Rev.G

I have the rule from Inventor 2020, where it works without problems.
I'm using Inventor 2024 now.
I'm not very strong in iLogic. I am attaching iLogic rule.


 

'------start of iLogic-------

oPath = ThisDoc.Path

oFileName = iProperties.Value("Custom", "sags nr.")

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

 

 

'Define the drawing

Dim oDrawing As DrawingDocument

oDrawing = ThisDoc.Document

 

 

Dim oSheet As Sheet

Dim lPos As Long

Dim rPos As Long

Dim sLen As Long

Dim sSheetName As String

Dim iSheetNumber As Integer

 

 

'step through each drawing sheet

For Each oSheet In oDrawing.Sheets

 

 

'find the seperator in the sheet name:number

lPos = InStr(oSheet.Name, ":")

'find the number of characters in the sheet name

sLen = Len(oSheet.Name)

'find the sheet name

sSheetName = Left(oSheet.Name, lPos -1)

'find the sheet number

iSheetNumber = Right(oSheet.Name, sLen -lPos)

 

 

'set PDF Options

'If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then

oOptions.Value("All_Color_AS_Black") = 1

oOptions.Value("Remove_Line_Weights") = 0

oOptions.Value("Vector_Resolution") = 4800

oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange

oOptions.Value("Custom_Begin_Sheet") = iSheetNumber

oOptions.Value("Custom_End_Sheet") = iSheetNumber

'End If

 

 

'get PDF target folder path

oFolder = Left(oPath, InStrRev(oPath, "\")) & "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

 

‘Get title From model iProperties

oRefDoc = ThisDrawing.ModelDocument

Dim oModelTitle As String

oModelTitle = oRefDoc.PropertySets("Summary Information").Item("Title").Value

 

 

'Set the PDF target file name

oDataMedium.FileName = oFolder & "\" & oFileName &"-"& iProperties.Value("Custom", "pos. nr.") &"   "& "Rev" &"."& oRevNum & "-" & "Sheet." & iSheetNumber & “   “ & oModelTitle & ".pdf"

 

 

'Publish document

oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

 

 

Next

'------end of iLogic-------

 

 

 

 

0 Likes
Accepted solutions (1)
797 Views
7 Replies
Replies (7)
Message 2 of 8

A.Acheson
Mentor
Mentor

Hi @maskintegning_dk 

It sounds like the drawing wasn't saved after  the rev was changed, could that be the case?

I would suggest to ensure the drawing is saved before you start the export.

After you get the drawing  object save the drawing like this. 

Dim oDrawing As DrawingDocument
oDrawing = ThisDoc.Document
oDrawing.Save

Troubleshooting:

After you get the rev number you can check its value with a messagebox

MessageBox.Show(oRevNum)

 At the end of the rule you can check also what the filename is by placing String value into a messagebox

MessageBox.Show(oDataMedium.FileName)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 8

maskintegning_dk
Contributor
Contributor

@A.Acheson 

Hi Alan.

Thank you for replying.

 

I have the rule in the Manage -> Event Triggers "After save".

Inventor saves the .idw correctly before the export to PDF. No problems there.

 

The problem occurs when I run the export rule.

In the Windows browser, the name of the PDF doesn't get updated to Rev.G.

 

So the result is that when I open the PDF, the correct Rev.G is printet

but in the Windows browser the PDF is still named Rev.F.

It should have been Rev.G

 

Yours sincerely, Lars

 

0 Likes
Message 4 of 8

A.Acheson
Mentor
Mentor
Accepted solution

Hi @maskintegning_dk 

 

I wasn't able to get the error your seeing when testing with Inventor 2020. Here is the same rule shorten up a little and objects fully declared.

 

'Define the drawing.
Dim oDrawing As DrawingDocument = ThisDoc.Document

Dim oPath As String = ThisDoc.Path

Dim oFileName As String = iProperties.Value("Custom", "sags nr.")

Dim oPosName As String = iProperties.Value("Custom", "pos. nr.")

Dim oRevNum As String= iProperties.Value("Project", "Revision Number")
 
Dim oPDFAddIn As ApplicationAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext

oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap

Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium

'Step through each drawing sheet.
For Each oSheet As Sheet In oDrawing.Sheets

	'Find the seperator in the sheet name:number.
	Dim lPos As Long = InStr(oSheet.Name, ":")

	'Find the number of characters in the sheet name.
	Dim sLen As Long = Len(oSheet.Name)

	'Find the sheet name.
	Dim sSheetName As String = Left(oSheet.Name, lPos -1)

	'Find the sheet number.
	Dim iSheetNumber As Integer = Right(oSheet.Name, sLen -lPos)

	'Set PDF Options.
	If oPDFAddIn.HasSaveCopyAsOptions(oDrawing,oContext, oOptions) Then

		oOptions.Value("All_Color_AS_Black") = 1

		oOptions.Value("Remove_Line_Weights") = 0

		oOptions.Value("Vector_Resolution") = 4800

		oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange

		oOptions.Value("Custom_Begin_Sheet") = iSheetNumber

		oOptions.Value("Custom_End_Sheet") = iSheetNumber

	End If

	'Get PDF target folder path.
	Dim oFolder As String = Left(oPath, InStrRev(oPath, "\")) & "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

	'Get title From model iProperties.
	Dim oRefDoc As Document = ThisDrawing.ModelDocument

	Dim oModelTitle As String = oRefDoc.PropertySets("Summary Information").Item("Title").Value

	'Set the PDF target file name
	oDataMedium.FileName = oFolder & "\" & oFileName & "-" & oPosName &"   "& "Rev."  & oRevNum & "-Sheet." & iSheetNumber & "   " & oModelTitle & ".pdf"

	'Publish document
	oPDFAddIn.SaveCopyAs(oDrawing, oContext, oOptions, oDataMedium)

Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 8

maskintegning_dk
Contributor
Contributor

@A.Acheson 

 

Hi Alan.
Thank you for your effort. Much obliged.

 

I copied your code in to Inventor, but it keeps on overwriting the same file.
I'm thinking that it's a Windows setup problem now.

 

Thank you again.
Kind regards, Lars

0 Likes
Message 6 of 8

maskintegning_dk
Contributor
Contributor

@A.Acheson 
Hi Alan.

Did you try the rule in Inventor 2024?

It seems like Inventor locks the very first name to the .idw when saving to PDF

 

Kind regards, Lars

0 Likes
Message 7 of 8

A.Acheson
Mentor
Mentor

I do not use 2024 so cannot test. 

 

Maybe you can disable the pdf export and focus only on the filename output. Is it what you expect? 

'Set the PDF target file name
	oDataMedium.FileName = oFolder & "\" & oFileName & "-" & oPosName &"   "& "Rev."  & oRevNum & "-Sheet." & iSheetNumber & "   " & oModelTitle & ".pdf"

    Logger.Info(oDataMedium.FileName)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 8 of 8

maskintegning_dk
Contributor
Contributor

@A.Acheson 

Hi Alan.

 

Sorry no. It didn't work.

I replaced the old line with yours in pdf-rule.

Inventor is still overwriting the old pdf.

 

I wonder why the rule works in Inventor 2020 and not 2024.

Mayby Autodesk have done some new coding in 2024?

 

Kind regards

Lars

0 Likes