I have two sets of code for creating a DWF to a
folder. This one is the current one I use, and it runs off of the
DWFwriter that you can download from the Autodesk webpage. This was built
using some code I was using to do a SaveAs to create the DWF. I'll provide
that code in a following post.
Once the DWFwriter is installed open the
DWFwriter 2 Beta driver and under "Advanced
Properties" -> "DWF
Filename" to select "Don't prompt - use source
filename". Make this choice
and the "Save As" dialog will not appear
any longer.
When DWFwriter 2 Beta is installed, a string value in the
registry is
created with an empty
value:
HKCU\Software\Autodesk\DWFwriter\2\Publish Directory
Change
this value to your desired target directory (with or without a
trailing \)
and your DWF files will land here.
I have also added code that will write text stating
it's a reference document, print the DWF, and then delete the text. We do
this for our standards.
Here's the code, take it a copy it into your IDW
template. Everytime you do a save it will create the DWF to a specified
folder:
Option Explicit
Private obDocument As Document
Public WithEvents DocEvents As
DocumentEvents
Public Sub
AutoSave_Copy_by_Event()
Set DocEvents =
ThisApplication.ActiveDocument.DocumentEvents
End Sub
Public Sub DocEvents_OnSave(ByVal BeforeOrAfter As
EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As
HandlingCodeEnum)
SaveAsType "dwf"
End Sub
Private Sub SaveAsType(szFileType As
String)
ThisApplication.SilentOperation = True
Set obDocument =
ThisApplication.ActiveDocument
If obDocument.DocumentType <> 12292
Then
Exit
Sub
Else
Dim
szFileName As String
Dim
szExtension As String
Dim oPrintMgr As DrawingPrintManager
' Create a new sketch on the active
sheet.
Dim oSketch As DrawingSketch
Set oSketch = obDocument.ActiveSheet.Sketches.Add
'Name the sketch
'oSketch.Name =
"DWF"
' Open the sketch for edit so
the text boxes can be created.
' This is only required for
drawing sketches, not part.
oSketch.Edit
Dim oTG As
TransientGeometry
Set oTG =
ThisApplication.TransientGeometry
'
Create text with simple string as input. Since this doesn't
use
' any text overrides, it will default to the active
text style.
Dim sText As String
Dim
oTextBox As TextBox
sText = "<StyleOverride Bold='True'
FontSize='.4'>REFERENCE ONLY<Br/>NOT A RELEASED
DOCUMENT</StyleOverride>"
Set oTextBox =
oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(1.5, 3),
sText)
' Exit the sketch from the edit
environment.
oSketch.ExitEdit
Set oPrintMgr =
ThisApplication.ActiveDocument.PrintManager
'This is the
name of the DWF printer on my system. Probably should
'Determine this by other means.
'Set the paper size
Dim oDrawDoc As
DrawingDocument
Set oDrawDoc =
ThisApplication.ActiveDocument
Dim
oSheet As Sheet
Dim oSheetSize As
String
Set oSheet = oDrawDoc.ActiveSheet
' Check to see if a filename is
defined.
If oSheet.Size = kADrawingSheetSize
Then
oSheetSize =
kPaperSizeLetter
'"B
Size"
ElseIf oSheet.Size = kBDrawingSheetSize
Then
oSheetSize =
kPaperSize11x17
'"C
Size"
ElseIf oSheet.Size = kCDrawingSheetSize
Then
oSheetSize =
kPaperSizeCustom
'"D
Size"
ElseIf oSheet.Size = kDDrawingSheetSize
Then
oSheetSize =
kPaperSizeCustom
'"Custom Size"
ElseIf oSheet.Size =
kCustomDrawingSheetSize Then
oSheetSize = kPaperSizeCustom
End If
oPrintMgr.Printer = "Autodesk
DWFwriter"
oPrintMgr.NumberOfCopies =
1
oPrintMgr.Orientation =
kLandscapeOrientation
oPrintMgr.ScaleMode =
kPrintBestFitScale
oPrintMgr.PrintRange =
kPrintAllSheets
oPrintMgr.PaperSize = oSheetSize
'get the full file name from obDocument
' szFileName =
obDocument.DisplayName
'Determine the extension of the file
' szExtension = Right(szFileName, 3)
'If the extension is IDW then print a DWF of the file, if not do
nothing
' If szExtension = "idw"
Then
'
szFileName = Left(szFileName, Len(szFileName) - 3) &
szFileType
'szFileName = "I:\Autodesk Inventor\DWF\" &
szFileName
' Call ThisApplication.CommandManager.PostPrivateEvent(kFileNameEvent,
szFileName)
oPrintMgr.SubmitPrint
'End If
End
If
oSketch.Delete
ThisApplication.SilentOperation = False
End
Sub
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">