- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
A few things I see.
This is incorrect, this is an API object mixed with an ilogic function for iproperties. You will need to stick with the API versions a list is here in this article.
assemblyDef.iProperties.Value(docFName, "Project", "Authority") Doc file is declared as a part Document but when looping through all referenced documents you will come across both assembly documents and part documents.
Dim docFile As PartDocument
So you will need to be more generic at the beginning then use a filter like
If docFile.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
End If
A few more questions:
Where in the drawing do you want the number put? You could try a different approach and extract the part qty either from the partslist object or the BOM Object. Both of which should give you total qty's once you filter by the target part.
If you want to stay with the assembly, are you putting the qty in a parameter of the Main assembly or an iProperty? What is your search criteria for the parts to be counted?
Or if this helped you, please, click (like)
Regards
Alan