- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I would love to have a ILogic rules that I could run in my main assembly and that would place the structured item numbers from the BOM into one of the standard Iproperties fields.
My goal is to use it to create a titlefield above views that incluse the Itemnumber of that part / subassembly.
Does one of you have ideas how to do this. I know not enough of programming in ILogic to do it myself.
Thanks,
Greeting from Norway,
Toon
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Similar discussion was had in this thread:
You'll need to change "Parts Only" to "Structured" and the iProperty that you want to use.
BrandonBG
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hei BrandonBG,
Thanks for the tip but when I use that first code I get an error:
Error in rule: Rule1, in document: 7951 P02 Rømningstrapp.iam
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
I ran the rule while standing in the main assembly. Right?
Dim oAssemblyDocument As AssemblyDocument
oAssemblyDocument= ThisDoc.Document
Dim oAssemblyComponentDefinition As AssemblyComponentDefinition
oAssemblyComponentDefinition = oAssemblyDocument.ComponentDefinition
Dim oBOM As BOM
oBOM = oAssemblyComponentDefinition.BOM
oBOM.PartsOnlyViewEnabled = True
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Parts Only") 'or structured
For Each oBOMRow As BOMRow In oBOMView.BOMRows
Dim oComponentDefinition As ComponentDefinition
oComponentDefinition = oBOMRow.ComponentDefinitions.Item(1)
Dim oBOMItemNumber As String
oBOMItemNumber = oBOMRow.ItemNumber() 'this is item number in the BOM
MessageBox.Show(oBOMItemNumber, "BOM Number") 'just to show what's going on
Dim oComponentDefinitionPropertySet As PropertySet
oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item("Inventor User Defined Properties")
'custom property tab
oComponentDefinitionPropertySet.Add(oBOMItemNumber, "BOM Number")
'creates the custom property and inputs the value
Next
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Do you have sub-assemblies? That iLogic isn't built to handle sub-assemblies. You need to run it inside the assembly that contains the .ipt to which you want to assign the new iProperty.
Brandon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, i've had the same problem. This is the rule that i used. Hope this helps you...
Sub Main
Dim oAssemblyDocument As AssemblyDocument
oAssemblyDocument = ThisDoc.Document
Dim oAssemblyComponentDefinition As AssemblyComponentDefinition
oAssemblyComponentDefinition = oAssemblyDocument.ComponentDefinition
Dim oBOM As BOM
oBOM = oAssemblyComponentDefinition.BOM
oBom.StructuredViewEnabled = True
Dim oBOMView As BOMView
oBOMView = oBom.BOMViews(2) 'Structured view
oBom.StructuredViewFirstLevelOnly = False
oBom.StructuredViewDelimiter = "."
Call RecursiveCheckAndSetProps(oBOMView.BOMRows)
End Sub
Sub RecursiveCheckAndSetProps(ByVal oRowsElements As BOMRowsEnumerator)
For Each oBOMRow As BOMRow In oRowsElements
Dim oComponentDefinition As ComponentDefinition
oComponentDefinition = oBOMRow.ComponentDefinitions.Item(1)
Dim oBOMItemNumber As String
oBOMItemNumber = oBOMRow.ItemNumber() 'this is item number in the BOM
' MessageBox.Show(oBOMItemNumber, "BOM Number") 'just to show what's going on
Dim oComponentDefinitionPropertySet As PropertySet
oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item("Inventor User Defined Properties")
'custom property tab
Try
'if already exists then set it
oComponentDefinitionPropertySet.Item("BOM Number").Value = oBOMItemNumber
Catch ex As Exception
'else add it
oComponentDefinitionPropertySet.Add(oBOMItemNumber, "BOM Number")
End Try
'creates the custom property and inputs the value
If Not oBOMRow.ChildRows Is Nothing Then
Call RecursiveCheckAndSetProps(oBOMRow.ChildRows)
End If
Next
End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hallo Fulvio81,
Thanks for your reaction. But when I take your code to make a rule it returns with an error. I made the rule in the main ****. Is that correct.
This is the more info from the error:
System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.BOMViews.get_Item(Object Index)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
What am I doing wrong?
Toon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I found it out myself. The assembly was not in the master Level of Detail. After switching it worked fine. Thanks agian. Now I can play with it to make it do what I want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have to aks for help one more time. The code I got works fine but I was trying to modify it so that the itemnumber is being saved in one of the standard Iproperties fields (for example in Project) and not in a custom field.
I think it is in this part of the code:
SyntaxEditor Code Snippet
Dim oComponentDefinitionPropertySet As PropertySet oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item("Inventor User Defined Properties") 'custom property tab Try 'if already exists then set it oComponentDefinitionPropertySet.Item("BOM Number").Value = oBOMItemNumber Catch ex As Exception 'else add it oComponentDefinitionPropertySet.Add(oBOMItemNumber, "BOM Number") End Try 'creates the custom property and inputs the value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
you can replace it with
Dim oComponentDefinitionPropertySet As PropertySet oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item(2) 'design tracking oComponentDefinitionPropertySet.ItemByPropId(Inventor.PropertiesForDesignTrackingPropertiesEnum.kProjectDesignTrackingProperties).Value = oBOMItemNumber
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Final revised version including both option (custom iProperty and project iProperty)
there was an error
PropertySets.Item(3)'correct instead of (2)'wrong
Sub Main()
Dim oAssemblyDocument As AssemblyDocument
oAssemblyDocument = ThisDoc.Document
Dim oAssemblyComponentDefinition As AssemblyComponentDefinition
oAssemblyComponentDefinition = oAssemblyDocument.ComponentDefinition
Dim oBOM As BOM
oBOM = oAssemblyComponentDefinition.BOM
oBom.StructuredViewEnabled = True
Dim oBOMView As BOMView
oBOMView = oBom.BOMViews(2) 'Structured view
oBom.StructuredViewFirstLevelOnly = False
oBom.StructuredViewDelimiter = "."
Call RecursiveCheckAndSetProps(oBOMView.BOMRows)
End Sub
Sub RecursiveCheckAndSetProps(ByVal oRowsElements As BOMRowsEnumerator)
For Each oBOMRow As BOMRow In oRowsElements
Dim oComponentDefinition As ComponentDefinition
oComponentDefinition = oBOMRow.ComponentDefinitions.Item(1)
Dim oBOMItemNumber As String
oBOMItemNumber = oBOMRow.ItemNumber() 'this is item number in the BOM
' MessageBox.Show(oBOMItemNumber, "BOM Number") 'just to show what's going on
' 'if you want standard iproperty (e.g. "project")
Dim oComponentDefinitionPropertySet As PropertySet
oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item(3) 'design tracking
oComponentDefinitionPropertySet.ItemByPropId(7).Value = oBOMItemNumber '7 is project property
' 'if you want custom iproperty then
' Dim oComponentDefinitionPropertySet As PropertySet
' oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item("Inventor User Defined Properties")
' 'custom property tab
' Try
' 'if already exists then set it
' oComponentDefinitionPropertySet.Item("BOM Number").Value = oBOMItemNumber
' Catch ex As Exception
' 'else add it
' oComponentDefinitionPropertySet.Add(oBOMItemNumber, "BOM Number")
' End Try
' 'creates the custom property and inputs the value
If Not oBOMRow.ChildRows Is Nothing Then
Call RecursiveCheckAndSetProps(oBOMRow.ChildRows)
End If
Next
End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi toolsol,
You might want to consider an alternative method of getting the item number and quantity to show for a particular part. One downside to the method you are currently using is that if a component is assembled in more than one assembly (or is inside a subassembly that is reused), then the custom iproperty you've created for the quantity, is incorrect and misleading.
This video shows a more robust way of showing filtered information from the BOM in a parts list. You'll probably be interested in 4 minutes 36 seconds onwards.
https://www.youtube.com/watch?t=277&v=qem8o-R2mqQ
The app shown on the video is on the Autodesk exchange apps website here:
Thanks,
Luke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
How I wish that this would work for me! This is to be run within an .IAM, right? Are changes required for use in Inventor 2019? I am getting the following error:
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.Property.set_Value(Object )
at ThisRule.RecursiveCheckAndSetProps(BOMRowsEnumerator oRowsElements)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi!
Hi!!
The code is running well at some point, except these two points:
An error arises and i think it's because of:
1- I use a LOD iLogic
2- I have library and content center parts
The questions are:
A) how can i avoid the error message?
(I tried the " on error resume", but it's incompatible with the "try" statement).
(Also tried the "if the part is modificable= true then", but i think this will not work for this case).
B) The code will work for a LOD other than Master?
Thanks
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good morning everyone.
I'm looking for something that look like this, but would love to have a ilogic code that make it the other way around.
For example.
I have a standard propertie, for example "Keywords" with the value "1" and use it as my value for the item number.
Could some one so nice and give me some help for that?