Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic for Part & Assembly Cost Calculations

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
arkelec
913 Views, 4 Replies

iLogic for Part & Assembly Cost Calculations

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?

 

4 REPLIES 4
Message 2 of 5
clutsa
in reply to: arkelec

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
Message 3 of 5
clutsa
in reply to: clutsa

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
Message 4 of 5
chandra.shekar.g
in reply to: clutsa

@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



Message 5 of 5
arkelec
in reply to: clutsa

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report