Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create a complete list of all available Content Centre parts

25 REPLIES 25
SOLVED
Reply
Message 1 of 26
Anonymous
3554 Views, 25 Replies

Create a complete list of all available Content Centre parts

Hi there

We would like to be able to access all of filenames from the available Content Centre parts, Excel or the likes.

The reason being we have many duplicate parts in our outdated Access database and Vault. I'd love to be able to tidy this up by pointing the duplicates to the Content Centre part i.e. "do not use, use ********* from Content Centre".

If anybody could help me I'd be most appreciative.

 

Thanks

25 REPLIES 25
Message 2 of 26
Jef_E
in reply to: Anonymous

So if I understand correct, you want to have a list of each part thats in the content center? Not a list for each content center family?



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 3 of 26
Anonymous
in reply to: Jef_E

Yes that is correct.

I'd like to be able to access the filename and part number properties and have them appear in a list, preferably under the categories/families in which they are contained.

Is this possible?

Message 4 of 26
Jef_E
in reply to: Anonymous

I would say yes, but I can't seem to find a way to loop all families in the content center?



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 5 of 26
Anonymous
in reply to: Jef_E

Really appreciate you having a look at this for me though.

I've introduced the Content Centre to the company but I've been forced to work in conjunction with the unadministered system they have ran here for years.

This would be a massive help to me.

Message 6 of 26
Jef_E
in reply to: Anonymous

You know that the list will be LONG, and I mean really LONG, I'm exporting mine as a test for the code but ugghhh it takes long 😄

 

But I guess it works, I will let you know.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 7 of 26
Anonymous
in reply to: Jef_E

I'll be doing it only for my library so, although it will be big, it'll not be for the entire Content Centre big.

Message 8 of 26
Jef_E
in reply to: Anonymous

Then you will need to disable the undesired content center files in your project file.

 

Do you know how-to make a standalone .exe? Then I can just give you the code and you can implement it, or do you want me to make a exe and send it to you? 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 9 of 26
Anonymous
in reply to: Jef_E

Above me I'm afraid but if you could send me one that would be absolutely excellent, thanks.

Really good of you.

By the way I only have the desired library available in my project file so no worries there.

Message 10 of 26
Anonymous
in reply to: Anonymous

Can anyone help on this one please?

Message 11 of 26
Jef_E
in reply to: Anonymous

Here is the code I used, did not have time to make a plugin .exe for it..

 

 Private Families As List(Of Family)
    Private Sub ContentCheck_Click(sender As Object, e As EventArgs) Handles ContentCheck.Click

        Dim oContentCenter As ContentCenter
        oContentCenter = oInvApp.ContentCenter

        Families = New List(Of Family)
        ReadContentCenter(oContentCenter.TreeViewTopNode)
        ListToExcel()
    End Sub

    Private Class FamilyMember

        Public Property FileName
        Public Property PartNumber
        Public Property AXCode

    End Class

    Private Class Family

        Public Property Name
        Public Property Members As List(Of FamilyMember)

        Public Sub New()
            Members = New List(Of FamilyMember)
        End Sub

    End Class

    Private Sub ReadContentCenter(ByVal Node As ContentTreeViewNode)

        For Each oNode As ContentTreeViewNode In Node.ChildNodes
            Debug.Print(oNode.DisplayName)

            ' Check if there are families
            If oNode.Families.Count > 0 Then
                ' Loop all the families in the node
                For Each oFamily As ContentFamily In oNode.Families
                    Debug.Print(oFamily.DisplayName)

                    Dim Family As New Family
                    Family.Name = oFamily.DisplayName

                    Dim oColumnNumber(2) As Integer
                    oColumnNumber = GetColumnNumbers(oFamily)

                    ' Loop all the family member
                    For Each oMember As ContentTableRow In oFamily.TableRows

                        Dim FamilyMember As New FamilyMember
                        Try
                            Debug.Print(oMember.GetCellValue(oColumnNumber(0)))
                            FamilyMember.FileName = oMember.GetCellValue(oColumnNumber(0))
                        Catch ex As Exception
                            FamilyMember.FileName = "#N/A"
                        End Try

                        Try
                            FamilyMember.PartNumber = oMember.GetCellValue(oColumnNumber(1))
                        Catch ex As Exception
                            FamilyMember.PartNumber = "#N/A"
                        End Try

                        Try
                            FamilyMember.AXCode = oMember.GetCellValue(oColumnNumber(2))
                        Catch ex As Exception
                            FamilyMember.AXCode = "#N/A"
                        End Try


                        Family.Members.Add(FamilyMember)

                    Next

                    Families.Add(Family)

                Next
            End If

            ' Check if there are more child nodes
            If oNode.ChildNodes.Count > 0 Then
                ' Recursivly search for more nodes
                ReadContentCenter(oNode)
            End If

        Next

    End Sub

    Private Function GetColumnNumbers(ByVal oFamily As ContentFamily) As Integer()

        Dim oColumnNumbers(2) As Integer
        Dim oFlag(2) As Boolean
        oFlag(0) = False
        oFlag(1) = False
        oFlag(2) = False

        ' Loop all columns
        For i As Integer = 1 To oFamily.TableColumns.Count

            If oFamily.TableColumns.Item(i).InternalName = "FILENAME" Then
                oColumnNumbers(0) = i
                oFlag(0) = True
            ElseIf oFamily.TableColumns.Item(i).InternalName = "PARTNUMBER" Then
                oColumnNumbers(1) = i
                oFlag(1) = True
            ElseIf oFamily.TableColumns.Item(i).InternalName = "AX_CODE" Then
                oColumnNumbers(2) = i
                oFlag(2) = True
            End If

            If oFlag(0) And oFlag(1) And oFlag(2) Then
                Exit For
            End If

        Next

        GetColumnNumbers = oColumnNumbers
    End Function

    Private Sub ListToExcel()

        ' Set reference to the currently active excel application
        Dim oExcel As Microsoft.Office.Interop.Excel.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application")

        ' Set reference to the currently active excel workbook ( 1 workbook open ?? )
        Dim oWorkbook As Workbook
        oWorkbook = oExcel.Workbooks.Item(1)

        ' Set reference to the correct worksheet
        Dim oSheet As Worksheet
        oSheet = oWorkbook.Sheets.Item(1)

        ' Row count
        Dim oCount As Integer = 2

        For Each Family In Families

            For Each FamilyMember In Family.Members

                oSheet.Range("A" & oCount).Value = Family.Name
                oSheet.Range("B" & oCount).Value = FamilyMember.FileName
                oSheet.Range("C" & oCount).Value = FamilyMember.PartNumber
                oSheet.Range("D" & oCount).Value = FamilyMember.AXCode

                ' Add to the count
                oCount += 1

            Next



        Next


    End Sub


Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 12 of 26
Anonymous
in reply to: Jef_E

I'd like to resurrect this one if I may please.

How would I run this code? plugin .exe's are well over my head I'm afraid.

Could anyone help me with getting this one to run please? It is becoming increasingly important for me to be able to access all part numbers from content centre in a complete list.

Message 13 of 26
MechMachineMan
in reply to: Anonymous

Run this in a rule.

 

