Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 516

Disable BOMs of a 3D-model in a DWF

$
0
0

By Xiaodong Liang

Question:

I'm writing a small tool for Inventor 2012 in VB.net, using the TranslatorAddIn, to export a drawing and its 3D-model to DWF. Unfortunately, when I export the drawing of an assembly, the BOM of the model is included as well, wich I would like to disable. The options "BOM_Structured" and "BOM_Parts_Only" seem to work only if I export the 3D-model, not the drawing...

Solution:

There is not such option for the DWF translator currently. The workaround is to disable the top assembly’s BOMs temporarily before exporting the drawing to DWF in this case. The following is a VBA demo. It disables the BOM view of all assemblies in the drawing before exporting to DWF, and restore after exporting.

 

Public Sub PublishDWFWithoutBOM()
    ' 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
   
    'disables the BOM view of all assemblies in the drawing before exporting to DWF
    Dim oEachRefDoc As Document
    For Each oEachRefDoc In oDocument.ReferencedDocuments
        If TypeOf oEachRefDoc Is AssemblyDocument Then
            Dim oAssDoc As AssemblyDocument
            Set oAssDoc = oEachRefDoc
           
            Dim oBOM As BOM
            Set oBOM = oAssDoc.ComponentDefinition.BOM
           
            oBOM.StructuredViewEnabled = False
            oBOM.StructuredViewFirstLevelOnly = False
            oBOM.PartsOnlyViewEnabled = False
           
            oAssDoc.Save
           
        End If
       
    Next   

    oDocument.Update   
   

    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

     
        If TypeOf oDocument Is DrawingDocument Then

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

            ' 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
        End If

    End If

    'Set the destination file name
    oDataMedium.FileName = "c:\temp\temptest.dwf"

    'Publish document.
    Call DWFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
   
    'restore after exporting
     For Each oEachRefDoc In oDocument.ReferencedDocuments
        If TypeOf oEachRefDoc Is AssemblyDocument Then
            Set oAssDoc = oEachRefDoc

             
            Set oBOM = oAssDoc.ComponentDefinition.BOM
           
            oBOM.StructuredViewEnabled = True
            oBOM.StructuredViewFirstLevelOnly = True
            oBOM.PartsOnlyViewEnabled = True
           
             oAssDoc.Save
           
        End If
       
    Next
   
End Sub


Viewing all articles
Browse latest Browse all 516

Trending Articles