Beyond Inventor Wizard... The Community!

Autodesk Inventor en AutoCAD Forum

Via Excel een BOM- list maken.

Macro Excel

Public Sub importinventorbom()

    Dim oApp As Inventor.Application

    Set oApp = GetObject(, "Inventor.Application")

   

    Dim odoc As Inventor.AssemblyDocument

    Dim oBOM As Inventor.BOM

   'Create a FileDialog object as a File Picker dialog box.

    Dim fd As FileDialog

    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    'Declare a variable to contain the path

    'of each selected item. Even though the path is aString,

    'the variable must be a Variant because For Each...Next

    'routines only work with Variants and Objects.

    Dim vrtSelectedItem As Variant

    'Use a With...End With block to reference the FileDialog object.

    With fd

   

    .AllowMultiSelect = False

    .Filters.Add "Inventor Assembly", "*.iam"

    .FilterIndex = 2

    .Title = "Select Inventor Assembly"

   

        'Use the Show method to display the File Picker dialog box and return the user's action.

        'The user pressed the button.

       

        If .Show = -1 Then

            'Step through each string in the FileDialogSelectedItems collection.

            For Each vrtSelectedItem In .SelectedItems

                'vrtSelectedItem is aString that contains the path of each selected item.

                'You can use any file I/O functions that you want to work with this path.

                'This example displays the path in a message box.

                Set odoc = oApp.Documents.Open(vrtSelectedItem, False)

                

                Set oBOM = odoc.ComponentDefinition.BOM

               

                ' Set whether first level only or all levels.

                Firstlevelonly = False

                If Firstlevelonly Then

                oBOM.StructuredViewFirstLevelOnly = True

                Else

                oBOM.StructuredViewFirstLevelOnly = False

                End If

               

                ' Make sure that the structured view is enabled.

                oBOM.StructuredViewEnabled = True

   

                'Set a reference to the "Structured" BOMView

                Dim oBOMView As BOMView

                Set oBOMView = oBOM.BOMViews.Item("Structured")

                Call QueryBOMRowProperties(oBOMView.BOMRows)

            Next vrtSelectedItem

        'The user pressed Cancel.

        Else

        End If

    End With

    'Set the object variable to Nothing.

    Set fd = Nothing

   

    Set bomrow = Nothing

    Set oBOM = Nothing

    Set odoc = Nothing

   Set oApp = Nothing

   

End Sub

Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator)

    'Iterate through the contents of the BOM Rows.

    Dim i As Long

    For i = 1 To oBOMRows.Count

        ' Get the current row.

        Dim oRow As bomrow

        Set oRow = oBOMRows.Item(i)

        'Set a reference to the primary ComponentDefinition of the row

        Dim oCompDef As ComponentDefinition

        Set oCompDef = oRow.ComponentDefinitions.Item(1)

        If TypeOf oCompDef Is VirtualComponentDefinition Then

            'Get the file property that contains the "Part Number"

            'The file property is obtained from the virtual component definition

            ActiveCell.Value = oCompDef.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value

            ActiveCell.Offset(RowOffset:=0, ColumnOffset:=1).Activate

 

           

            'Get the file property that contains the "Description"

            ActiveCell.Value = oCompDef.PropertySets.Item("Design Tracking Properties").Item("Description").Value

            ActiveCell.Offset(RowOffset:=0, ColumnOffset:=1).Activate

            'Get the quantity

            ActiveCell.Value = oRow.ItemQuantity

            ActiveCell.Offset(RowOffset:=1, ColumnOffset:=-2).Activate

        Else

            'Get the file property that contains the "Part Number"

            'The file property is obtained from the virtual component definition

            ActiveCell.Value = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value

            ActiveCell.Offset(RowOffset:=0, ColumnOffset:=1).Activate

           

            'Get the file property that contains the "Description"

            ActiveCell.Value = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Description").Value

            ActiveCell.Offset(RowOffset:=0, ColumnOffset:=1).Activate

            'Get the quantity

            ActiveCell.Value = oRow.ItemQuantity

            ActiveCell.Offset(RowOffset:=1, ColumnOffset:=-2).Activate

           

            'Recursively iterate child rows if present.

            If Not oRow.ChildRows Is Nothing Then

                Call QueryBOMRowProperties(oRow.ChildRows)

            End If

        End If

    Next

End Sub

Bron: http://microconceptstechnical.blogspot.be/2010/11/use-excel-to-extr...

Aantal maal bekeken: 453

Hierop reageren

Interessante links

Word Fan!

Inventor Wizard Cartoons

Video's

  • Video's toevoegen
  • Alles weergeven

© 2019   Gemaakt door Stefaan Boel.   Verzorgd door

Banners  |  Een probleem rapporteren?  |  Algemene voorwaarden