Hello everyone!
I need some help creating a rule that does the following:
It finds a value for a parameter which will make a condition possible.
For example I need Volume1 to be equal to ProductVolume.
Volume1 is the input value which I will give everytime I will create the part. Then I need the rule to change (or to find) a parameter value that ProductVolume depends on for until the 2 volume parameters are equal.
I thought it should start like this:
If Volume1<>ProductVolume Then
End If
Please help!
Regards
Sandu
Solved! Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
What is going to change for the Volume1 to = ProductVolume thickness, length, width, material type?
You say you will place Volume1 when you create the part and wish for what to change for it to =ProductVolume?
The height will change the ProductVolume making it equal to Volume1.
The part will be published to Content Center and initially will have a certain ProductVolume, let's say 345 L
When placing it in the assembly I want the part to have that ProductVolume let's say 500 L. The input parameter will be Volume1 and I will give it 500 L, next the rule should change the height for the condition to be true: ProductVolume=Volume1
I will mention that ProductVolume is a physical property of body, it can not be changed unless you change a dimension, and that is the "height" in my case.
Hope that's clear and make some sense for you.
Cheers
Ok have some of the code done need your info to finish it up..... I found I was right on the cubic in to liters so just waiting on you...
Ok, so this is the possible shape of the volume:
Let's say we have the minimum volume:
The parameter with the value=25 is the one that will change the volume, so it will go only bigger.
And we can have something like that:
So let's say that the template part from CC will have the minimum volume admitted, let's say 10L. So our desired volume will be equal or bigger than this volume.
I thought to use formulas for calculating the volume of cylinder and cone, but the shape can be more complicated that these. Like you can see in this example the cone is an excentric one.
Hope I'm quite clear about all the things.
Thanks!
Ok.
I have made it again, in INV 2012. I have defined already the parameters. One is driven by the Rule0.
You will find the part attached.
Thanks!
Yes I am on it just trying to make it faster don't like the way it is updating. So I am trying a few things out.
If you go from 500L to 1000L or so lets say it takes a few minutes to complete so I am tryig a few things to speed it up should have it posted later today.
Monday is bad for me I have like 10 clients I have to go have meetings with see if they need anything then I should be able to finish it up...
ok. take your time, it's not urgent for me. thank you very much for your effort!
I’ve slightly modified parameters in your model and add "optimization" rule that calculates desired height using the simplest iterative bisection (dichotomy) method.
'******************************************************** 'this rule adjust the value of Height model parameter 'to get the part volume equal to TargetVolume '******************************************************** 'TargetVolume - target volume 'HLowerLimit - Lower heifht limit - HLowLimit 'HUpperLimit - Upper height limit - HUpperLimit 'NMax - maximal number of iterations - 'RelErr - Relative error '******************************************************** 'maximal number of iterations Dim NMax As Integer = 30 'Relative error Dim RelErr As Double = 0.00001 '******************************************************** ThisDoc.Save Dim oDoc As PartDocument = ThisDoc.Document Dim oUOM As UnitsOfMeasure = oDoc.UnitsOfMeasure Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition Dim oPars As Parameters = oDef.Parameters Dim oMassProps As MassProperties = oDef.MassProperties oMassProps.Accuracy = MassPropertiesAccuracyEnum.k_Medium 'Input data Dim Hmax As Double = oPars.Item("HUpperLimit").Value Dim Hmin As Double = oPars.Item("HLowerLimit").Value Dim Target_Volume As Double = oPars.Item("TargetVolume").Value 'control height. Volume is driven by this parameter Dim oModelPar As ModelParameter = oPars.ModelParameters.Item("Height") Dim N As Integer = 0 Dim H As Double = (Hmin + Hmax) / 2 oModelPar.Value = H oDoc.Update Dim V As Double = oMassProps.Volume Do While (N <= NMax) And (Math.Abs(V - Target_Volume)/Target_Volume > RelErr) N = N + 1 If (V - Target_Volume) > 0 Then Hmax = H Else Hmin = H End If H = (Hmin + Hmax) / 2 oModelPar.Value = H oDoc.Update V = oMassProps.Volume ThisApplication.activeview.update Loop oDoc.Update oPars.Item("Current_Volume").Value = V Dim delta As Double = Math.Abs(V - Target_Volume)/Target_Volume 'report MsgBox ("N = " & N & vbNewLine & "V = " & _ oUOM.GetStringFromValue(V, "l") & vbNewLine & _ "Delta = " & delta) '********************************************************
Updated version of your part is attached.
Hope this rule is a good start point to move further.
Cheers,
This rule looks very good. I think it is just what I need. Probably I will have to tweak it a little bit, as it will run for a multibody part. Hope it will work.
Thank you very much Vladimir!
Spasibo!