Hello Everyone
I have a rule that will export a PDF (for an idw), or a dwf (for an ipt or iam) to a folder in my Fusion 360 desktop connector.
What I would like to be able to do, is access the file just created and copy the share link to my clipboard.
Any ideas how I could accomplish the attached?
It is only a couple of mouse clicks manually, I am hoping I can convert this to code somehow.
Solved! Go to Solution.
Solved by william. Go to Solution.
Ok, I have managed to do most of it.
See below example for publishing a PDF to Fusion Teams from Inventor and then opening the link online. So you can then set the shared link options.
Step One: Publish Rule, export from idw to F360 drive project and folder.
Make sure you have a txt file called "F360_Filepath.txt" saved in "C:\Scripts\"
'Rev 0 - 201029 - WI - Initial issue 'Check it is an .idw (see value for kDrawingDocumentObject in the API reference) If ThisApplication.ActiveDocumentType <> 12292 Then MessageBox.Show("This is not a drawing. This rule can only be run in an .idw environment" & vbNewLine & "The rule will exit...", "Error Handling",MessageBoxButtons.OK,MessageBoxIcon.Error) Return End If ' Check that this file has been saved and actually exists on disk If String.IsNullOrEmpty(ThisDoc.Path) Then MessageBox.Show("This file has not yet been saved and doesn't exist on disk!" & vbLf & "Please save it first","Error Handling",MessageBoxButtons.OK,MessageBoxIcon.Error) Return End If Dim strUserProfile As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile) 'MessageBox.Show(strUserProfile, "strUserProfile") ExportPath = strUserProfile & "\Fusion\HARROWS\CAD OUTPUT\" 'MessageBox.Show(ExportPath, "ExportPath") 'Check that a save directory was found If Not Directory.Exists(ExportPath) Then MessageBox.Show("There was an error finding the folder save location" & vbNewLine & "The rule will exit...", "Error Handling", MessageBoxButtons.OK, MessageBoxIcon.Error) End If Try drawingmodel = ThisDrawing.ModelDocument 'MessageBox.Show(drawingmodel.FullDocumentName, "drawingmodel") oFileName = drawingmodel.PropertySets("Design Tracking Properties").Item("Stock Number").Value If oFileName = "" Then MessageBox.Show("There is no value in the stock number." & vbLf & "Please complete the metadata first","Error Handling",MessageBoxButtons.OK,MessageBoxIcon.Error) Return End If ExportFilename = "SAL_" & oFileName & ".pdf" oWrite = System.IO.File.CreateText("C:\Scripts\F360_Filepath.txt") oWrite.WriteLine(ExportFilename) oWrite.Close() Catch MessageBox.Show("There is no model document in the drawing." & vbLf & "Please create a drawing view first","Error Handling",MessageBoxButtons.OK,MessageBoxIcon.Error) Return End Try 'Get the PDF export application 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 'set PDF Options If oPDFAddIn.HasSaveCopyAsOptions(oDocument, 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 End If 'Set the PDF target file name oDataMedium.FileName = ExportPath & ExportFilename MessageBox.Show(oDataMedium.FileName, "Filename") Try 'Publish document oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Catch MessageBox.Show("Error writing out PDF", "Error Handling",MessageBoxButtons.OK,MessageBoxIcon.Error) End Try Q = MessageBox.Show("Do you want to open the link?", "F360 Publish", MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation) If Q = vbYes Then R = MessageBox.Show("Has Autodesk Desktop Connector Finished processing the created file? If not wait until it has before proceeding", "Autodesk Desktop Connector Status", MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation) If R = vbOK Then ThisDoc.Launch(“C:\Scripts\F360_OpenLink.vbs”) End If End If
Step Two: Create a VB script called F360_OpenLink.vbs and save it in the location specified above. This was "C:\Scripts\" in my instance
'Some assumptions are made:
'You have a text file in the C drive with the location of the cad file stored as a string
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim file
Set file = fso.OpenTextFile("C:\Scripts\F360_Filepath.txt",1,-2)
Dim targetfilepath
targetfilepath = file.ReadAll
Call WshShell.Run("explorer.exe /select," & targetfilepath, 1, true)
WScript.Sleep 5000
WshShell.SendKeys "+{F10}"
WshShell.SendKeys "{DOWN}"
WshShell.SendKeys "{DOWN}"
WshShell.SendKeys "{DOWN}"
WshShell.SendKeys "{DOWN}"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 3000
Dim sh,w
myfolder = "C:\Users\william.HARROWS\Fusion\HARROWS\CAD OUTPUT"
Set sh = CreateObject("shell.application")
For Each w In sh.Windows
If w.document.folder.self.Path = myfolder Then w.Quit
Next
This should open the folder, select the file you have just exported, activate the context menu with SHIFT + F10 (Sendkeys), arrow key down to the "View Online" option and ENTER to activate.
The remainder of the code is not always neccessary, but it just closes the opened folder. Our F360 project structure is very simple, and all exported files go to one location, so may need customising depending how yours is set up.
IMO this was simpler than trying to do this with Forge and Javascript programming. It may be of some use to someone else.
Can't find what you're looking for? Ask the community or share your knowledge.