Updating user parameter with ilogic

Updating user parameter with ilogic

ejaL9K8H
Advocate Advocate
1,631 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,632 Views
21 Replies
Replies (21)
Message 2 of 22

bradeneuropeArthur
Mentor
Mentor

Is the parameter

Parameter(CompFileNameOnly, "ID_Number") = ItemNumber

Always in the model available?

Otherwise you need to add that first!

 

Regards 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 22

ejaL9K8H
Advocate
Advocate

Yes the parameter is always available in the model.

 

I Added: 

iLogicVb.UpdateWhenDone = True

The iproperties updates after the new parameter, but the paramter in factory properties remains the same..

0 Likes
Message 4 of 22

bradeneuropeArthur
Mentor
Mentor
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 = Nothing
Dim oDoc As Inventor.Document
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)
    
	oDoc = oCompDef.Document
	'Doc.FullFileName
    Dim CompFullDocumentName As String = oDoc.FullFileName'oCompDef.Document.fullfilename
    Dim CompFileNameOnly As String
    Dim index As Integer = CompFullDocumentName.LastIndexOf("\")
    
    CompFileNameOnly = CompFullDocumentName.Substring(index + 1)

	ItemNumber = oBOMRow.ItemNumber
	
 	Parameter(CompFileNameOnly, "ID_Number") = ItemNumber


Next

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 22

ejaL9K8H
Advocate
Advocate

The iProperties are updating, but I want my factory propererties to update as well.

The ID_Number is set to "X" as default.

Is it possible to synchronize these two values? 

Properties would not update.png

 

0 Likes
Message 6 of 22

ejaL9K8H
Advocate
Advocate

This ilogic rule, is what updates the iproperties in the part/asset

iProperties.Value("Custom", "ID Number") = ID_Number

 

0 Likes
Message 7 of 22

bradeneuropeArthur
Mentor
Mentor

What do you mean with Factory?

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 8 of 22

ejaL9K8H
Advocate
Advocate

By Factory i mean the "Factory Properties" (at the left-hand-side) which follows the user parameters from the part/asset.

I am trying to biuld a Factory layout as an assembly which are buildup with Assets.

0 Likes
Message 9 of 22

bradeneuropeArthur
Mentor
Mentor

For "Factory Design Suite"?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 10 of 22

ejaL9K8H
Advocate
Advocate

It is Assets properties which can be found in this menu:

ejaL9K8H_0-1615803327181.png

 

0 Likes
Message 11 of 22

ejaL9K8H
Advocate
Advocate

Nomally it updates with the assets user parameter:

ejaL9K8H_1-1615803406540.png

 

 

0 Likes
Message 12 of 22

bradeneuropeArthur
Mentor
Mentor

What Version of Inventor are you using?

And what vertical are you using, "Factory Design Suite"?

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 13 of 22

ejaL9K8H
Advocate
Advocate

I am using Autodesk® Factory Design Utilities, Version 2020.1.3

0 Likes
Message 14 of 22

bradeneuropeArthur
Mentor
Mentor

I can't help you with that since I have not Inventor Factory Design installed!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 15 of 22

ejaL9K8H
Advocate
Advocate

I found a solution, but it is only working if i Run it as 2 separately codes:

 

Firstly the ID number is updated:

' Update ID Number
' Item Number = ID Number

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)
	
	Try
	ItemNumber = oBOMRow.ItemNumber
	
 	Parameter(CompFileNameOnly, "ID_Number") = ItemNumber
	Catch
	End Try


Next
iLogicVb.UpdateWhenDone = True

 

Secondly an Asset Tag is made, which updates the all asset models:

AddReference "Autodesk.Factory.PublicAPI.dll"
Imports Autodesk.Factory.PublicAPI.Currency.v2

Sub Main()

' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Set up a variable for the component cccurrence
Dim oOcc As ComponentOccurrence, factoryInstance As IAssetInstance

'Access the Browser and Activate the "Bim Content" Browser Pane
Dim oBrowserPanes = ThisApplication.ActiveDocument.BrowserPanes
Dim Model_Browser_Pane As BrowserPane = oBrowserPanes.Item("Model")
Dim oOccNode As BrowserNode

For Each oOcc In oAsmCompDef.Occurrences
	 Try
 If (Not IsFactoryInstance(ThisApplication.ActiveDocument, oOcc, factoryInstance)) Then
  MessageBox.Show(oOcc.Name & " is NOT a Factory Asset", "Title")
 Else 
  oOccNode = Model_Browser_Pane.TopNode.BrowserNodes.Item(oOcc.Name)
  oOccNode.DoSelect
  ChangeAssetTag(ThisApplication.ActiveDocument, oOcc, factoryInstance)
 End If
	Catch
  	End Try

Next

End Sub

'Use this Function To see If the models are Assets
Function IsFactoryInstance(layoutDoc As Document, oOcc As ComponentOccurrence, ByRef factoryInstance As IAssetInstance)
 Dim instances = Autodesk.Factory.PublicAPI.API.Instance.GetAssetInstances(layoutDoc)
 found = False
 For Each instance In instances
  If instance.NativeObject.Equals(oOcc) Then
   factoryInstance = instance
   found = True
   Exit For
  End If
 Next
 Return found
End Function

'The public subroutine will allow the editing of Asset Tags
Public Sub ChangeAssetTag(layoutDoc As Document, oOcc As ComponentOccurrence, Asset_Instance As IAssetInstance)
For Each grp In Asset_Instance.PropertyGroups
 If grp.Name = "AssetTag" Then
  For Each prop In grp.Properties
   If prop.Name = "Asset Tag" Then
	    New_Value = Parameter(oOcc.Name, "ID_Number") & " - " & iProperties.Value(oOcc.Name, "Project" ,"Part Number") 
    	prop.Value = New_Value
   End If
  Next
 End If
Next

'After changed some value, you need To update the instance
Dim ins() As IAssetInstance={Asset_Instance}
Autodesk.Factory.PublicAPI.API.Instance.UpdateAssetInstances(layoutDoc,ins)
End Sub

 

Is it possible to merge these two codes and improve them?

I would like the code to save computer capacity and work faster.

 

Thanks in Advance  

 

 

 

0 Likes
Message 16 of 22

Ralf_Krieg
Advisor
Advisor

Hello

 

I don't have Factory Design Utilities installed, so I can't test it. Maybe it runs anyway.

AddReference "Autodesk.Factory.PublicAPI.dll"
Imports Autodesk.Factory.PublicAPI.Currency.v2

Sub Main()

' Update ID Number
' Item Number = ID Number

Dim oDoc = 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)
	
	Try
		ItemNumber = oBOMRow.ItemNumber
	 	Parameter(CompFileNameOnly, "ID_Number") = ItemNumber
	Catch
	End Try
	
	If IsFactoryInstance(oDoc, oCompDef.Document, factoryInstance)) Then
		ChangeAssetTag(oDoc, oCompDef.Document, factoryInstance)
	End if

Next
iLogicVb.UpdateWhenDone = True

End Sub

'Use this Function To see If the models are Assets
Function IsFactoryInstance(layoutDoc As Document, oDoc As Document, ByRef factoryInstance As IAssetInstance)
	 Dim instances = Autodesk.Factory.PublicAPI.API.Instance.GetAssetInstances(layoutDoc)
	 Dim found as Boolean=False
	 For Each instance In instances
	  If instance.NativeObject.Definition.Document.Equals(oDoc) Then
	   factoryInstance = instance
	   found=true
	   Exit For
	  End If
	 Next
	 
	 Return found
End Function

'The public subroutine will allow the editing of Asset Tags
Public Sub ChangeAssetTag(layoutDoc As Document, oDoc As Document, Asset_Instance As IAssetInstance)
	For Each grp In Asset_Instance.PropertyGroups
	 If grp.Name = "AssetTag" Then
	  For Each prop In grp.Properties
	   If prop.Name = "Asset Tag" Then
			New_Value = Parameter(oDoc.Name, "ID_Number") & " - " & iProperties.Value(oDoc.Name, "Project" ,"Part Number") 
			prop.Value = New_Value
	   End If
	  Next
	 End If
Next

'After changed some value, you need To update the instance
Dim ins() As IAssetInstance={Asset_Instance}
Autodesk.Factory.PublicAPI.API.Instance.UpdateAssetInstances(layoutDoc,ins)
End Sub

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

ejaL9K8H
Advocate
Advocate

This messages is showed:

Error in rule

The public member 'Name' of the type 'PartDocument' was not found.

0 Likes
Message 18 of 22

WCrihfield
Mentor
Mentor

In this line:

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

Try replacing oDoc.Name with oDoc.DisplayName.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 19 of 22

ejaL9K8H
Advocate
Advocate

Still getting an error message:

Error in rule: 

Parameter: The component named "Test" was not found.

0 Likes
Message 20 of 22

WCrihfield
Mentor
Mentor

Hmm.... Just 'shooting from the hip' here, but I'm thinking the problem may still be in that same line.  Sometimes using 'DisplayName' works OK, and sometimes it doesn't, depending on how you have things set-up.  Try using oDoc.FullDocumentName instead of oDoc.DisplayName.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)