Got it to work! Thanks a lot for your help!
SyntaxEditor Code Snippet
Sub Main()
Dim oDoc As Document = ThisApplication.ActiveDocument
'verify that oDoc is an assembly
If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
'set variable for main parameter
Dim oUM As UnitsOfMeasure = oDoc.UnitsOfMeasure
Dim sLar As Parameter = oCD.Parameters.UserParameters.Item("LARGEUR_MAITRE")
Value_largeur = oUM.GetStringFromValue(sLar.Value, sLar.Units)
Dim sLon As Parameter = oCD.Parameters.UserParameters.Item("LONGUEUR_MAITRE")
Value_longueur = oUM.GetStringFromValue(sLon.Value, sLon.Units)
'run the private sub for each part
For Each aDoc As Document In oDoc.AllReferencedDocuments
Dim sName As String = aDoc.DisplayName
Select Case sName
Case "TRANSFERT GAUCHE-DROITE - EMA60XXWLA": DrivePart(aDoc, "LARGEUR_USER", sLar.Value, sLar.Units)
iPart.ChangeRow("GAUCHE-DROITE", Value_largeur)
Case "TRANSFERT DROITE-GAUCHE - EMA60XXWLA": DrivePart(aDoc, "LARGEUR_USER", sLar.Value, sLar.Units)
iPart.ChangeRow("DROITE-GAUCHE", Value_largeur)
Case "COTE 1 - EMA60XXWLA": DrivePart(aDoc, "LARGEUR_USER", sLar.Value, sLar.Units)
iPart.ChangeRow("COTE 1", Value_largeur)
Case "COTE 2 - EMA60XXWLA": DrivePart(aDoc, "LARGEUR_USER", sLar.Value, sLar.Units)
iPart.ChangeRow("COTE 2", Value_largeur)
Case "BOUT PLEIN - EMAXX72WLA": DrivePart(aDoc, "LONGUEUR_USER", sLon.Value, sLon.Units)
iPart.ChangeRow("BOUT PLEIN", Value_longueur)
Case "BOUT OUVERT - EMAXX72WLA - REV A": DrivePart(aDoc, "LONGUEUR_USER", sLon.Value, sLon.Units)
iPart.ChangeRow("BOUT OUVERT", Value_longueur)
End Select
Next
End Sub
Private Sub DrivePart(oDoc As Document, sParaName As String, oValue As Double, sUnits As String)
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
Dim oFactory As iPartFactory
'verify if the part is an iPart
If oCD.iPartFactory Is Nothing Then
oFactory = oCD.CreateFactory
Else
oFactory = oCD.iPartFactory
End If
'verify if a column already exists for the parameter
Dim bExist As Boolean = False
Dim iCL As Integer = 0
For Each oCL As iPartTableColumn In oFactory.TableColumns
If oCL.Heading = sParaName Then
bExist = True
iCL = oCL.Index
Exit For
End If
Next
'adds the parameter if it doesn't exist
Dim oUM As UnitsOfMeasure = oDoc.UnitsOfMeasure
Dim oParameter As Parameter
Try
oParameter = oCD.Parameters.UserParameters.Item(sParaName)
Catch
oParameter = oCD.Parameters.UserParameters.AddByValue(sParaName, oValue, sUnits)
End Try
Dim oWorkSheet As Object = oFactory.ExcelWorkSheet
Dim oCells As Object = oWorkSheet.Cells
Dim iColumns As Integer = oFactory.TableColumns.Count + 1
Dim iRows As Integer = oFactory.TableRows.Count + 2
Dim sValue As String = oUM.GetStringFromValue(oValue, oParameter.Units)
'creates new column for the parameter if it doesn't exist
If Not bExist Then
MessageBox.Show("Le param�tre n'a pas �t� cr�� dans la pi�ce", "iLogic")
' oCells.Item(1, iColumns).Value = sParaName' oCells.Item(2, iColumns).Value = oUM.GetStringFromValue(oParameter.Value, oParameter.Units)' oCells.Item(iRows, iColumns).Value = oUM.GetStringFromValue(oValue, oParameter.Units)
'checks if the iPart column contains the value
Else
Dim bFound As Boolean = False
For i = 1 To iRows
If oCells.Item(i, iCL).Value = sValue Then
bFound = True
Exit For
End If
Next
'if not found, adds the value
If Not bFound Then
oCells.Item(iRows, 1).Value = sValue
For i = 2 To iCL - 1
tmp = oCells.Item(iRows - 1, i).Value
oCells.Item(iRows, i).Value = tmp
Next
oCells.Item(iRows, iCL).Value = sValue
End If
End If
Dim oWB As Object = oWorkSheet.Parent
oWB.Save()
oWB.Close()
End Sub