Save pdf or dwf to My Documents iLogic

Save pdf or dwf to My Documents iLogic

andrew_canfield
Collaborator Collaborator
776 Views
2 Replies
Message 1 of 3

Save pdf or dwf to My Documents iLogic

andrew_canfield
Collaborator
Collaborator

This is the code I've been using (borrowing):

SyntaxEditor Code Snippet

'------start of iLogic-------'oPath = ThisDoc.Path  C:\Dwf
oPath = "C:\Dwf"
oFileName = ThisDoc.FileName(False) 'without extension'oRevNum = iProperties.Value("Project", "Revision Number")
oPartNum = iProperties.Value("Project", "Part 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
'get PDF target folder path
oFolder = Left(oPath, InStrRev(oPath, "\")) & "Dwf"
'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
iName = iProperties.Value("Project", "Part Number")
MessageBox.Show( oPath, iName)
'Set the dwf target file name
oDataMedium.FileName = oFolder & "\" & iName &  ".dwf"
'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'------end of iLogic-------

 

 

It works - it was for pdf but changing the extension to .dwf works too.

 

Changing the top line from:

 

oPath = "C:\Dwf"

to:

 

oPath = "%userprofile%\documents\Dwf"

 doesn't work.

 

I'd like the save destination to be here:

MyDocs.JPG

 

 

The user's can't save to the C\: drive just to their profile.

The plan is to run the code as an external rule across the network.

Multiple users being able to save as locally.

 

Thanks

 

Andrew

 

 

 

0 Likes
Accepted solutions (1)
777 Views
2 Replies
Replies (2)
Message 2 of 3

ekinsb
Alumni
Alumni
Accepted solution

The library folders are really just aliases to real folders.  For example on my machine the "My Documents" folder resolves to "C:\Users\ekinsb\Documents". You can use the .NET library to get the real folder for the "My Documents" alias.  The code below is an example.  Because iLogic is based on .NET you have access to these libraries.

 

Dim docFolder As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3

andrew_canfield
Collaborator
Collaborator

Fabulous 🙂

top two lines are now:

 

SyntaxEditor Code Snippet

Dim docFolder As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments

oPath =docFolder & "\Dwf"

 

 

Many Thanks 

0 Likes