How to put a specific part to Lock Items on/off in Bill of materials using Ilogic

How to put a specific part to Lock Items on/off in Bill of materials using Ilogic

manu.marjanen
Advocate Advocate
402 Views
4 Replies
Message 1 of 5

How to put a specific part to Lock Items on/off in Bill of materials using Ilogic

manu.marjanen
Advocate
Advocate

How to put a specific part to Lock items on/off in Bill of materials using Ilogic?

For example,  if Iproperties custom fields says "Locked" then those specified parts Lock Items go ON in Bill of materials. 

And the other way, if Iproperties custom fields says "UnLocked" then those a specified parts Lock Items go OFF in Bill of materials.

 

manumarjanen_0-1630770100818.png

 

0 Likes
Accepted solutions (1)
403 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor

This example will lock the item in the first row

Dim doc As AssemblyDocument = ThisDoc.Document
Dim def As AssemblyComponentDefinition = doc.ComponentDefinition
Dim bom As BOM = def.BOM
bom.StructuredViewEnabled = True
Dim bomView As BOMView = bom.BOMViews.Item("Structured")

Dim firstBomRow As BOMRow = bomView.BOMRows.Item(1)
Logger.Info("Lock item with number: " + firstBomRow.ItemNumber)
firstBomRow.ItemNumberLocked = True

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 5

manu.marjanen
Advocate
Advocate

Thanks for your quick answer.

Now the code is locking the first row, but can you edit the code so that it is locking part names individually (Part:1)?

 

0 Likes
Message 4 of 5

JelteDeJong
Mentor
Mentor
Accepted solution

something like this:

' set name of occurence here
Dim name As String = "Part:1"

Dim doc As AssemblyDocument = ThisDoc.Document
Dim def As AssemblyComponentDefinition = doc.ComponentDefinition
Dim bom As BOM = def.BOM
bom.StructuredViewEnabled = True
Dim bomView As BOMView = bom.BOMViews.Item("Structured")

Dim rows = bomView.BOMRows.Cast(Of BOMRow)

Dim row = rows.Where(Function(r)
                         Dim occs = r.ComponentOccurrences.Cast(Of ComponentOccurrence)
                         Dim occ = occs.Where(Function(o) o.Name.Equals(name)).FirstOrDefault()
                         Return (occ IsNot Nothing)
                     End Function ).FirstOrDefault()
					 
Logger.Info("Lock item with number: " + row.ItemNumber)
row.ItemNumberLocked = True

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 5

manu.marjanen
Advocate
Advocate

Yes, this is just what i needed. Thanks a lot 😀

0 Likes