- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm developing a universal code to use in all my part templates that will calculate the labour costs of the part. Part of the rule needs to search through the custom iProperties and find unique operational codes that have timing values inside them and use those values to calculate the cost. Here is a snippet of the code I have so far:
'Calculate glass labour cost If iProperties.Value("Custom", "GLASS_SET") > 0 Then glass_labour_set = (iProperties.Value("Custom", "GLASS_SET")/60)*glass_labour_rate glass_labour_run = (iProperties.Value("Custom", "GLASS_RUN")/60)*glass_labour_rate End If 'Calculate sheet metal labour cost If iProperties.Value("Custom", "PUNCH_SET") > 0 Then punch_labour_set = (iProperties.Value("Custom", "PUNCH_SET")/60)*punch_labour_rate punch_labour_run = (iProperties.Value("Custom", "PUNCH_RUN")/60)*punch_labour_rate End If
How can I get the code to skip an IF statement if the iProperty doesn't exist? For example when the rule runs in a glass part, it throws up an error and says it cannot find a property names "PUNCH_SET" because the glass part only has GLASS_RUN and GLASS_SET in it.
Any help would be much appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
link to a great blog post by Curtis Waguespack - http://inventortrenches.blogspot.com/2011/05/use-ilogic-to-add-and-use-custom.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Try
glass_labour_set = (iProperties.Value("Custom", "GLASS_SET")/60)*glass_labour_rate
Catch
End TryHere's an example of the Try Catch for one of your custom iProps.
Downside is you'd have to place each of your custom iprops in its own one.
This is another option:
On Error Resume Next
Fairly self explanatory, if it hits an error, like a missing custom iProp it will move onto the next line of code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks for both your replies. In the end I went with placing each property in between a Try/Catch block, which works great. The code does seem overly long for what I'm trying to achieve, I especially don't like the last line that totals everything up.
I've attached the full code below for those interested, if anyone has the time to take a look at it and make some suggestions as to how I can improve it/make it more manageable I'd appreciate it very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Could you not add the running total in each try/catch block?
You wouldn't need the really long statement at the end...
Try
SAW_labour_set = (iProperties.Value("Custom", "SAW_SET")/60)*SAW_labour_rate
SAW_labour_run = (iProperties.Value("Custom", "SAW_RUN")/60)*SAW_labour_rate
' SAW_labour = SAW_labour_set + SAW_labour_run
labour_total += SAW_labout_set + SAW_labour_run
Catch
End Try
Try
CNCF_labour_set = (iProperties.Value("Custom", "CNCF_SET")/60)*CNCF_labour_rate
CNCF_labour_run = (iProperties.Value("Custom", "CNCF_RUN")/60)*CNCF_labour_rate
' CNCF_labour = CNCF_labour_set + CNCF_labour_run
labour_total += CNCF_labour_set + CNCF_labour_run
Catch
End TryAlso, found this link..
See post #5, interesting approach to keeping track of multiple custom iProperties.
Yet another approach, setup a custom class for your labor, erh... labour costs with a module in the class to add all of values the in the custom class.
http://blogs.rand.com/manufacturing/2011/12/if-this-then-ilogic.html
Good luck and let us know how your final project turns out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks Yosso, I think I prefer the method in the 1st link you sent.
I've gotten this far with it (for now just testing with four iProperties). I think I'm going wrong with the line highlighted in red
customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties") Dim iprop(4) As String iprop(1) = "GLASS_RUN" iprop(2) = "GLASS_SET" iprop(3) = "BPG_RUN" iprop(4) = "BPG_SET" For k = 1 To 4 Dim prop(k) As String Try prop(k) = iProperties.Value("Custom", iprop(k)) total_labour = (iProperties.Value("Custom", prop(k))/60)*20 Catch End Try Next
Any idea how I can total up all the values of the iProperties and include that total in my equation?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You'll need to convert the iProp(k) string value to a numeric value....
SyntaxEditor Code Snippet
Option Explicit Dim iprop(4) As String iprop(1) = "GLASS_RUN" iprop(2) = "GLASS_SET" iprop(3) = "BPG_RUN" iprop(4) = "BPG_SET" Dim dRate As Double Dim dTotalLabour As Double For k = 1 To 4 Try dRate = CDbl(iProperties.Value("Custom", iprop(k))) dTotalLabour = ((dRate/60)*20) + dTotalLabour Catch End Try Next MessageBox.Show ("Total Labour : $" & CStr(Round(dTotalLabour,2)),"Debug Me")
Hope this helps. Sorry for the delay, was away from computer and attempted to reply earlier via my phone...