Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have some code that will:
- look at all occurrences in an assembly
- for each, get the reference file name, and trim down to desired string
- load this string into the iproperty part number
It is supposed to look at the occurrence and, if it is an assembly, run through the previous steps for the suboccurrences. I can't seem to get the rule to change the iproperties in my suboccurrences. Below is my code:
Sub Main 'Gets the Active Document oDoc = ThisDoc.Document 'Saves this document oDoc.Save 'Checks if the active document is an assembly If oDoc.DocumentType = kAssemblyDocumentObject 'Gets the assembly occurrences Dim oOccs As ComponentOccurrences oOccs = oDoc.ComponentDefinition.Occurrences 'Call the subprocedure to traverse the assembly Call TraverseAssembly(oOccs) End If End Sub '*************** Public Sub TraverseAssembly(oOccs As ComponentOccurrences) 'Integer to traverse the assembly occurrences Dim i As Integer Dim oOcc As ComponentOccurrence For Each oOcc In oOccs If oOcc.Suppressed = False 'Occurrence Name (Display Name) oOccName = oOcc.Name 'Builing Part Number 'get full file path Dim pnName As String pnName = oOcc.ReferencedFileDescriptor.FullFileName 'Dump file path Dim dumpName As String dumpName = pnName.Remove(0, pnName.LastIndexOf("\") + 1) Dim dumpLength As Long dumpLength = Len(dumpName) 'trim file file extension [.ipt or .iam] Dim trimName As String trimName = Left(dumpName, dumpLength - 4) Dim trimLength As Long trimLength = Len(trimName) 'set value to feed Dim feedName As String feedName = Right(trimName, trimLength - 10) Try 'iProperties.Value(oOccName, "Project", "Project") = iProperties.Value("Project", "Project") iProperties.Value(oOccName, "Project", "Part Number") = feedName Catch 'It won't be able to change Read-Only parts (e.g. Content Center) 'MessageBox.Show("This is a content center file: " & oOcc.Name, "Title") End Try If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Call TraverseAssembly(oOcc.SubOccurrences) End If End If Next End Sub
Solved! Go to Solution.