Annonces
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Inventor : i-logic insérer liste de piece selon type d'assemblage

denis.semeniuc
Advocate

Inventor : i-logic insérer liste de piece selon type d'assemblage

denis.semeniuc
Advocate
Advocate

Bonjour,

 

j'ai 3 type de part liste:

 

1-pour assemblages dans la quels la colonne "Part Number" ne pas vide

2-pour assemblages dans la quels la  colonne "Part Number"  vide

3 - pour sousassemblages ossature

 

est-ce que c'est possible incérer la liste de composantes selon le type de assemblage sur la feuille?

 

j'ai déjà une règle quelle fait insertion du liste des pièces selon la norme.

 

 

Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
    
Dim oSheet As Sheet
oSheet = oDrawingDoc.ActiveSheet

'Detect if the template has a parts list
Try 
Dim oPartslistCheck As PartsList
oPartslistCheck = oSheet.PartsLists(1)
partslistpresent=True
Catch
partslistpresent=False
End Try

If partslistpresent=True
      'Delete the current parts list
        Dim oPartsList As PartsList
        oPartsList = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
        oPartsList.Delete
 End If
     ' Set a reference to the first drawing view on
    ' the sheet. This assumes the first drawing
    ' view on the sheet is not a draft view.
    Dim oDrawingView As DrawingView
    oDrawingView = oSheet.DrawingViews(1)
    
    ' Set a reference to the sheet's border
    Dim oBorder As Border
    oBorder = oSheet.Border
    
    Dim oPlacementPoint As Point2d
    
        xrev = oBorder.RangeBox.MaxPoint.X-0.3175
        yrev = oBorder.RangeBox.MaxPoint.Y-0.3175
    oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(xrev, yrev)
        
    ' Create the parts list.
    Dim oPartsList1 As PartsList
    oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
	
	'Set Parts List Type

oPartsList1 = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("LISTE DE PIÈCES - PE (FR)")'("LISTE Ossature - PE (FR)")'("LISTE DE PIÈCES ET DESSINS - PE (FR)")
	
oPartsLis1t = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
	Call oPartsList1.Sort2("DESCRIPTION",True,"CODE",,,True,False,True)
			oPartsList1.Renumber
    	    oPartsList1.SaveItemOverridesToBOM

ThisApplication.ActiveView.Fit

InventorVb.DocumentUpdate()

Le titre du sujet a été modifié par un modérateur pour faciliter la recherche. Titre original:
i-logic incerer liste de piece selon type de assemblage

0 J'aime
Répondre
Solutions acceptées (2)
427 Visites
9 Réponses
Replies (9)

ThomasB44
Mentor
Mentor
Solution acceptée

Salut @denis.semeniuc 

Je pense que c'est possible, mais il faut bien identifier les 3 conditions que tu indiques.

 

Pour le PartNumber :

Dans ton code tu vas chercher la DrawingViews(1), ce qui permet d'obtenir l'ensemble de référence.

Il faut ensuite créer une boucle sur les occurrences de cet ensemble et regarder les iPropriétés "Part Number"

  • Valeurs <> "" => Liste 1
  • Valeurs = "" => Liste 2

Pour l'ossature ou le Frame :

Tu peux tester s'il s'agit d'un Frame comme ceci :

If oFrameDoc.DocumentInterests.HasInterest("FrameDoc") = True Then
                    logger.Info("This is a frame assembly")

oFrameDoc est ici l'assemblage.

Si la propriété n'existe pas ou retourne False, il s'agit d'un assemblage classique.


Thomas
Mechanical Designer / Inventor Professionnal 2025
Inventor Professional EESignature

0 J'aime

denis.semeniuc
Advocate
Advocate

Bonjour,

 

Tout est correct. 

Je pense plus cherche BOM et regarder si la colonne part number est vide ou non. Si est rempli et element avec numéro est une enssamble = style 1 si non style 2.

Sauf je ne sais pas comment faire tout ca.

Mon niveau de programmation est tres faible.

Merci de votre aide.

 

 

Sauf 

0 J'aime

ThomasB44
Mentor
Mentor
Solution acceptée

Salut @denis.semeniuc 

Voici un exemple de code pour regarder dans la nomenclature d'un ensemble, le code est disponible dans l'aide de l'API :

Public Sub BOMQuery()
    ' Set a reference to the assembly document.
    ' This assumes an assembly document is active.
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument

    Dim FirstLevelOnly As Boolean
    If MsgBox("First level only?", vbYesNo) = vbYes Then
        FirstLevelOnly = True
    Else
        FirstLevelOnly = False
    End If
    
    ' Set a reference to the BOM
    Dim oBOM As BOM
    Set oBOM = oDoc.ComponentDefinition.BOM
    
    ' Set whether first level only or all levels.
    If FirstLevelOnly Then
        oBOM.StructuredViewFirstLevelOnly = True
    Else
        oBOM.StructuredViewFirstLevelOnly = False
    End If
    
    ' Make sure that the structured view is enabled.
    oBOM.StructuredViewEnabled = True
    
    'Set a reference to the "Structured" BOMView
    Dim oBOMView As BOMView
    Set oBOMView = oBOM.BOMViews.Item("Structured")
        
    Debug.Print "Item"; Tab(15); "Quantity"; Tab(30); "Part Number"; Tab(70); "Description"
    Debug.Print "----------------------------------------------------------------------------------"

    'Initialize the tab for ItemNumber
    Dim ItemTab As Long
    ItemTab = -3
    Call QueryBOMRowProperties(oBOMView.BOMRows, ItemTab)