Private Sub Main()

		Dim oInvApp As Inventor.Application = ThisApplication
		
        Dim oContentCenter As ContentCenter
        oContentCenter = oInvApp.ContentCenter

        Families = New List(Of Family)
        ReadContentCenter (oContentCenter.TreeViewTopNode)
        ListToExcel()
    End Sub

	Private Families As List(Of Family)

    Private Class FamilyMember
        Public Property FileName
        Public Property PartNumber
        Public Property Description
    End Class

    Private Class Family
        Public Property Name
		
        Public Property Members As List(Of FamilyMember)

        Public Sub New()
            Members = New List(Of FamilyMember)
        End Sub
    End Class

    Private Sub ReadContentCenter(ByVal Node As ContentTreeViewNode)
        For Each oNode As ContentTreeViewNode In Node.ChildNodes
            If oNode.Families.Count > 0 Then
                For Each oFamily As ContentFamily In oNode.Families
                    Dim Family As New Family
                    Family.Name = oFamily.DisplayName

                    Dim oColumnNumber(2) As Integer
                    oColumnNumber = GetColumnNumbers(oFamily)

                    For Each oMember As ContentTableRow In oFamily.TableRows
                        Dim FamilyMember As New FamilyMember
                        Try
                            FamilyMember.FileName = oMember.GetCellValue(oColumnNumber(0))
                        Catch ex As Exception
                            FamilyMember.FileName = "#N/A"
                        End Try

                        Try
                            FamilyMember.PartNumber = oMember.GetCellValue(oColumnNumber(1))
                        Catch ex As Exception
                            FamilyMember.PartNumber = "#N/A"
                        End Try

                        Try
                            FamilyMember.Description = oMember.GetCellValue(oColumnNumber(2))
                        Catch ex As Exception
                            FamilyMember.Description = "#N/A"
                        End Try

                        Family.Members.Add (FamilyMember)

                    Next

                    Families.Add (Family)

                Next
            End If

            If oNode.ChildNodes.Count > 0 Then
                ReadContentCenter (oNode)
            End If

        Next

    End Sub

    Private Function GetColumnNumbers(ByVal oFamily As ContentFamily) As Integer()

        Dim oColumnNumbers(2) As Integer
        Dim oFlag(2) As Boolean
        oFlag(0) = False
        oFlag(1) = False
        oFlag(2) = False

        For i As Integer = 1 To oFamily.TableColumns.Count
            If oFamily.TableColumns.Item(i).InternalName = "FILENAME" Then
                oColumnNumbers(0) = i
                oFlag(0) = True
            ElseIf oFamily.TableColumns.Item(i).InternalName = "PARTNUMBER" Then
                oColumnNumbers(1) = i
                oFlag(1) = True
            ElseIf oFamily.TableColumns.Item(i).InternalName = "DESCRIPTION" Then
                oColumnNumbers(2) = i
                oFlag(2) = True
            End If
            If oFlag(0) And oFlag(1) And oFlag(2) Then
                Exit For
            End If
        Next

        GetColumnNumbers = oColumnNumbers
    End Function

    Private Sub ListToExcel()

        Dim oExcel As Object = CreateObject("Excel.Application")
		oExcel.Visible = True

        Dim oWorkbook As Object
        oWorkbook = oExcel.Workbooks.Add()

        Dim oSheet As Object
        oSheet = oWorkbook.Sheets.Item(1)

        Dim oCount As Integer = 2
	
        For Each Family In Families
            For Each FamilyMember In Family.Members
                oSheet.Range("A" & oCount).Value = Family.Name
                oSheet.Range("B" & oCount).Value = FamilyMember.FileName
                oSheet.Range("C" & oCount).Value = FamilyMember.PartNumber
                oSheet.Range("D" & oCount).Value = FamilyMember.Description

                oCount = oCount + 1
            Next
        Next
		
		oExcel = Nothing
    End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 14 of 26
Anonymous
in reply to: MechMachineMan

I can't thank you both enough for taking the time to help, this is exactly what I need.

 

Thank you very much.

 

Message 15 of 26
Jef_E
in reply to: Anonymous

@MechMachineMan thanks for finishing the code so @Anonymous can use it. I am just swamped here and don't have time to write it adjust it..



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 16 of 26
b.ziegler
in reply to: MechMachineMan

Hello,

I have a similar issue as the original poster.  I would like to make an excel spread sheet with the following columns:

Family name (not really that important but it would be nice)

Part number

description

 

I ran the code presented above and it worked very well except for the descriptions when came up #N/A which from looking at the code means that there was an exception on this line.

 

I could also export the display name on the parts as well, as that is linked to the description.  Could someone guide me to where I need to change things in the code to make that happen?

 

I have included screen shots of the description column and the designation column.

 
Message 17 of 26


@MechMachineMan wrote:

Run this in a rule.

 

