iLogic to create custom iProperty in sub-component
I found this code to create a custom iProperty in the current, open document:
Dim propertyName As String = "MyProperty" Dim propertyValue as String = "Test Value" customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties") Try prop = customPropertySet.Item(propertyName) Catch ' Assume error means not found customPropertySet.Add("", propertyName) End Try iProperties.Value("Custom", propertyName) = propertyValue
I have a iLogic rule that goes through each component of an assembly, counts how many times it occurs in the assembly, and then assigns that value to an iProparty (i.e. it inserts the total quantity of the part in some iProperty). Currently, however, it assigns the value to a default iProperty value, "Authority". I'd like, instead, for it to assign it to a custom iProperty called "Total QTY". However, I don't know how to tell Inventor to do the above code for a component in the assembly rather than the assembly itself. Below is my entire code. I've labeled where I'm guessing the above code should go. Could someone tell me how I'd modify the above code to create the iProperty in the component being processed by the rule at that point? Thanks for any help!
Current code:
''True comment: Begin '' 'Commented-out code: Begin ' ''PartDocumentObject = 12290 ''AssemblyDocumentObject = 12291 Dim openDoc As Document openDoc = ThisDoc.Document Dim docFile As Document If openDoc.DocumentType = 12291 Then ''If the open document is an assembly: ''For each document referenced in this document: For Each docFile In openDoc.AllReferencedDocuments Dim FNamePos As Long FNamePos = InStrRev(docFile.FullFileName, "\", -1) Dim docFName As String docFName = Mid(docFile.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos) If docFile.IsModifiable = True Then 'If the document is not read only: Dim assemblyDoc As AssemblyDocument assemblyDoc = openDoc Dim assemblyDef As AssemblyComponentDefinition assemblyDef = assemblyDoc.ComponentDefinition Dim partDoc As PartDocument partDoc = ThisApplication.Documents.Open(docFile.FullFileName, False) Dim partQty As ComponentOccurrencesEnumerator partQty = assemblyDef.Occurrences.AllReferencedOccurrences(partDoc) 'MessageBox.Show(partQty.Count, "") If IsNumeric(partQty.Count) = True Then 'CREATE CUSTOM VARIABLE "Total QTY" HERE If CDblAny(partQty.Count) <> CDblAny(iProperties.Value(docFName, "Custom", "Total QTY")) Then iProperties.Value(docFName, "Custom", "Total QTY") = partQty.Count partDoc.Close Else partDoc.Close End If End If End If Next Else ''If the open document is not an assembly: MessageBox.Show("You must have a valid Assembly document open before using this code.", "File Type Mismatch",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End If