Inventor API: Publish DWF with Options

Inventor API: Publish DWF with Options

ThomasRambach
Advisor Advisor
2,083 Views
15 Replies
Message 1 of 16

Inventor API: Publish DWF with Options

ThomasRambach
Advisor
Advisor

I'm having some trouble with the attached VBA script to publish a DWF. I'm trying to publish all sheets if it's a drawing but also include the 3DModel from the 1st sheet and do not include the structured BOM. I can't get the combination of those options to work correctly.

 

Public Sub PublishDWF(fFilename As String)
    ' 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") = 0

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

        If TypeOf oDocument Is DrawingDocument Then

            ' Drawing options
            oOptions.Value("Publish_Mode") = kCustomDWFPublish
            'oOptions.Value("Publish_All_Sheets") = 1

            ' The specified sheets will be ignored if
            ' the option "Publish_All_Sheets" is True (1)
            Dim oSheets As NameValueMap
            Set oSheets = ThisApplication.TransientObjects.CreateNameValueMap

            ' Publish the first sheet AND its 3D model
            Dim oSheet1Options As NameValueMap
            Set oSheet1Options = ThisApplication.TransientObjects.CreateNameValueMap

            oSheet1Options.Add "Name", "Sheet:1"
            oSheet1Options.Add "3DModel", True
            oSheets.Value("Sheet1") = oSheet1Options
        
            'Set the sheet options object in the oOptions NameValueMap
            oOptions.Value("Sheets") = oSheets
        End If

    End If

    'Set the destination file name
    oDataMedium.FileName = fFilename + ".dwf"

    'Publish document.
    Call DWFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub
0 Likes
2,084 Views
15 Replies
Replies (15)
Message 2 of 16

clutsa
Collaborator
Collaborator

Took me some time but I think I got it. One line was undoing your changes.

Public Sub PublishDWF(fFilename As String)
    ' 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") = 0

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

        If TypeOf oDocument Is DrawingDocument Then

            ' Drawing options
            oOptions.Value("Publish_Mode") = kCustomDWFPublish
            oOptions.Value("Publish_All_Sheets") = 1 'uncommented this

            ' The specified sheets will be ignored if
            ' the option "Publish_All_Sheets" is True (1)
            Dim oSheets As NameValueMap
            Set oSheets = ThisApplication.TransientObjects.CreateNameValueMap

            ' Publish the first sheet AND its 3D model
            Dim oSheet1Options As NameValueMap
            Set oSheet1Options = ThisApplication.TransientObjects.CreateNameValueMap

            oSheet1Options.Add "Name", "Sheet:1"
            oSheet1Options.Add "3DModel", True
            oSheets.Value("Sheet1") = oSheet1Options
        
            'Set the sheet options object in the oOptions NameValueMap
            'oOptions.Value("Sheets") = oSheets '<----This line was overwriting the changes.
        End If

    End If

    'Set the destination file name
    oDataMedium.FileName = fFilename + ".dwf"

    'Publish document.
    Call DWFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 16

ThomasRambach
Advisor
Advisor

@clutsa I'm still trying to figure out how that works. I commented it out but now it's not adding the model in the DWF. I basically want it to output all sheets, the 1st sheets model and an option for the BOM but not the structured BOM.

0 Likes
Message 4 of 16

clutsa
Collaborator
Collaborator

I'll look at this more on Monday but it would appear that something isn't working... I can get it to work properly after I manually export a dwf through the GUI. I use almost identical code and it's been working fine for years but now I wonder if it's just been using the last used GUI settings this whole time. 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 5 of 16

ThomasRambach
Advisor
Advisor

@clutsa Yeah, it's strange. It's like it's ignoring something. I can't get a predicable result from what seems like a predictable change in the code.

0 Likes
Message 6 of 16

ThomasRambach
Advisor
Advisor

@clutsa I think the example in the help file is out of date according to the API. This line works:

 

oOptions.Value("Publish_3D_Models") = True

 

But I still can't get these two options to work:

 

oOptions.Value("BOM_Parts_Only") = False
oOptions.Value("BOM_Structured") = False

 

0 Likes
Message 7 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@ThomasRambach,

 

Good to know that you have found a workaround. Could you please click on "ACCEPT SOLUTION" button which is helpful to solve?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 16

ThomasRambach
Advisor
Advisor

@chandra.shekar.g Not quite a completely working word-around yet.

0 Likes
Message 9 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@ThomasRambach,

 

Below options are supported for Assembly/presentation document.

oOptions.Value("BOM_Parts_Only") = False
oOptions.Value("BOM_Structured") = False

DWF.png

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 10 of 16

clutsa
Collaborator
Collaborator

The BOM data comes from the assy. 

I seem to have this working...