Private Sub Main()

		Dim oInvApp As Inventor.Application = ThisApplication
		
        Dim oContentCenter As ContentCenter
        oContentCenter = oInvApp.ContentCenter

        Families = New List(Of Family)
        ReadContentCenter (oContentCenter.TreeViewTopNode)
        ListToExcel()
    End Sub

	Private Families As List(Of Family)

    Private Class FamilyMember
        Public Property FileName
        Public Property PartNumber
        Public Property Description
    End Class

    Private Class Family
        Public Property Name
		
        Public Property Members As List(Of FamilyMember)

        Public Sub New()
            Members = New List(Of FamilyMember)
        End Sub
    End Class

    Private Sub ReadContentCenter(ByVal Node As ContentTreeViewNode)
        For Each oNode As ContentTreeViewNode In Node.ChildNodes
            If oNode.Families.Count > 0 Then
                For Each oFamily As ContentFamily In oNode.Families
                    Dim Family As New Family
                    Family.Name = oFamily.DisplayName

                    Dim oColumnNumber(2) As Integer
                    oColumnNumber = GetColumnNumbers(oFamily)

                    For Each oMember As ContentTableRow In oFamily.TableRows
                        Dim FamilyMember As New FamilyMember
                        Try
                            FamilyMember.FileName = oMember.GetCellValue(oColumnNumber(0))
                        Catch ex As Exception
                            FamilyMember.FileName = "#N/A"
                        End Try

                        Try
                            FamilyMember.PartNumber = oMember.GetCellValue(oColumnNumber(1))
                        Catch ex As Exception
                            FamilyMember.PartNumber = "#N/A"
                        End Try

                        Try
                            FamilyMember.Description = oMember.GetCellValue(oColumnNumber(2))
                        Catch ex As Exception
                            FamilyMember.Description = "#N/A"
                        End Try

                        Family.Members.Add (FamilyMember)

                    Next

                    Families.Add (Family)

                Next
            End If

            If oNode.ChildNodes.Count > 0 Then
                ReadContentCenter (oNode)
            End If

        Next

    End Sub

    Private Function GetColumnNumbers(ByVal oFamily As ContentFamily) As Integer()

        Dim oColumnNumbers(2) As Integer
        Dim oFlag(2) As Boolean
        oFlag(0) = False
        oFlag(1) = False
        oFlag(2) = False

        For i As Integer = 1 To oFamily.TableColumns.Count
            If oFamily.TableColumns.Item(i).InternalName = "FILENAME" Then
                oColumnNumbers(0) = i
                oFlag(0) = True
            ElseIf oFamily.TableColumns.Item(i).InternalName = "PARTNUMBER" Then
                oColumnNumbers(1) = i
                oFlag(1) = True
            ElseIf oFamily.TableColumns.Item(i).InternalName = "DESCRIPTION" Then
                oColumnNumbers(2) = i
                oFlag(2) = True
            End If
            If oFlag(0) And oFlag(1) And oFlag(2) Then
                Exit For
            End If
        Next

        GetColumnNumbers = oColumnNumbers
    End Function

    Private Sub ListToExcel()

        Dim oExcel As Object = CreateObject("Excel.Application")
		oExcel.Visible = True

        Dim oWorkbook As Object
        oWorkbook = oExcel.Workbooks.Add()

        Dim oSheet As Object
        oSheet = oWorkbook.Sheets.Item(1)

        Dim oCount As Integer = 2
	
        For Each Family In Families
            For Each FamilyMember In Family.Members
                oSheet.Range("A" & oCount).Value = Family.Name
                oSheet.Range("B" & oCount).Value = FamilyMember.FileName
                oSheet.Range("C" & oCount).Value = FamilyMember.PartNumber
                oSheet.Range("D" & oCount).Value = FamilyMember.Description

                oCount = oCount + 1
            Next
        Next
		
		oExcel = Nothing
    End Sub

Could anyone help my if I want to adapt the code to include custom column like "PTN_ARTNR" and "PTN_SIZE", they are 2 custom iproperties that exists in all CC parts. It would save us a lot of work. Many Thanks, Johan

Inventor 20250, Vault Professional 2025, Autocad Plant 3D 2024
Message 18 of 26
Rich-T
in reply to: Anonymous

I've tried this code but it stops after listing fasteners family in our library with the error message "Exception from HRESULT: 0x800AC472".

The fastener count is about 16.5k could that be the problem ?

Any idea why it stops so soon ?

 

We need to capture data from the structural shapes & tube and pipe families too.

Any advice would be greatly appreciated.

 

Message 19 of 26
A.Acheson
in reply to: johan.degreef

@johan.degreef 

 

Here is the output. The trick here is to follow the pattern laid out by the previous columns. Pay special attention to  numbers  as they will be your index in for loops.  I would suggest to create a new project with a custom library and with one family  to test your output. Otherwise you could get too much data and not the outcome you want. Alternatively place an if statement to search for a specific family name bypassing other families. 

 

AAcheson_1-1657718820149.png

Here is the modified code

