Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Save PDF using iLogic and name after revision number?

47 REPLIES 47
SOLVED
Reply
Message 1 of 48
GustavStigsohn
14848 Views, 47 Replies

Save PDF using iLogic and name after revision number?

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

 

47 REPLIES 47
Message 41 of 48
FProcp
in reply to: FProcp

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
in reply to: FProcp

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
Message 43 of 48

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

Message 44 of 48
FProcp
in reply to: Edward_Lowe

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
in reply to: FProcp

Thanks for the quick reply,

Regards,

Edward

Message 46 of 48
jostroopers
in reply to: jostroopers

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.....
Message 47 of 48
gunermustafa
in reply to: danvang

Hi, 

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

Thanks in advance

Message 48 of 48
gunermustafa
in reply to: gunermustafa

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")	

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report