,Catia arbre à l'exportation v5 grâce à une bonne soirée macro VBA
je dois exporter l'arbre Spec Catia à utiliser comme BoM.
L'exportation devraient:
- Aller vers Excel et utilisera la fonction WalkDownTree.
- Avoir le numéro de pièce, la nomenclature et un utilisateur ajouté Propriété appelée "Sinex Ref".
Il devra également s'assurer que l'arbre exporté ignore les parties et les produits appelés "Ref".
Présentez la quantité de chaque article en utilisant le numéro de pièce .
Inclure les parties désactivées mais mentionner qu'elles sont désactivées.
Je suis nouveau à Catia et VBA et sont venus avec les éléments suivants (j'ai fait des ajustements à d'autres macros que j'ai trouvé mais on a remarqué qu'ils ignorent les enfants dans l'arbre). Actuellement, la macro génère le fichier Excel et, dans la même cellule, parcourt toutes les parties et tous les enfants de l'arbre des spécifications, qu'ils soient ou non désactivés.
Sub CATMain()
' ********* is the current document a CATIA Product **************
If CATIA.Documents.Count = 0 Then
MsgBox "There are no CATIA documents open. Please open a CATIA document and try again.", ,msgboxtext
Exit Sub
End If
If InStr(CATIA.ActiveDocument.Name, ".CATProduct") < 1 Then
MsgBox "The active document is not a Product. Please open a CATIA Product and try again.", ,msgboxtext
Exit Sub
End If
' ************* General declarations for the Active CATIA session *****************
Dim oProdDoc As ProductDocument
t = 1
Set oProdDoc = CATIA.ActiveDocument
Dim oRootProd As Product
Set oRootProd = oProdDoc.Product
Dim par As Parameters
Set par = oRootProd.UserRefProperties
Dim SinexRef As String
' *************** begin spec tree scroll ******************
Call WalkDownTree(oRootProd)
End Sub
Sub WalkDownTree(oInProduct As Product)
Dim oInstances As Products
Set oInstances = oInProduct.Products
On Error Resume Next
Set Excel = GetObject(, "EXCEL.Application")
If Err.Number <> 0 Then
Set Excel = CreateObject("EXCEL.Application")
Excel.Visible = True
Excel.Workbooks.Add
End If
If t <> 1 Then
for i=1 to oInProduct.Count
'**************************** Export title ***************************
row=2
col=1
Excel.Columns.Columns(1).Columnwidth = 5
Excel.Columns.Columns(2).Columnwidth = 15
Excel.Cells(row,col+1).Value = "CATProduct:"
Excel.Cells(row,col+1).Font.Bold = true
Excel.Cells(row,col+1).HorizontalAlignment = 3
Excel.Cells(row,col+2).Value = CATIA.ActiveDocument.Name
' **************************** Export column titles ***************
row=4
Excel.Cells(row,col+1).Value = "Instance Name"
Excel.Cells(row,col+1).Font.Bold = true
Excel.Columns.Columns(2).Columnwidth = 20
Excel.Cells(row,col+1).borders.LineStyle = 1
Excel.Cells(row,col+1).HorizontalAlignment = 3
Excel.Cells(row+2,col+1).Value = oInProduct.ReferenceProduct.PartNumber
Excel.Cells(row,col+2).Value = "Ref"
Excel.Cells(row,col+2).Font.Bold = true
Excel.Columns.Columns(3).Columnwidth = 15
Excel.Cells(row,col+2).borders.LineStyle = 1
Excel.Cells(row,col+2).HorizontalAlignment = 3
Excel.Cells(row+2,col+2).Value = oInProduct.ReferenceProduct.Nomenclature
Excel.Cells(row,col+3).Value = "Quantity"
Excel.Cells(row,col+3).Font.Bold = true
Excel.Columns.Columns(4).Columnwidth = 15
Excel.Cells(row,col+3).borders.LineStyle = 1
Excel.Cells(row,col+3).HorizontalAlignment = 3
Excel.Cells(row+2,col+3).Value = 1 'insert item quantity corresponding to PartNumber
Excel.Cells(row,col+4).Value = "SinexRef"
Excel.Cells(row,col+4).Font.Bold = true
Excel.Columns.Columns(5).Columnwidth = 15
Excel.Cells(row,col+4).borders.LineStyle = 1
Excel.Cells(row,col+4).HorizontalAlignment = 3
Excel.Cells(row+2,col+4).Value = 1 'insert Sinex Ref corresponding to PartNumber
t = t + 1
Next
End If
Dim k As Integer
For k = 1 To oInstances.Count
Dim oInst As Product
Set oInst = oInstances.Item(k)
Call WalkDownTree(oInst)
Next
End Sub
Comment voulez-vous créer les en-têtes? – Castella
Créer essentiellement une rangée d'en-têtes, comme Excel.Cells (1,1) .Value = "CATProduct", Excel.Cells (1,2) .Value = "Nom de l'instance", et ainsi de suite, donc tous ces en-têtes sont seulement dans une rangée. Vous n'avez besoin de le faire qu'une seule fois, puis créer une boucle (similaire à ce que vous avez déjà) qui insère juste les informations appropriées dans la même colonne que l'en-tête associé. Cela vous permettra (ou d'autres) de résumer/filtrer/trier plus facilement les données dans la feuille Excel. – garthhh
J'ai fait les modifications que vous avez suggérées mais le résultat est le même, la même cellule est écrasée avec les mêmes valeurs. – Castella