Private Sub Main()

		Dim oInvApp As Inventor.Application = ThisApplication
		
        Dim oContentCenter As ContentCenter
        oContentCenter = oInvApp.ContentCenter

        Families = New List(Of Family)
        ReadContentCenter (oContentCenter.TreeViewTopNode)
        ListToExcel()
    End Sub

	Private Families As List(Of Family)

    Private Class FamilyMember
        Public Property FileName
        Public Property PartNumber
        Public Property Description
		Public Property PTN_ARTNR
		Public Property PTN_SIZE
    End Class

    Private Class Family
        Public Property Name
		
        Public Property Members As List(Of FamilyMember)

        Public Sub New()
            Members = New List(Of FamilyMember)
        End Sub
    End Class

    Private Sub ReadContentCenter(ByVal Node As ContentTreeViewNode)
        For Each oNode As ContentTreeViewNode In Node.ChildNodes
            If oNode.Families.Count > 0 Then
                For Each oFamily As ContentFamily In oNode.Families
                    Dim Family As New Family
                    Family.Name = oFamily.DisplayName
                    Dim oColumnNumber(4) As Integer
                    oColumnNumber = GetColumnNumbers(oFamily)

                    For Each oMember As ContentTableRow In oFamily.TableRows
                        Dim FamilyMember As New FamilyMember
                        Try
                            FamilyMember.FileName = oMember.GetCellValue(oColumnNumber(0))
                        Catch ex As Exception
                            FamilyMember.FileName = "#N/A"
                        End Try

                        Try
                            FamilyMember.PartNumber = oMember.GetCellValue(oColumnNumber(1))
                        Catch ex As Exception
                            FamilyMember.PartNumber = "#N/A"
                        End Try

                        Try
                            FamilyMember.Description = oMember.GetCellValue(oColumnNumber(2))
                        Catch ex As Exception
                            FamilyMember.Description = "#N/A"
                        End Try
						
						Try
                            FamilyMember.PTN_ARTNR = oMember.GetCellValue(oColumnNumber(3))
                        Catch ex As Exception
                            FamilyMember.PTN_ARTNR = "#N/A"
                        End Try
						
						Try
                            FamilyMember.PTN_SIZE = oMember.GetCellValue(oColumnNumber(4))
                        Catch ex As Exception
                            FamilyMember.PTN_SIZE = "#N/A"
                        End Try

                        Family.Members.Add (FamilyMember)
					
                    Next

                    Families.Add(Family)
	
                Next
            End If

            If oNode.ChildNodes.Count > 0 Then
                ReadContentCenter (oNode)
            End If

        Next

    End Sub

    Private Function GetColumnNumbers(ByVal oFamily As ContentFamily) As Integer()

        Dim oColumnNumbers(4) As Integer
        Dim oFlag(4) As Boolean
        oFlag(0) = False
        oFlag(1) = False
        oFlag(2) = False
		oFlag(3) = False
		oFlag(4) = False

        For i As Integer = 1 To oFamily.TableColumns.Count
            If oFamily.TableColumns.Item(i).InternalName = "FILENAME" Then
                oColumnNumbers(0) = i
                oFlag(0) = True
            ElseIf oFamily.TableColumns.Item(i).InternalName = "PARTNUMBER" Then
                oColumnNumbers(1) = i
                oFlag(1) = True
            ElseIf oFamily.TableColumns.Item(i).InternalName = "DESCRIPTION" Then
                oColumnNumbers(2) = i
                oFlag(2) = True
			ElseIf oFamily.TableColumns.Item(i).InternalName = "PTN_ARTNR" Then
                oColumnNumbers(3) = i
                oFlag(3) = True	
			ElseIf oFamily.TableColumns.Item(i).InternalName = "PTN_SIZE" Then
                oColumnNumbers(4) = i
                oFlag(4) = True
            End If
            If oFlag(0) And oFlag(1) And oFlag(2) And oFlag(3) And oFlag(4) Then
                Exit For
            End If
        Next

        GetColumnNumbers = oColumnNumbers
    End Function

    Private Sub ListToExcel()

        Dim oExcel As Object = CreateObject("Excel.Application")
		oExcel.Visible = True

        Dim oWorkbook As Object
        oWorkbook = oExcel.Workbooks.Add()

        Dim oSheet As Object
        oSheet = oWorkbook.Sheets.Item(1)
		oSheet.Range("A1").Value = "Family Name"
        oSheet.Range("B1").Value = "FileName"
        oSheet.Range("C1").Value = "PartNumber"
        oSheet.Range("D1").Value = "Description"
		oSheet.Range("E1").Value = "PTN_ARTNR"
		oSheet.Range("F1").Value = "PTN_SIZE"
        Dim oCount As Integer = 2
	
        For Each Family In Families
            For Each FamilyMember In Family.Members
                oSheet.Range("A" & oCount).Value = Family.Name
                oSheet.Range("B" & oCount).Value = FamilyMember.FileName
                oSheet.Range("C" & oCount).Value = FamilyMember.PartNumber
                oSheet.Range("D" & oCount).Value = FamilyMember.Description
				oSheet.Range("E" & oCount).Value = FamilyMember.PTN_ARTNR
				oSheet.Range("F" & oCount).Value = FamilyMember.PTN_SIZE

                oCount = oCount + 1
            Next
        Next
		
		oExcel = Nothing
    End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 20 of 26
Rich-T
in reply to: A.Acheson

Thanks AA,

That works pretty well for me - but i got my terminology wrong.

I want to be able to loop through all the content centre categories too. Is that even possible ? 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report