ilogic form in iam - change parameters in ipt

ilogic form in iam - change parameters in ipt

Anonymous
Not applicable
916 Views
10 Replies
Message 1 of 11

ilogic form in iam - change parameters in ipt

Anonymous
Not applicable

Hi guys!

 

Currently having a problem with a parametric assembly that I'm trying to do. 

 

I have created two USER PARAMETER in an iam and I want them to drive the parts.

This I can do using this code:

 

SyntaxEditor Code Snippet

Parameter("TRANSFERT GAUCHE-DROITE - EMA60XXWLA.ipt", "LARGEUR")=LARGEUR_MAITRE
Parameter("TRANSFERT DROITE-GAUCHE - EMA60XXWLA.ipt", "LARGEUR")=LARGEUR_MAITRE
Parameter("COTE 2 - EMA60XXWLA.ipt", "LARGEUR")=LARGEUR_MAITRE
Parameter("COTE 1 - EMA60XXWLA.ipt", "LARGEUR")=LARGEUR_MAITRE
Parameter("BOUT PLEIN - EMAXX72WLA.ipt", "LONGUEUR")=LONGUEUR_MAITRE
Parameter("BOUT OUVERT - EMAXX72WLA - REV A.ipt", "LONGUEUR")=LONGUEUR_MAITRE

 But the problem is that the part in the assembly are also used elsewhere so I need them to be Ipart.

 

I tried using a custom parameter in the iPart table but it seems like it cant be driven by a parameter.

 

I need inventor to create a new member for the iPart. This way I'd just have to change my two parameter to create a couple of iPart.

 

Is it possible?

 

Thanks 

0 Likes
917 Views
10 Replies
Replies (10)
Message 2 of 11

johnsonshiue
Community Manager
Community Manager

Hi! It can be either a syntax error, or context inconsistency, or it just cannot be done. WIthout the dataset, it is hard to tell where the problem is. Could you provide an example?

Many thanks!

 



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 3 of 11

Owner2229
Advisor
Advisor

Hey, this should get you started:

 

Sub Main()
     Dim oDoc As Document = ThisApplication.ActiveDocument
     If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub
     Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
     Dim sLar As Parameter = oCD.Parameters.UserParameters.Item("LARGEUR_MAITRE")
     Dim sLon As Parameter = oCD.Parameters.UserParameters.Item("LONGUEUR_MAITRE")
     For Each aDoc As Document In oDoc.AllReferencedDocuments
          Dim sName As String = aDoc.DisplayName
          Select Case sName
          Case "TRANSFERT GAUCHE-DROITE - EMA60XXWLA.ipt":  DrivePart(aDoc, "LARGEUR", sLar.Value, sLar.Units)
          Case "TRANSFERT DROITE-GAUCHE - EMA60XXWLA.ipt":  DrivePart(aDoc, "LARGEUR", sLar.Value, sLar.Units)
          Case "COTE 2 - EMA60XXWLA.ipt":                   DrivePart(aDoc, "LARGEUR", sLar.Value, sLar.Units)
          Case "COTE 1 - EMA60XXWLA.ipt":                   DrivePart(aDoc, "LARGEUR", sLar.Value, sLar.Units)
          Case "BOUT PLEIN - EMAXX72WLA.ipt":               DrivePart(aDoc, "LONGUEUR", sLon.Value, sLon.Units)
          Case "BOUT OUVERT - EMAXX72WLA - REV A.ipt":      DrivePart(aDoc, "LONGUEUR", sLon.Value, sLon.Units)
          End Select
     Next
End Sub

Private Sub DrivePart(oDoc As Document, sParaName As String, oValue As Object, sUnits As String)
     Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
     Dim oFactory As iPartFactory
     If oCD.iPartFactory Is Nothing Then
          oFactory = oCD.CreateFactory
     Else
          oFactory = oCD.iPartFactory
     End If
     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
     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 + 1
     If Not bExist Then
          oCells.Item(1, iColumns) = sParaName
          oCells.Item(2, iColumns) = oUM.GetStringFromValue(oParameter.Value, oParameter.Units)
          oCells.Item(iRows, iColumns) = oUM.GetStringFromValue(oValue, oParameter.Units)
     Else
          Dim bFound As Boolean = False
          For i = 1 To iRows
               If oCells.Item(i, iCl) = oValue Then
                    bFound = True
                    Exit For
               End If
          Next
          If Not bFound Then
               oCells.Item(iRows, iColumns) = oUM.GetStringFromValue(oValue, oParameter.Units)
          End If
     End If
     Dim oWB As Object = oWorkSheet.Parent 
     oWB.Save()
     oWB.Close()
End Sub 
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 4 of 11

Anonymous
Not applicable

It does look like it would do what I want it to do.

 

Trying to make it work. I had to remove the .ipt at the end of the part name, if I keep the .ipt at the end it does nothing. Now i'm getting an error. 

 

'Public Shared Operator =(left As Double, right As Double) As Boolean':

 

I can't figure out what it means. Seems to be linked to the bExist and bFound as they are the only Boolean operator in this. Ever encountered this error?

 

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 sLar As Parameter = oCD.Parameters.UserParameters.Item("LARGEUR_MAITRE")
     Dim sLon As Parameter = oCD.Parameters.UserParameters.Item("LONGUEUR_MAITRE")
     
     '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", sLar.Value, sLar.Units)
          Case "TRANSFERT DROITE-GAUCHE - EMA60XXWLA":  DrivePart(aDoc, "LARGEUR", sLar.Value, sLar.Units)
          Case "COTE 2 - EMA60XXWLA":                   DrivePart(aDoc, "LARGEUR", sLar.Value, sLar.Units)
          Case "COTE 1 - EMA60XXWLA":                   DrivePart(aDoc, "LARGEUR", sLar.Value, sLar.Units)
          Case "BOUT PLEIN - EMAXX72WLA":               DrivePart(aDoc, "LONGUEUR", sLon.Value, sLon.Units)
          Case "BOUT OUVERT - EMAXX72WLA - REV A":      DrivePart(aDoc, "LONGUEUR", sLon.Value, sLon.Units)
          End Select
     Next
End Sub

Private Sub DrivePart(oDoc As Document, sParaName As String, oValue As Object, 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 value to the parameter
     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 + 1
     
     'creates new column for the parameter if it doesn't exist
     If Not bExist Then
          oCells.Item(1, iColumns) = sParaName
          oCells.Item(2, iColumns) = oUM.GetStringFromValue(oParameter.Value, oParameter.Units)
          oCells.Item(iRows, iColumns) = oUM.GetStringFromValue(oValue, oParameter.Units)
     'validate if the value has changed      
     Else
          Dim bFound As Boolean = False
          For i = 1 To iRows
               If oCells.Item(i, iCl) = oValue Then
                    bFound = True
                    Exit For
               End If
          Next
     'if not the same adds the value
          If Not bFound Then
               oCells.Item(iRows, iColumns) = oUM.GetStringFromValue(oValue, oParameter.Units)
          End If
     End If
     
     
     Dim oWB As Object = oWorkSheet.Parent 
     oWB.Save()
     oWB.Close()
End Sub 

 

0 Likes
Message 5 of 11

Owner2229
Advisor
Advisor

Hmm, that's strange. You can try write in something like MsgBox("here") and move it by every few rows to see "how far the code gets before it crashes".

Anyway, you've got the descriptions mostly right, except for:

 

'adds the value to the parameter >> 'adds the parameter if it doesn't exist

 

'validate if the value has changed >> 'checks if the iPart column contains the value

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 6 of 11

Anonymous
Not applicable

Thanks for the description.

 

Using the message text box I found out that the error is somewhere in there.

 

SyntaxEditor Code Snippet

     'creates new column for the parameter if it doesn't exist
     If Not bExist Then
          oCells.Item(1, iColumns) = sParaName
          oCells.Item(2, iColumns) = oUM.GetStringFromValue(oParameter.Value, oParameter.Units)
          oCells.Item(iRows, iColumns) = 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) = oValue Then
                    bFound = True
                    Exit For
               End If
          Next
     'if not the same adds the value
          If Not bFound Then
               oCells.Item(iRows, iColumns) = oUM.GetStringFromValue(oValue, oParameter.Units)
          End If
     End If 

 

0 Likes
Message 7 of 11

Anonymous
Not applicable

SyntaxEditor Code Snippet

     If Not bExist Then
          oCells.Item(1, iColumns) = sParaName
          oCells.Item(2, iColumns) = oUM.GetStringFromValue(oParameter.Value, oParameter.Units)
          oCells.Item(iRows, iColumns) = oUM.GetStringFromValue(oValue, oParameter.Units)

I dont get the difference between the two last rows.  

0 Likes
Message 8 of 11

Owner2229
Advisor
Advisor

The second row ads the current (original) value from the part's parameter and the last row adds the value required by assembly.

 

Also, you can try this:

 

     'creates new column for the parameter if it doesn't exist
     If Not bExist Then
          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 = Cstr(oValue) Then
                    bFound = True
                    Exit For
               End If
          Next
     'if not the same adds the value
          If Not bFound Then
               oCells.Item(iRows, iColumns).Value = oUM.GetStringFromValue(oValue, oParameter.Units)
          End If
     End If 

 

I guess this line was causing the error:

If oCells.Item(i, iCL).Value = Cstr(oValue) Then

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 9 of 11

Anonymous
Not applicable

The problem is in this line

SyntaxEditor Code Snippet

If oCells.Item(i, iCL) = oValue Then

I changed the type of oValue from sting to double but it still doesn't work

 

Edit: you already replied to this one hehe Thanks

0 Likes
Message 10 of 11

Anonymous
Not applicable

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 

 

 

 

0 Likes
Message 11 of 11

Owner2229
Advisor
Advisor

You're welcomed Smiley Happy

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes