Get the quantity using ILogic code

Get the quantity using ILogic code

FINET_Laurent
Advisor Advisor
1,177 Views
6 Replies
Message 1 of 7

Get the quantity using ILogic code

FINET_Laurent
Advisor
Advisor

Morning everyone.

 

I whould like to know if it is possible to get the quantity of a part and set this quantity as a double using ilogic in an assembly. (not a custom iproperty)

I'm talking about the part quantity shown in the default BOM. 😥

 

Thanks and best regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Accepted solutions (1)
1,178 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor

Hi @FINET_Laurent 

Try this:

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oBOM As BOM = oAsm.ComponentDefinition.BOM
Dim oBomView As BOMView = oBOM.BOMViews(1)
Dim oBomRows As BOMRowsEnumerator = oBomView.BOMRows
Dim oBomRow As BOMRow
Dim oDef As ComponentDefinition

For Each oBomRow In oBomRows
	Try
		If oBomRow.ComponentDefinitions(1).Document.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = "Part number here"
			oBomRow.TotalQuantity = 80 'Quantity
		End If
	Catch
	End Try
Next

Just fill in your parts part number and the quantity you want.

Message 3 of 7

Daan_M
Collaborator
Collaborator

Hi, 

 

You can try something like this

iLogicVb.UpdateWhenDone = True

Dim PartQuantity As Double = 0
Dim test As String


Dim oAsm As AssemblyDocument = ThisDoc.Document
For Each oRefDoc As Document In oAsm.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject AndAlso _
		oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc).Count > 0 AndAlso
		oRefDoc.DisplayName = "Part or member name of part document"
		PartQuantity = PartQuantity + 1
		On Error Resume Next
	End If
	Next
	
	MsgBox(PartQuantity) 'do something with the quantity here
Message 4 of 7

JhoelForshav
Mentor
Mentor

Oh I get it now I think... You just want to store the value in a double? Since it's not a decimal value, I'd suggest an Integer instead.

 

Just count the referenced occurrences of the part in the assembly:

Dim oAsm = ThisDoc.Document
Dim oPartOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Pick part")
Dim oPart As PartDocument = oPartOcc.Definition.Document
Dim oQty As Integer = oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oPart).Count

MsgBox(oQty)
Message 5 of 7

FINET_Laurent
Advisor
Advisor

First of all thank you, it works perfectly as intended but I have an other question.

Is it possible to target the part name using a string (part1.ipt)  instead of clicking the actual part.

 

Thanks and have a nice day,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 6 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

@FINET_Laurent 

Something like this maybe? 🙂

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim partName As String = "Part1.ipt"
Dim oQty As Integer = 0
For Each oRefDoc As Document In oAsm.AllReferencedDocuments
If oRefDoc.FullFileName.EndsWith(partName)
oQty = oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc).Count
Exit For
End If
Next
MsgBox(oQty)

Or if you rather use displayname (no file extension)

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim partName As String = "Part1"
Dim oQty As Integer = 0
For Each oRefDoc As Document In oAsm.AllReferencedDocuments
If oRefDoc.DisplayName = partName
oQty = oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc).Count
Exit For
End If
Next
MsgBox(oQty)
Message 7 of 7

FINET_Laurent
Advisor
Advisor

This is exactly what I needed !

Thank you for sharing knowledge ! 🙂

 

Have a nice day,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill