CATIA V5 | 3DEXPERIENCE
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
-17%
Le deal à ne pas rater :
Casque de réalité virtuelle Meta Quest 2 128 Go Blanc (+29,99€ ...
249.99 € 299.99 €
Voir le deal

liste +arbre catproduct VBA

3 participants

Aller en bas

R?solu liste +arbre catproduct VBA

Message par quentinc Lun 13 Juin 2016 - 12:13

bonjour
je fait actuellement un programme listant les différent sous Product et part d'un ensemble
mais je voudrai aussi qu'il me l'affiche en arborescence
j'ai donc ce code pour le moment:
Code:
Public NDocCatia As Document
Public ProductDocCatia As ProductDocument
Public NomActif As String
Public PartDocCatia As PartDocument
Dim tableau() As String
Dim i As Integer

Public Property Get DocCatia() As Documents
Set DocCatia = CATIA.Documents
End Property

Public Property Get NomDocActif() As String
NomDocActif = ProduitSelect.Name
End Property

Public Property Get NouveauDocCatia() As Documents
Set NouveauDocCatia = CATIA.Documents
End Property

Public Property Get ProduitSelect() As ProductDocument
'
NomActif = CATIA.ActiveDocument.Name
    If (InStr(1, NomActif, "CATProduct") > 0) Then
        Set ProduitSelect = CATIA.ActiveDocument
    Else
        MsgBox ("l'application ne fonctionne que pour les assemblages"), vbOKOnly
        End
    End If
    
End Property


Public Function ListeDoc()
i = 0
For Each NDocCatia In DocCatia
NomDocCatia = NDocCatia.Name
CompteProduct = 0
ComptePart = 0
'
    If (InStr(1, NomDocCatia, "CATProduct") > 0) Then
        Extensionfichier = "CATProduct"
        Set ProductDocCatia = NouveauDocCatia.Item(NomDocCatia)
         If NomDocActif = NDocCatia.Name Then
         Else
         UserForm2.ListBox1.AddItem "----------"
         UserForm2.ListBox1.AddItem ProductDocCatia.Product.PartNumber
         UserForm2.ListBox1.AddItem "----------"
         CompteProduct = CompteProduct + 1
         UserForm2.tree.Nodes.Add
        
            i = i + 1
            ReDim tableau(i)
            tableau(i) = ProductDocCatia.Product.PartNumber
         End If
    End If
    
    If (InStr(1, NomDocCatia, "CATPart") > 0) Then
        Extensionfichier = "CATPart"
        Set PartDocCatia = NouveauDocCatia.Item(NomDocCatia)
        UserForm2.ListBox1.AddItem "----------"
        UserForm2.ListBox1.AddItem PartDocCatia.Product.PartNumber
        UserForm2.ListBox1.AddItem "----------"
        ComptePart = ComptePart + 1
        UserForm2.tree.Nodes.Add
        
            i = i + 1
            ReDim tableau(i)
            tableau(i) = PartDocCatia.Product.PartNumber
    End If

Next



For n = 1 To i
    UserForm2.tree.Nodes.Item(i) = tableau(i)
    
Next n

End Function

Sub CATMain()

ListeDoc
UserForm2.Show


End Sub


pour le moment il me dit une erreur sur cette ligne je ne sait pas pourquoi

                     UserForm2.tree.Nodes.Item(i) = tableau(i)
une explication s'il vous plait

si quelqu'un a des conseil sur le reste oui vois d'autre erreur je suis preneur

merci d'avance
cordialement
quentin


Dernière édition par quentinc le Jeu 16 Juin 2016 - 9:27, édité 1 fois

quentinc
actif
actif

Messages : 33
Date d'inscription : 07/06/2016
Localisation : saint quentin en yveline

Revenir en haut Aller en bas

R?solu Re: liste +arbre catproduct VBA

Message par raphael_59240 Lun 13 Juin 2016 - 13:19

Bonjour,


Peux tu etre plus precis quand tu dis qu'il y a une erreur.
Quel type d'erreur? incompatibilité...?


raphael
raphael_59240
raphael_59240
actif
actif

Messages : 127
Date d'inscription : 28/03/2015
Age : 53
Localisation : dunkerque

Revenir en haut Aller en bas

R?solu Re: liste +arbre catproduct VBA

Message par quentinc Lun 13 Juin 2016 - 13:44

type mismatch


quentinc
actif
actif

Messages : 33
Date d'inscription : 07/06/2016
Localisation : saint quentin en yveline

Revenir en haut Aller en bas

R?solu Re: liste +arbre catproduct VBA

Message par raphael_59240 Lun 13 Juin 2016 - 14:08

Bonour,

y a t il possibilite d'obtenir ton fichier macro?
Si oui j e transmettrai MP mon adresse mail

raphael
raphael_59240
raphael_59240
actif
actif

Messages : 127
Date d'inscription : 28/03/2015
Age : 53
Localisation : dunkerque

Revenir en haut Aller en bas

R?solu Re: liste +arbre catproduct VBA

Message par quentinc Lun 13 Juin 2016 - 14:18

oui il n'y a aucun problème

quentin

quentinc
actif
actif

Messages : 33
Date d'inscription : 07/06/2016
Localisation : saint quentin en yveline

Revenir en haut Aller en bas

R?solu Re: liste +arbre catproduct VBA

Message par raphael_59240 Lun 13 Juin 2016 - 16:03

ok va ta messagerie c'est fait
raphael_59240
raphael_59240
actif
actif

Messages : 127
Date d'inscription : 28/03/2015
Age : 53
Localisation : dunkerque

Revenir en haut Aller en bas

R?solu Re: liste +arbre catproduct VBA

Message par raphael_59240 Mer 15 Juin 2016 - 10:01

bonjour,


pour commencer j ai déclaré le tableau en variant car en mettant
Code:
UserForm2.tree.Nodes.Item(i)
en espion  j'ai eu un retour integer (donc avec un variant ça passe bien).
apres tu as une erreur de définition car le programme plante sur ton
Code:
UserForm2.tree.Nodes.Count
 il compte quelque chose qu'il n a pas.

je n arrive pas trop à voir ce que tu cherches à faire hors mis de recréer l’arborescence dans un user forme.

peut etre que ceci pourrais t'eclairé :http://silkyroad.developpez.com/VBA/XlOrganigramme/
Raphael
raphael_59240
raphael_59240
actif
actif

Messages : 127
Date d'inscription : 28/03/2015
Age : 53
Localisation : dunkerque

Revenir en haut Aller en bas

R?solu Re: liste +arbre catproduct VBA

Message par quentinc Mer 15 Juin 2016 - 11:49

bonjour,
je cherche justement a reproduire l'arborescence dans une user forme, mais je ne comprend pas comment indiqué que telle product est le parent d'un autre.
l'objectif final est que le programme compare les nom des parent enfant afin de savoir si sa correspond bien a une norme prédéfinie

quentinc
actif
actif

Messages : 33
Date d'inscription : 07/06/2016
Localisation : saint quentin en yveline

Revenir en haut Aller en bas

R?solu Re: liste +arbre catproduct VBA

Message par lumpazepfel Mer 15 Juin 2016 - 17:07

Salut Quentin,

Je suis parti d'une autre source pour ton problème d'arbre voici le code:
Code:
Sub CATMain()

'*******************************************************
'*** Macro pour lister l'arbre d'un Product          ***
'*** Il faut une userform nommée UserForm1          ***
'***    avec une listbox nommée ListBox1            ***
'***    avec une treeview nommée Treeview1          ***
'*** Source:CATIA PORTABLE SCRIPT CENTER VERSION 2.0 ***
'*******************************************************
'*** http://catiav5.forumactif.org/t1462-liste-arbre-catproduct-vba#6534

On Error Resume Next

Dim myTree As TreeView
Dim myList As ListBox

Set myTree = UserForm1.TreeView1
Set myList = UserForm1.ListBox1

Dim myDoc As Document
Dim myrootProduct As Product

Set myDoc = CATIA.ActiveDocument

If myDoc Is Nothing Then
    MsgBox "Please load a product - THEN activate this function!"
    Return
End If

Set myrootProduct = myDoc.Product
visitProduct myrootProduct, "", myTree
UserForm1.Show
End Sub

Sub visitProduct(prod As Product, parentKey As String, ByRef myTree As TreeView)

On Error Resume Next

Dim children As Products
Set children = prod.Products
Dim i As Integer
Dim child As Product
Dim key As String
Dim label As String

label = prod.PartNumber & " / " & prod.Name ' pour afficher le pratNumber et le nom d'instance

key = parentKey & "###" & prod.Name

If parentKey = "" Then
    myTree.Nodes.Add(, , key, label).Expanded = True
    UserForm1.ListBox1.AddItem "----------"
    UserForm1.ListBox1.AddItem prod.PartNumber
    UserForm1.ListBox1.AddItem "----------"

Else
    myTree.Nodes.Add(parentKey, tvwChild, key, label).Expanded = True
    UserForm1.ListBox1.AddItem "----------"
    UserForm1.ListBox1.AddItem prod.PartNumber
    UserForm1.ListBox1.AddItem "----------"
End If

For i = 1 To children.Count
    Set child = children.Item(i)
    visitProduct child, key, myTree
Next

End Sub
et le résultat :
liste +arbre catproduct VBA Testtr10
lumpazepfel
lumpazepfel
Fédérateur
Fédérateur

Messages : 315
Date d'inscription : 02/11/2015
Localisation : Ensisheim

Revenir en haut Aller en bas

R?solu Re: liste +arbre catproduct VBA

Message par quentinc Jeu 16 Juin 2016 - 9:04

bonjour,

merci beaucoup pour ton programme ,

pour ces deus ligne :*
Sub visitProduct(prod As Product, parentKey As String, ByRef myTree As String)
Dim myTree As TreeView

mon logiciel ne reconnait pas le TreeView a tu une idée ?
il me manque aussi l'outil pour créer le treeview dans user form je suis obliger de le copier de programme existent.
me manque t'il une option ou extension?

cordialement
quentin

quentinc
actif
actif

Messages : 33
Date d'inscription : 07/06/2016
Localisation : saint quentin en yveline

Revenir en haut Aller en bas

R?solu Re: liste +arbre catproduct VBA

Message par quentinc Jeu 16 Juin 2016 - 9:17

bonjour,
c'est bon j'ai trouver en cherchant dans l'outil référence,
encore merci pour ton aide
A bientôt
quentin

quentinc
actif
actif

Messages : 33
Date d'inscription : 07/06/2016
Localisation : saint quentin en yveline

Revenir en haut Aller en bas

R?solu Re: liste +arbre catproduct VBA

Message par raphael_59240 Jeu 16 Juin 2016 - 9:24

bonjour,

edite ton premier message pour y mettre un statut resolu Smile
raphael_59240
raphael_59240
actif
actif

Messages : 127
Date d'inscription : 28/03/2015
Age : 53
Localisation : dunkerque

Revenir en haut Aller en bas

R?solu Re: liste +arbre catproduct VBA

Message par Contenu sponsorisé


Contenu sponsorisé


Revenir en haut Aller en bas

Revenir en haut

- Sujets similaires

 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum