- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Updating user parameter with ilogic
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
What do you mean with Factory?
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
For "Factory Design Suite"?
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
What Version of Inventor are you using?
And what vertical are you using, "Factory Design Suite"?
Regards,
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I can't help you with that since I have not Inventor Factory Design installed!
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
(Not an Autodesk Employee)