Edit exist iLogic (export to pdf)

Edit exist iLogic (export to pdf)

kresh.bell
Collaborator Collaborator
276 Views
5 Replies
Message 1 of 6

Edit exist iLogic (export to pdf)

kresh.bell
Collaborator
Collaborator

Please, can someone edit the attached iLogic for me?

 

I would like the file name to be:
iProperties.Value("Custom", "DWGRef")& " "& 
iProperties.Value("Custom", "Sufix")& " "&

'iLogic rule to export PDF from Inventor Drawings



'May 5, 2016


Imports System.Windows.Forms

' Query user
'------start of iLogic-------
question = MessageBox.Show("You want to create PDF of this file?", "MJM Tool Box", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

' Set condition based on answer
If question <> vbYes Then Exit Sub

' Get current location of this file
Dim ExportPath As String = ThisDoc.Path

' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ExportPath) Then
	MsgBox("This file has not yet been saved and doesn't exist on disk! - please save it first",64, "PDF EXPORT!")
	Exit Sub
End If

' Define folder browse dialog
Dim Dialog = New FolderBrowserDialog()

' Set options for folder browser dialog
Dialog.SelectedPath = ExportPath
Dialog.ShowNewFolderButton = True
Dialog.Description = "Choose Folder for Export..."

If DialogResult.OK = Dialog.ShowDialog() Then ' Show dialog box
	' User clicked 'ok' on dialog box - capture the export path
	ExportPath = Dialog.SelectedPath & "\"
Else
	Exit Sub ' User clicked 'cancel' on dialog box - exit
End If

Dim SheetRange As String = InputBox("Please enter the range of sheets you want to export." & vbLf & _
"You can use these input types:" & vbLf & "  ' 1 ' ,  ' 1-65 ' ", "Sheet range", "1-65")
If SheetRange = vbNullString Then Exit Sub
Dim SPL As Integer = InStr(SheetRange, "-")
Dim L1 As Integer
Dim L2 As Integer
If SPL > 0 Then
	L1 = Val(Left(SheetRange, SPL))
	L2 = Val(Mid(SheetRange, SPL + 1))
Else
	L1 = Val(SheetRange)
	L2 = Val(SheetRange)
End If

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

' Formate PDF Setting

oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 150
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
' Range of pages for publishing
oOptions.Value("Custom_Begin_Sheet") = L1
oOptions.Value("Custom_End_Sheet") = L2

ExportPath = ExportPath & "\" & ThisDoc.FileName(False)

oDataMedium.FileName = ExportPath & iProperties.Value("Custom", "Sufix")& " "& iProperties.Value("Custom", "Disney04")& " " & iProperties.Value("Custom", "Disney01")& " " & iProperties.Value("Custom", "Disney08")& ".pdf"

Try
	' Publish document
	oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
	'--------------------------------------------------?--------------------------------------------------?----------------
	' Ask the user if he wants to open the file
	question2 = MessageBox.Show("Open PDF file?", "Sinago Tool Box",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
	If question2  = vbYes Then
		ThisDoc.Launch(oDataMedium.FileName)
	End If
Catch
	MessageBox.Show("PDF not created, most likely someone else has it open.", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
End Try

iProperties.Value("Custom", "Disney04")& " " &

iProperties.Value("Custom", "Disney01")& " " &

iProperties. Value("Custom", "Disney08")& ".pdf"


So, instead of attached file name, I would like iProperties.Value("Custom", "DWGRef")

0 Likes
Accepted solutions (1)
277 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Just to clarify...you want to replace the following code on Line 75:

oDataMedium.FileName = ExportPath & iProperties.Value("Custom", "Sufix")& " "& iProperties.Value("Custom", "Disney04")& " " & iProperties.Value("Custom", "Disney01")& " " & iProperties.Value("Custom", "Disney08")& ".pdf"

...with this code?

oDataMedium.FileName = ExportPath & iProperties.Value("Custom", "DWGRef") & ".pdf"

 If not, then please explain the situation a little more clearly, so that we can understand, and provide more accurate suggestions.  I usually do not recommend 'in-line' calls to iProperties, especially when it involves file paths.  It would likely be better to capture the  current value of each of those iProperties to variables on different lines of code, before that line, then make sure they each had a value, and were not empty first.  Then use those variables in the file path.  Just a suggestion though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

kresh.bell
Collaborator
Collaborator

Hi @WCrihfield ,

thanks for your answer.

I'm doing something wrong and I don't understand what. Now the file name is ok for me, using this code:

'iLogic rule to export PDF from Inventor Drawings



'May 5, 2016


Imports System.Windows.Forms

' Query user
'------start of iLogic-------
question = MessageBox.Show("You want to create PDF of this file?", "MJM Tool Box", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

' Set condition based on answer
If question <> vbYes Then Exit Sub

' Get current location of this file
Dim ExportPath As String = ThisDoc.Path

' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ExportPath) Then
	MsgBox("This file has not yet been saved and doesn't exist on disk! - please save it first",64, "PDF EXPORT!")
	Exit Sub
End If

' Define folder browse dialog
Dim Dialog = New FolderBrowserDialog()

' Set options for folder browser dialog
Dialog.SelectedPath = ExportPath
Dialog.ShowNewFolderButton = True
Dialog.Description = "Choose Folder for Export..."

If DialogResult.OK = Dialog.ShowDialog() Then ' Show dialog box
	' User clicked 'ok' on dialog box - capture the export path
	ExportPath = Dialog.SelectedPath & "\"
Else
	Exit Sub ' User clicked 'cancel' on dialog box - exit
End If

Dim SheetRange As String = InputBox("Please enter the range of sheets you want to export." & vbLf & _
"You can use these input types:" & vbLf & "  ' 1 ' ,  ' 1-65 ' ", "Sheet range", "1-65")
If SheetRange = vbNullString Then Exit Sub
Dim SPL As Integer = InStr(SheetRange, "-")
Dim L1 As Integer
Dim L2 As Integer
If SPL > 0 Then
	L1 = Val(Left(SheetRange, SPL))
	L2 = Val(Mid(SheetRange, SPL + 1))
Else
	L1 = Val(SheetRange)
	L2 = Val(SheetRange)
End If

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

' Formate PDF Setting

oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 150
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
' Range of pages for publishing
oOptions.Value("Custom_Begin_Sheet") = L1
oOptions.Value("Custom_End_Sheet") = L2

ExportPath = ExportPath & "\" & ThisDoc.FileName(False)

oDataMedium.FileName =  iProperties.Value("Custom", "DWGRef") & iProperties.Value("Custom", "Sufix")& " "& iProperties.Value("Custom", "Disney04")& " " & iProperties.Value("Custom", "Disney01")& " " & iProperties.Value("Custom", "Disney08")& ".pdf"

Try
	' Publish document
	oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
	'--------------------------------------------------?--------------------------------------------------?----------------
	' Ask the user if he wants to open the file
	question2 = MessageBox.Show("Open PDF file?", "Sinago Tool Box",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
	If question2  = vbYes Then
		ThisDoc.Launch(oDataMedium.FileName)
	End If
Catch
	MessageBox.Show("PDF not created, most likely someone else has it open.", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
End Try

 

it generates a pdf but saves it in this location.

C:\Program Files\Autodesk\Inventor 2023\Bin

 

I want it to be in the same location as the drawing file

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

I think I see it.

Line 18 has this:

Dim ExportPath As String = ThisDoc.Path

...then Line 73 has this:

ExportPath = ExportPath & "\" & ThisDoc.FileName(False)

...but then, you are not including that at the start of your Line 75 final file path anymore:

oDataMedium.FileName = ...

I see that you added these two in there at the start of that path:

iProperties.Value("Custom", "DWGRef")

and

iProperties.Value("Custom", "Sufix")

but I do not know what values they contain, so maybe it is using some 'default' root path, and tacking the rest on as the file name...not sure.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

kresh.bell
Collaborator
Collaborator

Hi,

that's the key. I would like to save in that folder, but I only want custom iProperties in the file name. Now the file name is ok, it works but save location is problem

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor
Accepted solution

If you only want custom iProperty values in it, then you may need to eliminate the "& ThisDoc.FileName(False)" portion of what you have on Line 73, because that is including the original file name, just after the base file path.  Does that original file name, or any of those custom iProperty values contain any "\" characters or "." (dot or period) characters.  If so, those may get confused for directory separator characters or confuse what the file extension should be?  Just guessing at this point.   

 

Edit:  Also, if the original document has not been saved yet, then it will not be getting any 'path' or 'file name' from it, so that portion of the final file path/name will be missing.  Oops, I guess you are already checking that.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)