iLogic for Part & Assembly Cost Calculations

arkelec
Collaborator
Collaborator

iLogic for Part & Assembly Cost Calculations

arkelec
Collaborator
Collaborator

I want to use an external rule to add iProps & then use any field data already present to calculate cost.

 

The adding of the iProps is (for the most), sorted.  What I need to do next is:

 

  1. Convert text from iProps to numbers
  2. Perform a calculation using two or more of the conversions
  3. Populate the calc result to another iProp

 

So I want "Unit_Buy".  This will be the result of "Unit_Trade" with "Discount" applied.

 

Here's what I have so far for the conversion of "Unit_Trade":

Dim Unit_Trade As String = iPropGetStr("Unit_Trade", "0")
Dim Unit_Trade_NUM As Integer = iPropGetStr("Unit_Trade_NUM", (Int32.TryParse(Unit_Trade, Unit_Trade_NUM)))
Dim Discount As String = iPropGetStr("Discount", "0")
Dim Discount_NUM As Integer = iPropGetStr("Discount_NUM",Int32.TryParse("Discount", Discount_NUM))

 

During the development of the iLogic, I've added an iProp from "Unit_Trade_NUM" so I can see if it works.  It doesn't.  The iProp is added with the format YES/NO.

 

The workflow at present is:

 

  1. Run the rule
  2. Add data to the empty fields on a form that loads
  3. Close form & re-run rule

Before each time for step 1 above, I make sure any existing iProp with the format Y/N is deleted, so the rule will add it.

 

I'm not sue if I've got the syntax for the TryParse correct, or have I have missed something else entirely?

 

0 Likes
Reply
Accepted solutions (1)
955 Views
4 Replies
Replies (4)

clutsa
Collaborator
Collaborator

So this seems to work for me even though it doesn't seem like it should.

Dim Unit_Trade As String = iProperties.Value("Custom", "Unit_Trade")
Dim Discount As String = iProperties.Value("Custom", "Discount")
Dim Unit_Buy As Double = Unit_Trade * Discount
iProperties.Value("Custom", "Unit_Buy") = Unit_Buy
MessageBox.Show(iProperties.Value("Custom", "Unit_Buy"), "Title")
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

clutsa
Collaborator
Collaborator
Accepted solution

This does a bit more to help get your text to a number format if you don't have only numbers as the text.

 

Dim Unit_Trade As String = iProperties.Value("Custom", "Unit_Trade")
'MessageBox.Show("Unit_Trade = " & Unit_Trade, "Title")
Dim Unit_Trade_Num As Double = Val(Replace(Unit_Trade,"$","")) 'Val returned '0' if preceded by '$' 
'MessageBox.Show("Unit_Trade_Num = " & Unit_Trade_Num, "Title")
Dim Discount As String = iProperties.Value("Custom", "Discount") 'discount is enter as '20%' 
Dim Discount_Num As Double = Val(Discount) / 100 'val returns '20' not '.20' as we need for a percent
Dim Unit_Buy As Double = Unit_Trade_Num * Discount_Num
iProperties.Value("Custom", "Unit_Buy") = Unit_Buy
'MessageBox.Show("Unit_Buy = " & iProperties.Value("Custom", "Unit_Buy"), "Title")

There is also "CDblAny(myString)" you can try if "Val(myString)" isn't working for you.

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

chandra.shekar.g
Autodesk Support
Autodesk Support

@arkelec,

 

If value of custom iProperty is either "True" or "False", delete the existing custom iProperty. For deleting custom iProperty, refer the answered post in below forum discussion link.

 

https://forums.autodesk.com/t5/inventor-forum/how-to-remove-custom-iproperty-with-ilogic/td-p/436406...

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



arkelec
Collaborator
Collaborator

Thanks for the replies.  Apologies for the late reply, but work stuff etc.

In the end, I re-structured the whole thing & then most recently, have engaged someone to assist with the wider customising tasks.

The Boolean issue was because I was using an incorrect function.

Thanks again.

0 Likes