Stock length quantity multiplier.

Stock length quantity multiplier.

Stahle
Contributor Contributor
433 Views
1 Reply
Message 1 of 2

Stock length quantity multiplier.

Stahle
Contributor
Contributor

I am new to iLogic and very rusty at programming. The scenario I have been working on that i can't seem to get correct is taking the cut length of my part and multiplying it by the quantity to provide a stock total. This is all working with iProperties. I can get it to work to an extent but I need some help with some issues.

My “code” is shown below and is probably very rudimentary and incorrect.

Here are my issues:

  • The iproperty "ipwModelExtents3" is created from iPropWiz 7 (from Neil Munro at www.c3mcad.com). He created some code to give me a “StockSize” based on the model extents. When you start a new part that does not have this iproperty, it faults out. I have tried to get around this, but to no avail.
  • We set the “Part QTY” manually and I want to multiply the length value of the stock to provide a “totalstocklenght”.
  • This works fine when using this code on existing parts, but does not work with new parts created from the default.ipt
  • When the value is written to the “totalstocklength”, I would like it to show 3 place decimal. It will only do that if the number requires is (i.e. 11.237 etc.) but if it is just 11, then it only shows as 11 without the decimal.

I know these things are very simple for an experienced programmer, but that is not me

Any help or suggestions is greatly appreciated. We are in-process of simplifying our stock counting as well as automating some other processes so the sooner the better.

Thanks in advance for you help! Don't berate me too bad......LOL

 

 

 

Code as follows:

 

 

doc = ThisDoc.Document

'unit manager of the document

oUOM = doc.UnitsOfMeasure

 

If ipwModelExtents3 = Nothing Then

        GoTo Skip

       

Else ipwModelExtents3 = "0"

       

End If

 

'get the value of each part length

partlength = iProperties.Value("Custom", "ipwModelExtents3")

iProperties.Value("custom", "partlength") = partlength

 

'set part quantity as quantity from ipw PART QTY

partquantity = iProperties.Value("Custom", "PART QTY")

 

'multiply individual lenth by quantity to get totalstocklength

totalstocklength = partlength * partquantity

 

iProperties.Value("Custom", "totalstocklength") = totalstocklength

totalstocklength = totalstocklength.ToString () + ""

 

Skip:

 

 

 

 

 

 

0 Likes
Accepted solutions (1)
434 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor
Accepted solution

Is this a 'local' or external iLogic rule?  Is there both a local parameter, and a local iProperty, both named "ipwModelExtents3"?  Are any of the other iProperties in this rule the same way (iProperty & Parameter with the same name)?  If so, is that parameter a text type user parameter, or a numerical value parameter?  Either way you wouldn't check it's value against 'Nothing'.   A numerical parameter will always have a value, but it may be zero.  A text type user parameter, if it were 'empty' would still contain an empty string, like "" or String.Empty.  If it is a text type parameter, you won't be able to multiply its value by the (hopefully numerical) value of the 'PART QTY' property.  If you want to set a numerical value to an iProperty, don't put quotation marks around the value you assign it.  If you do assign an iProperty numbers that are quoted (to avoid any possible conversions or something), you will need to convert its value later back to numerical, before you can use it in a mathematical scenario.

Here is one version of an alternative iLogic rule:

doc = ThisDoc.Document
'unit manager of the document
oUOM = doc.UnitsOfMeasure
oCustomProps = doc.PropertySets.Item("Inventor User Defined Properties")

Dim oME3 As Inventor.Property
Try
	oME3 = oCustomProps.Item("ipwModelExtents3")
Catch
	oME3 = oCustomProps.Add(0, "ipwModelExtents3")
End Try

Dim oPartLength As Inventor.Property
Try
	oPartLength = oCustomProps.Item("partlength")
	oPartLength.Value = oME3.Value
Catch
	oPartLength = oCustomProps.Add(oME3.Value, "partlength")
End Try

Dim oPartQTY As Inventor.Property
Try
	oPartQTY = oCustomProps.Item("PART QTY")
Catch
	'it didn't find this pivotal property, so exit the rule
	'oPartQTY = oCustomProps.Add(0, "PART QTY")
	MsgBox("Didn't find the iProperty named 'PART QTY'.  Exiting Rule.", vbExclamation, "iLogic")
	Return 'or Exit Sub
End Try

'multiply individual lenth by quantity to get totalstocklength
totalstocklength = oPartLength.Value * oPartQTY.Value

Dim oTotalStockLength As Inventor.Property
Try
	oTotalStockLength = oCustomProps.Item("totalstocklength")
	oTotalStockLength.Value = totalstocklength
Catch
	oTotalStockLength = oCustomProps.Add(totalstocklength, "totalstocklength")
End Try

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes