ilogic create folder not working

ilogic create folder not working

andrew_canfield
Collaborator Collaborator
2,199 Views
8 Replies
Message 1 of 9

ilogic create folder not working

andrew_canfield
Collaborator
Collaborator

 

Hello 

 

I've copied some code to create pdf's but the folder isn't being created.

(I've changed the path).

Copied out the folder code (as below)  - ideally i'd like all users to be able to output to their desktop areas.

 

No error messages are returned  - wondering what's happening?

 

 

oFolder = "%USERPROFILE%\Desktop\PDF"

If Not System.IO.Directory.Exists(oFolder) Then 
    System.IO.Directory.CreateDirectory(oFolder)
End If

create folder.JPG 

 

Regards

 

Andrew

0 Likes
Accepted solutions (1)
2,200 Views
8 Replies
Replies (8)
Message 2 of 9

JhoelForshav
Mentor
Mentor

Hi @andrew_canfield 

Does this work for you?

 

Dim oFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\PDF"
If Not System.IO.Directory.Exists(oFolder) Then 
    System.IO.Directory.CreateDirectory(oFolder)
End If
Message 3 of 9

andrew_canfield
Collaborator
Collaborator

Thankyou - the code works.

However when I transfer it back to the main body (original copied from

https://forums.autodesk.com/t5/inventor-customization/ilogic-auto-save-pdf/td-p/7427556:

)

 

inventor environment.JPG

 

my Frankenstein :

(top 5 lines commented out to save with defer updates on & then produce a pdf)

 

'Dim oDoc As Document'
'oDoc = ThisApplication.ActiveDocument'
''oValue = oDoc.DrawingSettings.DeferUpdates ()'
'
'oDoc.DrawingSettings.DeferUpdates = "True"'
'
'ThisDoc.Save

Dim oFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\PDF"
If Not System.IO.Directory.Exists(oFolder) Then 
    System.IO.Directory.CreateDirectory(oFolder)
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(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 = "%USERPROFILE%\Desktop\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) 
'------end of iLogic-------

 

0 Likes
Message 4 of 9

JhoelForshav
Mentor
Mentor

Try changing "Environment" to System.Environment 🙂

It's interpreted now as Inventor.Environment so you need to clearify

 

Dim oFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) & "\PDF"
If Not System.IO.Directory.Exists(oFolder) Then 
    System.IO.Directory.CreateDirectory(oFolder)
End If
0 Likes
Message 5 of 9

andrew_canfield
Collaborator
Collaborator

just tried a manual save as pdf & see this (I started this thread thinking it would be fairly straight forward!) - apologies.

 

manual.JPG

0 Likes
Message 6 of 9

JhoelForshav
Mentor
Mentor
Accepted solution

That error message seems to be about some missing font?

 

What happens if you run the code like this?

 

'Dim oDoc As Document'
'oDoc = ThisApplication.ActiveDocument'
''oValue = oDoc.DrawingSettings.DeferUpdates ()'
'
'oDoc.DrawingSettings.DeferUpdates = "True"'
'
'ThisDoc.Save

Dim oFolder As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) & "\PDF"
If Not System.IO.Directory.Exists(oFolder) Then 
    System.IO.Directory.CreateDirectory(oFolder)
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(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 


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


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

andrew_canfield
Collaborator
Collaborator

Thanks

0 Likes
Message 8 of 9

andrew_canfield
Collaborator
Collaborator

but...when i run the code again

 

save2.JPG

0 Likes
Message 9 of 9

andrew_canfield
Collaborator
Collaborator

working ok on a different drawing - will test some more.

 

thanks again

0 Likes