Save DWF of Active Document in Specified File Location

Save DWF of Active Document in Specified File Location

eric.frissell26WKQ
Advocate Advocate
1,234 Views
7 Replies
Message 1 of 8

Save DWF of Active Document in Specified File Location

eric.frissell26WKQ
Advocate
Advocate

Pretty simple, I'm writing a macro to save a DWF of an active document in a specific folder for our ECR/ECN process.  Every macro seems really long and has additional functionality built into it.  I AM HOPING that is why they are as long as they are because this should be a lot easier than it seems like it is.  Currently I am going to down 2 paths but returning a file path as a string is clearly triggering Inventor.  Trying to use the strFileName it tells me an object is needed, if I comment it out and use the ExportDocName it tells me object variable or with block variable not set.  What is the proper variable for returning a file path?  Asking because it seems to work fine as a string in the second one.

 

Secondly I feel like I went down this path and found out it only exports the active page, will that be the case with this code?  What's the preferred method for getting all the pages and none of the 3d files?  Print manager vs DWF add in?  Is it possible to do without the DWF add in?  This kind of seems really difficult for exporting something that should be considered a native format...

 

 

Public Sub AutoSave()
' Get the filename minus the extension.
Dim strFilename As String
Dim dwfDirectory As String
Dim ExportDocName As String
Dim ExportDoc As DrawingDocument

dwfDirectory = "C:\Users\ MY DESKTOP "
strFilename = ActiveDoc.fullFilename
ExportDocName = ExportDoc.fullFilename
strFilename = Left(strFilename, Len(strFilename) - 4)
' Save the current SilentOperation and then turn it on.
' This will suppress the dwf viewer from being displayed.
Dim currentSetting As Boolean
currentSetting = ThisApplication.SilentOperation
ThisApplication.SilentOperation = True

' Save the file as dwf.
'Call ThisDocument.SaveAs(dwfDirectory & strFilename & ".dwf", True)

' Reset SilentOperation back to its previous value.
ThisApplication.SilentOperation = currentSetting

Debug.Print "Full save name is " & dwfDirectory & strFilename & ".dwf"

End Sub

 

Working macro

 

Public Sub ExportDWF()

Dim ExportDoc As DrawingDocument
Dim ExportDocName As String
Set ExportDoc = ThisApplication.ActiveDocument

ExportDocName = ExportDoc.fullFilename

Debug.Print "File name is " & ExportDocName


End Sub

0 Likes
1,235 Views
7 Replies
Replies (7)
Message 2 of 8

eric.frissell26WKQ
Advocate
Advocate

I gave into the DWF translator option.  I do not understand why this has to be as difficult as it is... However, new problems have come up.  I am attempting to get this to publish a DWF with no 3D file, into a directory on my desktop.  Currently it publishes the DWF to the viewer with a 3D file and is not saving the file to my desktop.  Any input is appreciated.

 

Public Sub ExportDWF()

Dim ExportDoc As DrawingDocument
Dim ExportFilePath As String
Dim DocumentNamePath As String
Dim DocumentName As String

Set ExportDoc = ThisApplication.ActiveDocument

ExportDocName = ExportDoc.fullFilename
DocumentNamePath = Right(ExportDocName, Len(ExportDocName) - InStrRev(ExportDocName, "\"))
DocumentName = Left(DocumentNamePath, Len(DocumentNamePath) - 4)

Debug.Print "File name is " & DocumentName


' Get the DWF translator Add-In.
Dim DWFAddIn As TranslatorAddIn
Set DWFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}")

'Set a reference to the active document (the document to be published).
Dim oDocument As Document
Set oDocument = ThisApplication.ActiveDocument

Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism

' Create a NameValueMap object
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Create a DataMedium object
Dim oDataMedium As DataMedium
Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

' Check whether the translator has 'SaveCopyAs' options
If DWFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

oOptions.Value("Launch_Viewer") = 1

' Other options...
'oOptions.Value("Publish_All_Component_Props") = 1
'oOptions.Value("Publish_All_Physical_Props") = 1
'oOptions.Value("Password") = 0

If TypeOf oDocument Is DrawingDocument Then

' Drawing options
'oOptions.Value("Pulish_Mode") = kCompleteDWFPublish
oOptions.Value("Publish_Mode") = kCustomDWFPublish
oOptions.Value("Publish_All_Sheets") = 1
oOptions.Value("Publish_3D_Models") = 0



End If

End If

'Set the destination file name
oDataMedium.filename = "A FOLDER ON MY DESKTOP" & DocumentName & ".dwf"

'Publish document.
Call DWFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

0 Likes
Message 3 of 8

lah29-bertrand
Advocate
Advocate

try this:

 

'Référence au document courant qui doit etre publié
Dim oDocument As Document
oDocument = ThisApplication.ActiveDocument

Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

DWFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

If DWFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("Launch_Viewer") = launchviewer
oOptions.Value("Publish_All_Component_Props") = 1
oOptions.Value("Publish_All_Physical_Props") = 1
oOptions.Value("Password") = 0
End If

'Définition du nom du DWFx
Dim oDWFx As String
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False)
oFolder = ThisDoc.Path & "\SortieDWFx"
oDWFx = oFolder & "\" & oFileName & "_" & DateTime.Now.ToString("dd-MM-yy") & ".dwfx"
oDataMedium.FileName = oDWFx

'Controle du répertoire "\SortieDWFx"
If Not System.IO.Directory.Exists(oFolder) Then
	System.IO.Directory.CreateDirectory(oFolder)
End If



'Publication du document.
Call DWFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

'ThisDoc.Launch(oDWFx)
Process.Start("explorer.exe", oFolder)
Return
0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

Here are the links to help you out with Exporting DWF's.

Export to DWF API Sample 

Translator Options  (scroll down the page to get to the DWF Export options)

TranslatorAddIn.HasSaveCopyAsOptions Property 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS 💡and Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

bradeneuropeArthur
Mentor
Mentor

Are you using Vault, then you can do that without programming?!

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 6 of 8

eric.frissell26WKQ
Advocate
Advocate

We are using vault but have an automated release system that isn't compatible with files that have been released prior to our implementation of the automated release system.  Being able to run a macro to do this is helpful because the dwf export is time consuming and has certain options by default that need to be changed - i.e. the 3d file and by default it wants to save as a dwfx.  Could it be implemented at the release level since we are being forced to have multiple methods of release?  Possibly but I'm just a peon who isn't allowed to make changes to processes because "it confuses people" so supplementing our processes with additional tools is my preferred route.

0 Likes
Message 7 of 8

eric.frissell26WKQ
Advocate
Advocate

Hey, thanks for the reply, like the code - the implementation of it looks pretty simple.  Question regarding it though.  It looks like the code is trying to save the dwf in the same place as the original part file is found so, since the dwf needs to be in a separate folder, if I define oFolder as the file path, will that cause any issues?  There seems to be a lot of whole new world of information I'm having trouble finding documentation on for the these translators/mediums

0 Likes
Message 8 of 8

lah29-bertrand
Advocate
Advocate

no, you can definite the oFolder as you want

0 Likes