Sie sind auf Seite 1von 2

Alright, I figured out how to export properties from a single part into an Excel file.

Now I would like to be able to open a product and run a macro which would then basically run this script on every part and export the properties into the same Excel sheet. Any ideas how to add on to my code to accomplish this? Here's my code to export properties from a part: Sub CATMain() 'Load the part Dim myDocuments As Documents Set myDocuments = CATIA.Documents Dim myDocument As PartDocument Set myDocument = CATIA.ActiveDocument Dim myPart As Part Set myPart = myDocument.Part Dim myProduct As Product Set myProduct = myDocument.GetItem(myPart.Name) Dim myParameters As Parameters Set myParameters = myProduct.UserRefProperties Dim getThickness As String getThickness = myParameters.Item(myPart.Name & "\Properties\Thickness").ValueAsS tring Dim getMaterial As String getMaterial = myParameters.Item(myPart.Name & "\Properties\Material").ValueAsStr ing Dim getMass As String getMass = myParameters.Item(myPart.Name & "\Properties\Mass").ValueAsString Dim partName As String partName=myProduct.name 'to excel Dim Dim Dim Dim Dim Dim Dim Dim Excel As Object workbooks As workbooks workbook As workbook Sheets As Object Sheet As Object worksheet As Excel.worksheet myworkbook As Excel.workbook myworksheet As Excel.worksheet

On Error Resume Next Set Excel = GetObject(, "EXCEL.Application") If Err.Number <> 0 Then Err.Clear Set Excel = CreateObject("EXCEL.Application") Else Err.Clear MsgBox "Please note you have to close Excel", vbCritical

Exit Sub End If Excel.Visible = True 'load a sheet Set Set Set Set workbooks = Excel.Application.workbooks myworkbook = Excel.workbooks.Add myworksheet = Excel.ActiveWorkbook.Add myworksheet = Excel.Sheets.Add

'download the properties 'row one Excel.Cells(1,1)="Part Number" Excel.Cells(1,2)="Thickness" Excel.Cells(1,3)="Material" Excel.Cells(1,4)="Mass" 'row 2 Excel.Cells(2,1)= Excel.Cells(2, 2) Excel.Cells(2, 3) Excel.Cells(2, 4) End Sub partName = getThickness = getMaterial = getMass

Das könnte Ihnen auch gefallen