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: 

Need help creating a rule

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
fakeru
786 Views, 15 Replies

Need help creating a rule

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

Autodesk Inventor 2015 Certified Professional
15 REPLIES 15
Message 2 of 16
jletcher
in reply to: fakeru

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?

Message 3 of 16
fakeru
in reply to: jletcher

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

Autodesk Inventor 2015 Certified Professional
Message 4 of 16
jletcher
in reply to: fakeru

OK this can be done but remind me 1 cubic inch = 0.016387064 liters correct?

Message 5 of 16
jletcher
in reply to: jletcher

Also is this round or square.

Message 6 of 16
jletcher
in reply to: jletcher

Ok if the height is what will change I need to know the width and length of the unit. If round the Diameter.

Message 7 of 16
jletcher
in reply to: jletcher

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...Smiley Happy

Message 8 of 16
fakeru
in reply to: jletcher

Ok, so this is the possible shape of the volume:

 

1.JPG

 

 

Let's say we have the minimum volume:

Untitled.jpg

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:

Untitled2.jpg

 

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!

Autodesk Inventor 2015 Certified Professional
Message 9 of 16
jletcher
in reply to: fakeru

Is this the part? If so post it so I can put the code in it and test..

Message 10 of 16
fakeru
in reply to: fakeru

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!

Autodesk Inventor 2015 Certified Professional
Message 11 of 16
jletcher
in reply to: fakeru

Ok I am on 2012 also so we will be fine there. I have meeting when I get out I will get her done....

Message 12 of 16
fakeru
in reply to: jletcher

Hi  jletcher!

Have you tried or not yet?

Autodesk Inventor 2015 Certified Professional
Message 13 of 16
jletcher
in reply to: fakeru

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...

Message 14 of 16
fakeru
in reply to: jletcher

ok. take your time, it's not urgent for me. thank you very much for your effort!

Autodesk Inventor 2015 Certified Professional
Message 15 of 16
Vladimir.Ananyev
in reply to: fakeru

I’ve slightly modified parameters in your model and add "optimization" rule that calculates desired height using the simplest iterative bisection (dichotomy) method. 

Result.PNG

'********************************************************
'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,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 16 of 16
fakeru
in reply to: Vladimir.Ananyev

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!Smiley Happy

Autodesk Inventor 2015 Certified Professional

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

Post to forums  

Autodesk Design & Make Report