Save PDF using iLogic and name after revision number?

Save PDF using iLogic and name after revision number?

GustavStigsohn
Enthusiast Enthusiast
17,301 Views
47 Replies
Message 1 of 48

Save PDF using iLogic and name after revision number?

GustavStigsohn
Enthusiast
Enthusiast

Hello!

 

My question: We want to use iLogic to save a PDF-file of the DWG-drawing every time we hit "save". We now use the following iLogic code:

 

Spoiler
oPath = ThisDoc.Path PN = iProperties.Value("Project", "Part Number") PDFAddIn = 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 PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 1 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  'Set the destination file name oDataMedium.FileName = oPath & "\" & PN & ".pdf"  'Publish document PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions,oDataMedium)  'Confirmation message MessageBox.Show("PDF SAVED TO: " & oDataMedium.FileName ,"PDF Saved", MessageBoxButtons.OK)

 

Question 1: Is it possible to save the PDF in a new folder that lies "one step up". For example: My DWG-file is placed in c:/drawings/thing4/DWG, I want the PDF to end up in c:/drawings/thing4/PDF. If I am in folder "c:/drawings/thing2/DWG" I want the PDF to end up in "c:/drawings/thing2/PDF" etc. Possible?

 

Question 2: My DWG files is named "thing4.dwg" and it is the 2nd revision. I want the PDF-file to be named

"thing4 Ed2.pdf". Possible?

 

Any help would be very appreciated!

/Gustav

 

0 Likes
Accepted solutions (2)
17,302 Views
47 Replies
Replies (47)
Message 41 of 48

FProcp
Collaborator
Collaborator

This is how I've done it, the information I want to turn off must be in the Layer "Title (ISO)":

 

SyntaxEditor Code Snippet

'------start of iLogic-------'
' If the drawing is not at Status "Released", the Title Block will NOT print
If iProperties.Value("Status", "Design State") <> 3 Then
  ThisDrawing.Document.StylesManager.Layers("Title (ISO)").Visible= False
Else
 ThisDrawing.Document.StylesManager.Layers("Title (ISO)").Visible= True
End If
'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(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
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 = 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

 'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" Rev" & oRevNum & ".pdf"

'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'ThisDrawing.Document.StylesManager.Layers("Title (ISO)").Visible= True
InventorVb.DocumentUpdate()
'------end of iLogic-------

 

Franco
GMT +08:00
Message 42 of 48

FProcp
Collaborator
Collaborator

This iLogic code doesn't work in Inventor 2018. Smiley Sad

 

Inventor 2018 has PDF export changes "The From and To values specified for Sheets in range are no longer session based"

 

This command confuses it:

 

 

SyntaxEditor Code Snippet

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

 And I get this message:

 

Error0589.JPG

Error in rule: PDF_Export, in document: ?????.idw

Invalid pointer (Exception from HRESULT: 0x80004003 (E_POINTER))

 

How can we fix this?

Franco
GMT +08:00
0 Likes
Message 43 of 48

Edward_Lowe
Enthusiast
Enthusiast

Hi Curtis,

 

I have successfully used your ilogic to create a pdf when closing down dwg files.  A number of my drawings have two sheets or more.  Is there some coding I can include to pdf all sheets as opposed to just the front/selected sheet?

 

Thanks,

 

Edward

0 Likes
Message 44 of 48

FProcp
Collaborator
Collaborator

In Inventor 2018 the following works:

 

SyntaxEditor Code Snippet

'------start of iLogic-------
' If the drawing is not at Status "Released", the Title Block layer will NOT appear on pdf
' Title block must be in that layer for this to work
If iProperties.Value("Status", "Design State") <> 3 Then
  ThisDrawing.Document.StylesManager.Layers("Title (ISO)").Visible= False
Else
 ThisDrawing.Document.StylesManager.Layers("Title (ISO)").Visible= True
End If
'
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

oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
oOptions.Value("Sheet_Range") =
Inventor.PrintRangeEnum.kPrintAllSheets

'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

'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" Rev" & oRevNum & ".pdf"

'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'
ThisDrawing.Document.StylesManager.Layers("Title (ISO)").Visible= True
InventorVb.DocumentUpdate()
'------end of iLogic-------
Franco
GMT +08:00
Message 45 of 48

Edward_Lowe
Enthusiast
Enthusiast

Thanks for the quick reply,

Regards,

Edward

0 Likes
Message 46 of 48

jostroopers
Collaborator
Collaborator

I try the code in Inventor 2019 and its not working.

I get the mesage box and then i get an error:

System.NullReferenceException: Ongeldige aanwijzer (Exception from HRESULT: 0x80004003 (E_POINTER))
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)

Do i have to change the code somewhere to make it work?
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
0 Likes
Message 47 of 48

Anonymous
Not applicable

Hi, 

How can i get stock number or revision number from part or assembly document ?

Thanks in advance

0 Likes
Message 48 of 48

Anonymous
Not applicable

This is the code:

 

	docFile = ThisDoc.ModelDocument
		Dim FNamePos As Long
		FNamePos = InStrRev(docFile.FullFileName, "\", -1)                        
		Dim docFName As String 
		docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 
		'Dim SN As String
		SN = iProperties.Value(docFName, "Project", "Stock Number")	
0 Likes