Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

How to assign Structured Item numbers to a Iproperties field

Anonymous

How to assign Structured Item numbers to a Iproperties field

Anonymous
Not applicable

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

0 Likes
Reply
Accepted solutions (2)
1,691 Views
17 Replies
Replies (17)

BrandonBG
Collaborator
Collaborator

Similar discussion was had in this thread:

 

http://forums.autodesk.com/t5/inventor-customization/make-a-custom-iproperty-equal-to-the-item-in-th...

 

You'll need to change "Parts Only" to "Structured" and the iProperty that you want to use.

 

BrandonBG

0 Likes

Anonymous
Not applicable

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

 

 

 

0 Likes

BrandonBG
Collaborator
Collaborator

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

0 Likes

Anonymous
Not applicable

That's a bummer. I have always a mix of parts and sub assemblies in my main assembly.

 

Toon

0 Likes

fulvio81
Contributor
Contributor
Accepted solution

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
		

Anonymous
Not applicable

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

0 Likes

Anonymous
Not applicable

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.

 

0 Likes

Anonymous
Not applicable

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
0 Likes

fulvio81
Contributor
Contributor
you can replace it with
Dim oComponentDefinitionPropertySet As PropertySet
oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item(2) 'design tracking
oComponentDefinitionPropertySet.ItemByPropId(Inventor.PropertiesForDesignTrackingPropertiesEnum.kProjectDesignTrackingProperties).Value = oBOMItemNumber

fulvio81
Contributor
Contributor
Accepted solution

 

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

 

Anonymous
Not applicable

Thanks you very much for your help. Inventor_1.png

Now I have the itemnumber and the amount in the viewtitle.

 

Toon

0 Likes

LukeDavenport
Collaborator
Collaborator

 

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:

 

https://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3aviewr...

 

Thanks,
Luke

 

 

0 Likes

RogerTheShrubber
Advocate
Advocate

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)

0 Likes

RogerTheShrubber
Advocate
Advocate

Turns out that one of the parts is in a Read Only library location, causing the error.

The code works beautifully. Thank you, 

0 Likes

CCarreiras
Mentor
Mentor

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

CCarreiras

EESignature

0 Likes

CCarreiras
Mentor
Mentor

.

CCarreiras

EESignature

0 Likes

Anonymous
Not applicable

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?

 

 

0 Likes