End Sub

Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, ItemTab As Long)
    ItemTab = ItemTab + 3
    ' Iterate through the contents of the BOM Rows.
    Dim i As Long
    For i = 1 To oBOMRows.Count
        ' Get the current row.
        Dim oRow As BOMRow
        Set oRow = oBOMRows.Item(i)

        'Set a reference to the primary ComponentDefinition of the row
        Dim oCompDef As ComponentDefinition
        Set oCompDef = oRow.ComponentDefinitions.Item(1)

        Dim oPartNumProperty As Property
        Dim oDescripProperty As Property

        If Typeof oCompDef Is VirtualComponentDefinition Then
            'Get the file property that contains the "Part Number"
            'The file property is obtained from the virtual component definition
            Set oPartNumProperty = oCompDef.PropertySets _
                .Item("Design Tracking Properties").Item("Part Number")

            'Get the file property that contains the "Description"
            Set oDescripProperty = oCompDef.PropertySets _
                .Item("Design Tracking Properties").Item("Description")

            Debug.Print Tab(ItemTab); oRow.ItemNumber; Tab(17); oRow.ItemQuantity; Tab(30); _
                oPartNumProperty.Value; Tab(70); oDescripProperty.Value
        Else
            'Get the file property that contains the "Part Number"
            'The file property is obtained from the parent
            'document of the associated ComponentDefinition.
            Set oPartNumProperty = oCompDef.Document.PropertySets _
                .Item("Design Tracking Properties").Item("Part Number")

            'Get the file property that contains the "Description"
            Set oDescripProperty = oCompDef.Document.PropertySets _
                .Item("Design Tracking Properties").Item("Description")

            Debug.Print Tab(ItemTab); oRow.ItemNumber; Tab(17); oRow.ItemQuantity; Tab(30); _
                oPartNumProperty.Value; Tab(70); oDescripProperty.Value
            
            'Recursively iterate child rows if present.
            If Not oRow.ChildRows Is Nothing Then
                Call QueryBOMRowProperties(oRow.ChildRows, ItemTab)
            End If
        End If
    Next
    ItemTab = ItemTab - 3
End Sub

Transformé en iLogic, et depuis un dessin, il suffit de prendre la 1ère référence de document :

Dim oDwgDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
Dim oAsmDoc As Inventor.AssemblyDocument = oDwgDoc.ReferencedDocuments.Item(1)
Dim oBOM As Inventor.BOM = oAsmDoc.ComponentDefinition.BOM
oBOM.StructuredViewFirstLevelOnly = True
oBOM.StructuredViewEnabled = True
Dim oStructuredBOMView As Inventor.BOMView = oBOM.BOMViews.Item("Structuré")
Dim oRow As Inventor.BOMRow
Dim oCompDef As Inventor.ComponentDefinition
Dim oPartNumProperty As Inventor.Property
For Each oRow In oStructuredBOMView.BOMRows
	oCompDef = oRow.ComponentDefinitions.Item(1)
	oPartNumProperty = oCompDef.Document.PropertySets _
                .Item("Design Tracking Properties").Item("Part Number")
	Logger.Info("Rep : " & oRow.ItemNumber & " | Part Number : " & oPartNumProperty.Value)
Next

 


Thomas
Mechanical Designer / Inventor Professionnal 2025
Inventor Professional EESignature

0 J'aime

denis.semeniuc
Advocate
Advocate

Merci

0 J'aime

denis.semeniuc
Advocate
Advocate

Bonjour @ThomasB44 ,

 

il y a une façonne pour déterminer séparément frame et ossature?

 

Le type mentionner plus haut détermine ossature(déjà vérifié, ca marche. Merci).

 

Quand je cherche dans BOM le PartNumber, dans assemblage normale la code marche bien, par contre dans assemblage Frame résultat est opposé.

 

Merci.

0 J'aime

ThomasB44
Mentor
Mentor

Désolé, mais je ne comprends pas ta réponse.

Frame et ossature sont la même chose pour moi.


Thomas
Mechanical Designer / Inventor Professionnal 2025
Inventor Professional EESignature

0 J'aime

denis.semeniuc
Advocate
Advocate
Bonjour,
Quand on utilise cette api sont cree 2 assemblages. Le 1 frame ou nous faisions tous les actions et 2 ossature ou sont placés tous les pièces. Par défaut il est fantôme dans BOM.

La fonction indiquer par vous detect la 2 ossature.

Cdt.
0 J'aime

ThomasB44
Mentor
Mentor

Salut @denis.semeniuc 

Pour être plus clair :

ThomasB44_0-1697186168733.png

Un Frame EST un ensemble (*.iam).

Dont la propriété DocumentInterests.HasInterest("FrameDoc") est renseignée comme indiquée dans ma réponse 2.

L'ensemble qui contient le Frame, EST un ensemble classique, il peut être un ensemble de construction soudée, sa structure de nomenclature peut également être réglée sur Fantôme si besoin.


Thomas
Mechanical Designer / Inventor Professionnal 2025
Inventor Professional EESignature

0 J'aime

denis.semeniuc
Advocate
Advocate
Merci.
Je vais regarder mon code. Pourquoi il fait les choses bizarres.

Merci encore.
0 J'aime