For this experiment I have some geometry that must maintain a particular weight as my part changes. As features are added, subtracted or modified the diameter of the large outer cylinder is the variable that must change to meet the target weight.
To make it easy to modify the critical values of the part I've created a few user parameters and assembled them together in a nice tidy little form.
The code will evaluate the "mass target" value and begin to increment the outer diameter up or down until the value matches the actual mass (or as close as it can get within the given increment).
The user can make multiple changes to the variables and with one click of a button find the new value of the outer diameter!
To facilitate the experiment I created one custom iProperty called "Weight" that I will reference in the form. (I could use the actual "lbsmass" iProperty value from the model but this method will allow me to control the rounding factor of the value with a line of code).
I created some custom parameters and linked the model parameters to them accordingly:
Finally I added an iLogic rule that will do all the work:
iProperties.Material = Material
If iProperties.Mass < TargetMass Then
While iProperties.Mass < TargetMass
Diameter = Diameter + .031
RuleParametersOutput()
InventorVb.DocumentUpdate(True)
End While
ElseIf iProperties.Mass > TargetMass Then
While iProperties.Mass > TargetMass
Diameter = Diameter - .031
RuleParametersOutput()
InventorVb.DocumentUpdate(True)
End While
End If
iProperties.Value("Custom", "Weight")= iProperties.Mass
iProperties.Value("Custom", "Weight") = Round(iProperties.Mass, 2)
ThisApplication.ActiveView.Update()
Now any change to the model geometry will prompt the code to search for a diameter that satisfies my targeted mass requirement.
MAGIC!
Download the sample file below and let me know if you can think of other ways code like this can help you automate your designs.
Hi.
Im just wondering about somethin in the iLogic.
I see in the rule that you have an expression saying that
While iProperties.Mass < TargetMass
Diameter = Diameter + .031
RuleParametersOutput()
InventorVb.DocumentUpdate(True)
End While
What does the number .031 stands for?
Correct me if i'm wrong.
As im thinking you need an formula that calculates the volume of the part and then multiple it with the density of the material to get the correct mass.
Where is this formula?
Another question;
I see in the paramaters that you have an line that says vParam_Designer. What is this?
As you already have guessed i am pretty new to iLogic. Do you know about any good tutorials or where to begin?
You must excuse my English because I am just an ordinary Norwegian ;-)
Posted by: Kenneth | 02/02/2012 at 09:45 AM
Hi Kenneth,
The .031 is the fraction I am increasing/decreasing the diameter. Using this method I am only only going to get close (although very close) to the true Target Mass value.
If you are looking to get an exact match, then a formula involving your equation of volume*density would be the way to go.
That "vParam_Designer" parameter is just something leftover from another experiment and has nothing to do with this exercise. Sorry for the confusion.
Posted by: Carl | 02/02/2012 at 04:46 PM