Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
JelteDeJong
in reply to: adam.mangan

I don't know a way to add cost to a material. Instead, you can save the data in an iLogic rule (or a separate file but that is not in this example). just add the material and cost to the top of the rule.

Public Class ThisRule
    Sub Main()
        Dim costs As New Dictionary(Of String, materialCost)
        ' Add material and csot here.
        ' costs.Add("[Material name]", New materialCost([Material cost (../Kg)], [Surface treatment cost (../Cm^2)]))
        costs.Add("Generic", New materialCost(10, 30))
        costs.Add("Brass, Soft Yellow", New materialCost(20, 0))

        Dim doc As PartDocument = ThisDoc.Document
        Dim materialName = doc.ActiveMaterial.DisplayName

        If (costs.ContainsKey(materialName)) Then
            ' mass is in Kg
            Dim mass = doc.ComponentDefinition.MassProperties.Mass
            ' area is in Cm^2
            Dim area = doc.ComponentDefinition.MassProperties.Area

            Dim cost As materialCost = costs.Item(materialName)
            Dim materialCost = mass * cost.Material
            Dim surfaceTreatmentCost = area * cost.SurfaceTreatment
            Dim totalCost = materialCost + surfaceTreatmentCost
            Dim txt = "Material: " & materialCost & System.Environment.NewLine
            txt = txt + "Surface treatment: " & surfaceTreatmentCost & System.Environment.NewLine
            txt = txt + "Total: " & totalCost
            MsgBox(txt)
        Else
            MsgBox("Unable to calculate cost for material: " & materialName)
        End If

    End Sub
End Class

Public Class materialCost
    Public Sub New(material As Double, surfaceTreatment As Double)
        Me.Material = material
        Me.SurfaceTreatment = surfaceTreatment
    End Sub
    Public Property Material As Double
    Public Property SurfaceTreatment As Double
End Class

 

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