Updating user parameter with ilogic

Updating user parameter with ilogic

ejaL9K8H
Advocate Advocate
1,666 Views
21 Replies
Message 1 of 22

Updating user parameter with ilogic

ejaL9K8H
Advocate
Advocate

Hi

 

I am trying to change the user parameter of an Asset model from an Assemply.

I would like my user paramter "ID_Number" to be equal to to the item number from the Bill of Materials.

I have used folowing code, but every time i run it, Inventor freezes and crashses...

What is the problem?

 

Thanks in advance

 

doc = ThisDoc.Document
Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition
Dim oBOM As BOM = oAssyDef.BOM

oBOM.StructuredViewEnabled = True
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
' Set the Row Merge Settings
oBOM.SetPartNumberMergeSettings(False)

Dim oBOMRow As BOMRow

For Each oBOMRow In oBOMView.BOMRows
    'Set a reference to the primary ComponentDefinition of the row
    Dim oCompDef As ComponentDefinition
    oCompDef = oBOMRow.ComponentDefinitions.Item(1)
    
    Dim CompFullDocumentName As String = oCompDef.Document.FullDocumentName
    Dim CompFileNameOnly As String
    Dim index As Integer = CompFullDocumentName.LastIndexOf("\")
    
    CompFileNameOnly = CompFullDocumentName.Substring(index + 1)

	ItemNumber = oBOMRow.ItemNumber

 	Parameter(CompFileNameOnly, "ID_Number") = ItemNumber


Next

 

0 Likes
1,667 Views
21 Replies
Replies (21)
Message 21 of 22

Ralf_Krieg
Advisor
Advisor

Hello

 

Can you try to replace the line

New_Value = Parameter(oDoc.Name, "ID_Number") & " - " & iProperties.Value(oDoc.Name, "Project", "Part Number")

with this line

New_Value = GetNewValue(oDoc)

and add the following function somewhere to the end of your iLogic Script

Private Function GetNewValue(oDoc As Document) As String

Dim oUserParams As UserParameters
Set oUserParams = oDoc.ComponentDefinition.Parameters.UserParameters

Dim oUserParam As UserParameter
For Each oUserParam In oUserParams
    If oUserParam.Name = "ID_Number" Then
        New_Value = oUserParam.Value
        Exit For
    End If
Next

Dim oPropSet As PropertySet
Set oPropSet = oDoc.PropertySets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")

Dim oProp As Property
For Each oProp In oPropSet
    If oProp.Name = "Part Number" Then
        New_Value = New_Value & " -" & oProp.Value
        Exit For
    End If
Next

GetNewValue = New_Value

End Function

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 22 of 22

ejaL9K8H
Advocate
Advocate

Error in rule: 

Parameter: The document named "C:\Working Folder\Designs\Factory Assets\Test_5C934505E5A8EC1FD6ED745FF98CBFF6.ipt" was not found.

But it workes fine if I just give the Asset Tag a emty name:

New_Value = ""

So you are rigth that the problem is that line.

But this is enough for my needs. Thanks a lot!

0 Likes