write assembly iprops to excel

write assembly iprops to excel

Anonymous
Not applicable
351 Views
2 Replies
Message 1 of 3

write assembly iprops to excel

Anonymous
Not applicable

hello, looking for some help please.

 

I have an assembly that a rule is ran from and I would like it to export a custom iproperty from all the assembly children to a spreadsheet.

 

 

the rule should look through the spreadsheet and try to match the filename with the entries in column 'A'. if it finds a match with one of the assembly children it would write the value from a custom iproperty to column 'N'

 

if it doesn't find the part number in the spreadsheet then it should create a new line and export the part number to column 'A' and the custom iproperty to column'N'

 

The rule should cycle through all assembly children until the end, completing the spreadsheet as above..

 

I have the code shown below that does the assembly file but would appreciate any help /guidance to get the code to iterate through the component occurences...

 

thanks

'Open file from disk and fill with iProperties
GoExcel.Open(ExcelFile2)
oDocNumber = ThisDoc.FileName(False) 'without extension
'Define the first row with data
RowStart = 2
'Define the amount of skipped rows
RowEnd = 1000

'Find the first empty cell
For countA = RowStart To (RowEnd * 0.01) + RowStart
    'If it's not blank jump to cell + 100. E.g. search cell A2 and then A102 etc.
    If Not String.IsNullOrEmpty(GoExcel.CellValue("A" & RowEnd)) Then
        'Add another 100 to searched cells
        RowEnd = RowEnd + 1000
    Else
        'Else if it's empty exit loop
        Exit For
    End If
Next

'Search for the file name in column A
For oRow = RowStart To RowEnd
    If (GoExcel.CellValue("A" & oRow)) = oDocNumber Then    
GoExcel.CellValue("N" & oRow) = iProperties.Value ("Custom", "Work Pack")
GoExcel.Save GoExcel.Close Else 'else create new row If (GoExcel.CellValue("A" & oRow) = "") Then GoExcel.CellValue("A" & oRow) = oDocNumber
GoExcel.CellValue("N" & oRow) = iProperties.Value ("Custom", "Work Pack") GoExcel.Save GoExcel.Close End If End If Next

 

 

 

0 Likes
352 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor

Hi,

Maybe you could use something like this to get all the referenced documents in the assembly. Then use oDoc as the argument of a sub that does what you've already figured out how to do with the document object 🙂

 

For Each oDoc As Document In ThisDoc.Document.AllReferencedDocuments
	MsgBox(oDoc.DisplayName.Substring(0,oDoc.DisplayName.Length - 4))
Next
Message 3 of 3

JhoelForshav
Mentor
Mentor

Sometimes I use this method to traverse an assembly instead.

Sub Main()
Dim asmDoc As AssemblyDocument = ThisDoc.Document
TraverseAssy(asmDoc)	
End Sub
    Sub TraverseAssy(ByVal asm As AssemblyDocument)
        Dim oOcc As ComponentOccurrence
        For Each oOcc In asm.ComponentDefinition.Occurrences
            If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
                'The occurrence is a part
				'Do something
            ElseIf oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
				'The occurrence is an assembly
				'Do something then traverse this assembly aswell.
                TraverseAssy(oOcc.ReferencedDocumentDescriptor.ReferencedDocument)
            End If
        Next
    End Sub

This sub goes through all occurrences in the assembly. If the occurrence is a subassembly it goes through all occurrences in that one aswell by calling itself with the subassembly as argument 🙂