Bonjour,

J'ai une petite question
Voilà, je reviens avec mes soucis VB et CATIA.

J'ai en fait une classe "collection" qui me sert de dictionnaire.
A chaque nom d'entrée je trouve dans mon dictionnaire le nom qui lui correspond en sortie. Pour comprendre, voici ma classe :

Classe Modules -
|
|_FileDictionary
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
Private szOldFileName As String
Private szNewFileName As String
 
Public Property Get oldFileName()
    oldFileName = szOldFileName
End Property
 
Public Property Get NewFileName()
    NewFileName = szNewFileName
End Property
 
Public Property Let oldFileName(strFileName)
       szOldFileName = strFileName
End Property
 
Public Property Let NewFileName(strFileName)
       szNewFileName = strFileName
End Property
 
Function fReadCsvFile(CsvFilePath As String) As Collection
    Dim MyDictionaryFiles As New Collection
 
    Open CsvFilePath For Input As #1 'ProductPathIN & "recup.csv"
 
      Dim myDictFile As FileDictionary
 
      While Not EOF(1)
        Line Input #1, L
        Datas = Split(L, ";")
        Set myDictFile = New FileDictionary
        myDictFile.oldFileName = Datas(0)
        myDictFile.NewFileName = Datas(1)
        MyDictionaryFiles.Add myDictFile
      Wend
 Close #1
     Set fReadCsvFile = MyDictionaryFiles
End Function
 
Function FindNewFileName(ByVal MyDictionary As Collection, ByVal oldFileName As String) As String
    Dim strNewFileName As String
    Dim myFileDict As FileDictionary
 
    strNewFileName = oldFileName
 
    For Each myFileDict In MyDictionary
        If UCase(myFileDict.oldFileName) = UCase(oldFileName) Then
           strNewFileName = myFileDict.NewFileName
           Exit For
        End If
    Next
    FindNewFileName = strNewFileName
End Function


A partir de mon bouton "start", j'appelle une fonction qui traite mes fichiers .CATProduct (ouvrir/modifier/enregistrer) sous CATIA.
Code de mon "form"
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 
Option Explicit
Private strPathCsv As String
Private strPathJob As String
Public strPathJobIN As String
Public strPathJobOUT As String
Public strPathTemp As String
Public strPathTempIN As String
Public strPathTempOUT As String
Public strInterTmp As String
Public reppart As String
Public repproduct As String
Public repdraw As String
Public repall As String
 
'....
 
'CATProduct ---------------------------------------------------
    'Dim repproduct As String
    'obtient le premier fichier ou répertoire qui est dans "c:\temp\IN\Tmp"
    repproduct = Dir(strInterTmp & "*.CATProduct", vbDirectory)
    'boucle tant que le répertoire n'a pas été entièrement parcouru
        Dim myDictionaryFile As New Collection
        Dim fileDict As New FileDictionary
 
        Set myDictionaryFile = fileDict.fReadCsvFile(strPathTempIN + "recup.csv")
        'Debug.Print (myCol.Count)
 
        Do While (repproduct <> "")
            'teste si c'est un fichier ou un répertoire
            If (GetAttr(strInterTmp & repproduct) And vbDirectory) = vbDirectory Then
                'MsgBox "Répertoire " & rep
 
            Else
                'MsgBox "Fichier " & repproduct
                'Call fProduct
                Call fProduct(strInterTmp, repproduct, strPathTempOUT, strPathTempIN, myDictionaryFile)
 
            End If
            'passe à l'élément suivant
            repproduct = Dir
        Loop
'...
et ma fonction pour les Products est :
Modules -
|
|_FunctProduct
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
 
Function fProduct(InterProductPathIN As String, ProductFile As String, ProductPathOUT As String, ProductPathIN As String, myDictionaryFile As Collection)
'Dim intCountItem As Integer
'Dim CourantObject As String
 
CATIA.DisplayFileAlerts = False
 
 
'Renomme les fichiers PRODUCT, replace les PART et sauvegarde ceux-ci dans le répertoire temporaire OUT
 
Language = "VBSCRIPT"
 
Set documents1 = CATIA.Documents
 
Dim productDocument1 As ProductDocument
 
Set productDocument1 = documents1.Open(InterProductPathIN + ProductFile)
 
Dim product1 As product
Set product1 = productDocument1.product
 
'Récupération productDocument de CATIA (permet d'afficher directement les propriété et méthodes d'un Product CATIA.)
 
Dim products1 As Products
Set products1 = product1.Products
'---------------------------------------------------------------------------
 
Dim myProduct As product
Dim dictFile As New FileDictionary
Dim strNewName As String
 
For Each myProduct In products1
    'Debug.Print (myProduct.PartNumber + " -> " + dictFile.FindNewFileName(myDictionaryFile, myProduct.PartNumber + ".CATProduct"))
    strNewName = dictFile.FindNewFileName(myDictionaryFile, myProduct.PartNumber + ".CATProduct")
    'Set productDocument2 = strNewName
    Set product2 = products1.Item(dictFile.NewFileName)
    Set Nothing1 = products1.ReplaceComponent(product2, strNewName, True)
 
Next
 
'-------------- Replace component -------------------------------------
'
'Sub CATMain()
'
'Set productDocument1 = CATIA.ActiveDocument
'
'Set product1 = productDocument1.product
'
'Set products1 = product1.Products
'
'Set product2 = products1.Item("M5711008820100.1")
'
'Set Nothing1 = products1.ReplaceComponent(product2, "C:\createxdubernet\IN\M5711008820100.CATPart", True)
'
'End Sub
 
' ------------------------------------------------------------------------
'' count elements in active CATProduct
''    intCountItem = products1.Item.Count
'
'    'renommer les Part dans le product courant
'    Dim L As String
'    Dim i As Long
'    Dim Datas() As String
'    'anciens nom de fichiers
'    Dim iny() As String
'    'nouveaux nom de fichiers
'    Dim outy() As String
'    i = 0
'
'    Dim j As Integer
'    For j = 1 To intCountItem
'     'récupération du nom de l'objet courant (PART ou Product)
'    Set CourantObject = productDocument1.Product.Item(j)
'    Set product2 = products1.Item(j)
'
'
'
'
'
'    Next j
'
'        Close #1
'ErrorFile:
 
 
'Set Nothing1 = products1.ReplaceComponent(product2, ProductPathOUT & "P9991002000000-STD01.CATPart", True)
 
'product2.Name = "M9991002000000-STD01.1"
'-------------------------------------------------------------------------------------
Set productDocument1 = CATIA.ActiveDocument
productDocument1.SaveAs ProductPathOUT & ProductFile
productDocument1.Close
 
End Function
Au moment de faire une replace component, je n'arrive pas à passer le nom de mon nouveau fichier à l'appel de la méthode "ReplaceComponent".

Quelqu'un peut-il m'aider?

Dans ma fenêtre debug, si j'utilise cette ligne,
Debug.Print (myProduct.PartNumber + " -> " + dictFile.FindNewFileName(myDictionaryFile, myProduct.PartNumber + ".CATProduct"))
J’ai bien pour chaque élément dans mon "product" son équivalence trouvée dans le dictionnaire.

Merci pour votre aide.

Cordialement,
Paloma