Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
j.romo
195 Views, 1 Reply

API VB.net Counting Parts in assembly

Hello Guys Im passing a old Ilogic rule to VB.net, the rule was courtesy of Mega Jerk.

The code is to Run in Assembly and count instaces of the same part and punt the instaces number in a parameter

to have the total count of parts in the drawing.

But Im running into an error, and havent figured out how to solve it.

 

any help would be appreciated

Here is The code

Public Class DATOS_FRM


    Private _inventor As Inventor.Application
    Public InventorApp As Inventor.Application = Marshal.GetActiveObject("Inventor.Application")
    Public assemblyDoc As AssemblyDocument = InventorApp.ActiveDocument

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim ThisApplication As Inventor.Application = Marshal.GetActiveObject("Inventor.Application")
        Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument


        Dim openDoc As Document
        Dim FNamePos As Long
        Dim docFName As String
        Dim assemblyDef As AssemblyComponentDefinition
        Dim partQty As ComponentOccurrencesEnumerator
        Dim docFile As PartDocument


        If oAsmDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
            Exit Sub
        Else

            'MsgBox("You must have a valid Assembly document open before using this code!", "File Type Mismatch!")
        End If

        For Each docFile In oAsmDoc.AllReferencedDocuments


                FNamePos = InStrRev(docFile.FullFileName, "\", -1)

                docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)

                If docFile.IsModifiable = True Then

                    oAsmDoc = openDoc
                    assemblyDef = oAsmDoc.ComponentDefinition
                    partQty = assemblyDef.Occurrences.AllReferencedOccurrences(docFile)

                    Try
                        If partQty.Count <> assemblyDef.iProperties.Value(docFName, "Project", "Authority") Then
                            assemblyDef.iProperties.Value(docFName, "Project", "Authority") = partQty.Count

                        End If
                    Catch
                        assemblyDef.iProperties.Value(docFName, "Project", "Authority") = partQty.Count
                    End Try
                End If
            Next

    End Sub
End Class

jromo_0-1670040314836.png