Public Sub PublishDWF(fFilename As String)
    ' 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 DrawingDocument
    Set oDocument = ThisApplication.ActiveDocument
    
    Dim oModelDocument As Document
    Set oModelDocument = oDocument.ReferencedDocuments.Item(1) '<---this may need to change?
    PartsOnly = oModelDocument.ComponentDefinition.BOM.PartsOnlyViewEnabled
    Structured = oModelDocument.ComponentDefinition.BOM.StructuredViewEnabled
    oModelDocument.ComponentDefinition.BOM.PartsOnlyViewEnabled = False
    oModelDocument.ComponentDefinition.BOM.StructuredViewEnabled = False
    

    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = IOMechanismEnum.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") = 0

        ' Other options...
        oOptions.Value("Publish_All_Component_Props") = True
        oOptions.Value("Publish_All_Physical_Props") = True
        oOptions.Value("BOM_Structured") = True
        oOptions.Value("BOM_Parts_Only") = True
        

        If TypeOf oDocument Is DrawingDocument Then

            ' Drawing options
            oOptions.Value("Publish_Mode") = DWFPublishModeEnum.kCustomDWFPublish
            oOptions.Value("Publish_All_Sheets") = False
            oOptions.Value("Publish_3D_Models") = True
            oOptions.Value("Include_Sheet_Tables") = False

            ' The specified sheets will be ignored if
            ' the option "Publish_All_Sheets" is True (1)
            Dim oSheets As NameValueMap
            Set oSheets = ThisApplication.TransientObjects.CreateNameValueMap
            
            For sheetNum = 1 To oDocument.Sheets.Count
                Dim oSheetOptions As NameValueMap
                Set oSheetOptions = ThisApplication.TransientObjects.CreateNameValueMap
                Call oSheetOptions.Add("Name", oDocument.Sheets(sheetNum).Name)
                If sheetNum = 1 Then
                    Call oSheetOptions.Add("3DModel", True)
                Else
                    Call oSheetOptions.Add("3DModel", False)
                End If
                oSheets.Value("Sheet" & sheetNum) = oSheetOptions
            Next
            
            
        
            'Set the sheet options object in the oOptions NameValueMap
            oOptions.Value("Sheets") = oSheets '<----This line was overwriting the changes.
        End If

    End If

    'Set the destination file name
    oDataMedium.FileName = fFilename + ".dwf"

    'Publish document.
    Call DWFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
    oModelDocument.ComponentDefinition.BOM.PartsOnlyViewEnabled = PartsOnly 'reset
    oModelDocument.ComponentDefinition.BOM.StructuredViewEnabled = Structured 'reset
End Sub
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 11 of 16

clutsa
Collaborator
Collaborator

@ThomasRambach Did you ever get this working for you?

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 12 of 16

bradeneuropeArthur
Mentor
Mentor

@chandra.shekar.g

 

Could you please tell us where the list is documented.

 

https://forums.autodesk.com/t5/inventor-customization/inventor-api-publish-dwf-with-options/td-p/825...

 

Regards,

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 13 of 16

ThomasRambach
Advisor
Advisor

@clutsa Not yet, I need to try your workaround still.

0 Likes
Message 14 of 16

clutsa
Collaborator
Collaborator

@bradeneuropeArthur enter "translator options" in the search help & commands

 

should lead you to ...

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-25D24E28-7517-4903-8AEE-123F8C71A89E

or whatever version you are on.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Message 15 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@bradeneuropeArthur,

 

@clutsa is located exactly at help documentation for list of "translator options".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 16 of 16

ChristiPedersen
Advocate
Advocate

I have been using what is listed here to loop through each sheet and write it out but it always writes out the first sheet.  I can see that my loop is working correctly but it never sets the next sheet, always writes out the first.  I have condensed this for easier reading with declarations not shown.  Any input is greatly appreciated.  I tried clearing osheets and osheetoptions between each one but that failed.  Still outputs sheet 1 everytime.

 

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

If DWFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("Launch_Viewer") = False
oOptions.Value("Publish_All_Component_Props") = False
oOptions.Value("Publish_All_Physical_Props") = False
oOptions.Value("BOM_Structured") = False
oOptions.Value("Publish_Mode") = kCustomDWFPublish
oOptions.Value("Publish_All_Sheets") = False
oOptions.Value("BOM_Structured") = False
oOptions.Value("BOM_Parts_Only") = False
oOptions.Value("Include_Sheet_Tables") = False
oOptions.Value("3DModel") = False

For ThisSHT = 1 To DrawDoc.Sheets.Count
On Error Resume Next
oSheets.Clear
oSheetOptions.Clear
Set oSheets = ThisApplication.TransientObjects.CreateNameValueMap
Set oSheetOptions = ThisApplication.TransientObjects.CreateNameValueMap
Call oSheetOptions.Add("Name", oDocument.Sheets(ThisSHT).Name)
oSheets.Value("Sheet" & ThisSHT) = oSheetOptions
oOptions.Value("Sheets") = oSheets
oDataMedium.FileName = frmPublishDWFDWG.txt2DDWFXSeparate & "\" & SheetNames(ThisSHT) & ".dwfx"
Call DWFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
Next
End If

0 Likes