Using iLogic to code a random polygon

Using iLogic to code a random polygon

morrig14
Participant Participant
969 Views
10 Replies
Message 1 of 11

Using iLogic to code a random polygon

morrig14
Participant
Participant

Hello!

 

I've been trying to make a rule that creates a random closed polygon, but have been running into some complications. The end goal is to make 2 random polygons the have a loft between them.

 

In my previous approach, I made a generic shape by placing a bunch of points then making a spline between them. Then through I rule I randomized all the dimensions to create a new shape, which usually would not be a polygon (lines would cross, example image below).

morrig14_0-1636056519573.png

Anyways my idea around this was to simply put the randomizing code in a while loop that keeps repeating until the loft is active. This is not working though because I am assuming it runs once and cant check if the loft works until after the rule is done, but what do I know.

 

Here is my code:

morrig14_1-1636056973467.png

 

If anyone has any ideas on how to get this to work all help would be greatly appreciated. Thanks!

 

Graham

 

 

0 Likes
Accepted solutions (1)
970 Views
10 Replies
Replies (10)
Message 2 of 11

J-Camper
Advisor
Advisor

Are you trying to make regular or irregular polygons?

 

If you are after regular Polygons, there is a SketchLines Method specifically for that: AddAsPolygon

 

If you are after irregular Polygons, there will be a lot of custom coding needed.  Let me know if this is the goal, but I'm not going to even start to go down that rabbit hole if you are only after regular polygons.

 

 

Message 3 of 11

morrig14
Participant
Participant

The goal is unfortunately to make irregular polygons.

 

Let me know if you can help!

0 Likes
Message 4 of 11

J-Camper
Advisor
Advisor

Okay, can you answer a few questions for me:

 

What is the reason you chose spline over lines?  Do you need tangency? 

 

Can you create and post an example of your end goal through GUI? [i.e. set one up manually as a target example]

 

Do you have inner and outer bounds for the randomization? You are current randomizing every dimension between 0 and 750 cm, will the bounds always be the same?

0 Likes
Message 5 of 11

morrig14
Participant
Participant

I am trying to create random wind turbine blades. The end goal is to create a bunch of random lofts between the 2 sketches and have them be relatively aerodynamic (but they don't have to be). What I am going to do once I get these randomized "blades", plan on running simulations on them using Inventor Nastran and some machine learning to optimize the blade for efficiency.

 

I decided to use spline because I thought it would make it more likely to make the blade aerodynamic and then would require less test cases.

 

I attached below the ipt of the original blade design that I am trying to optimize, so it is essentially the target example. I was not really sure what you meant by the posting my end example through a GUI (like a form where you choose all the dimension sizes?)

 

Finally they all are just randomly 0 to 750, which seeing now is a very bad idea, but I have absolutely no clue how I could determine better bounds for each dimension while still making it random. Maybe take the example dimensions and add or subtract some random number from that?

 

Sorry that's a lot but thanks so much for being so helpful!

 

0 Likes
Message 6 of 11

J-Camper
Advisor
Advisor

GUI = Graphical User Interface, so basically the way you use Inventor as a user. Exactly what you posted.

 

Anyways, you mentioned a form and I think that is a good way to achieve your goal.  I modified the part you posted by naming dimensions for your control points and sizing them based on individual scale parameters, based on the major and minor axes of the ellipses you're using for the under side of the turbine profile.  I then brought all the modifiable settings into a user form with Slider controls for each "Scale" Parameter. 

 

The profile control points are not "random", but they are "skew-able".  I have attached the modified part with a user form in it. 

 

Let me know if this kind of approach will not work for your end goal.  Also let me know if you need an explanation of the form I created, if you don't have much experience with user forms.

 

 

0 Likes
Message 7 of 11

morrig14
Participant
Participant

Wow this is awesome thanks!

 

I could definitely use this, but the end goal is to have it randomly change through a rule, because once I do that I can (hopefully) run simulations within' the rule using Inventor Nastran and export the dimensions and results to a spreadsheet. I feel like I need to do it within' a rule because I want a lot of data and was hoping that this could just run in the background of my computer and record results for me.

 

Let me know if you have any idea on how I could somehow use a rule to change the part, make sure that it is a valid loft / design, record values to a spreadsheet, then restart the rule for a new set of parameters.

0 Likes
Message 8 of 11

J-Camper
Advisor
Advisor

Oh I see. I didn't understand how many iterations you were looking to produce.  The part is set up a little better to do a randomization as you should be able to randomize the individual scale values with an iLogic rule.  I can work something up.

Message 9 of 11

morrig14
Participant
Participant

Thankyou so much! I really appreciate the help!

 

0 Likes
Message 10 of 11

J-Camper
Advisor
Advisor
Accepted solution

Okay I built a randomizer rule in the attached part.  I did a little tweaking to randomizer bounds, but the shell does fail on update occasionally.  The rule is as follows, but it is pretty specific to the parameter names in the part file:

 

Sub Main
	Dim pDef As PartComponentDefinition = TryCast(ThisDoc.Document.ComponentDefinition, PartComponentDefinition)
	If IsNothing(pDef) Then Exit Sub
	
	Dim Iterations As Integer = 3
	
	Dim scaleRanges As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	'LENGTH
	scaleRanges.Add("OA_LENGTH", "7500 mm") 		'LENGTH NO VARIATION [FOR VARIATION: "LOWER:UPPER" (EXAMPLE: "5000 mm:10000 mm")]
	'BASE MAJOR ELLIPSE AXIS [SKETCH X AXIS]
	scaleRanges.Add("BASE_ELLIPSE_MAJOR", "500 mm:1000 mm")'BASE MAJOR ELLIPSE AXIS [SKETCH X AXIS] VARIATION [FOR NO VARIATION: "SINGLE VALUE" (EXAMPLE: "700 mm")]
	'BASE MINOR ELLIPSE AXIS [SKETCH Y AXIS]
	scaleRanges.Add("BASE_ELLIPSE_MINOR", "120 mm:300 mm") 	'BASE MinorR ELLIPSE AXIS [SKETCH X AXIS] VARIATION [FOR NO VARIATION: "SINGLE VALUE" (EXAMPLE: "190 mm")]
	'TIP MAJOR ELLIPSE AXIS SCALE
	scaleRanges.Add("OA_SCALE", ".50:.90")		'PERCENTAGE OF VARIATION FOR TIP_ELLIPSE_MAJOR/BASE_ELLIPSE_MAJOR
	'BASE POINT 1
	scaleRanges.Add("BP1_X_SCALE", ".25:.90")		'PERCENTAGE OF VARIATION FOR BP1_X/BASE_ELLIPSE_MAJOR [SKETCH X AXIS]
	scaleRanges.Add("BP1_Y_SCALE", ".30:.90")		'PERCENTAGE OF VARIATION FOR BP1_Y/BASE_ELLIPSE_MINOR [SKETCH Y AXIS]
	'BASE POINT 2
	scaleRanges.Add("BP2_X_SCALE", ".05:.50")		'PERCENTAGE OF VARIATION FOR BP2_X/BASE_ELLIPSE_MAJOR [SKETCH X AXIS]
	scaleRanges.Add("BP2_Y_SCALE", ".30:.90")		'PERCENTAGE OF VARIATION FOR BP2_Y/BASE_ELLIPSE_MINOR [SKETCH Y AXIS]
	'BASE POINT 3
	scaleRanges.Add("BP3_X_SCALE", ".40:.90")		'PERCENTAGE OF VARIATION FOR BP3_X/BASE_ELLIPSE_MAJOR [SKETCH X AXIS]
	scaleRanges.Add("BP3_Y_SCALE", ".05:.40")		'PERCENTAGE OF VARIATION FOR BP3_Y/BASE_ELLIPSE_MINOR [SKETCH Y AXIS]
	'TIP POINT 1
	scaleRanges.Add("TP1_X_SCALE", ".25:.90")	'PERCENTAGE OF VARIATION FOR TP1_X/TIP_ELLIPSE_MAJOR [SKETCH X AXIS]
	scaleRanges.Add("TP1_Y_SCALE", ".30:.90")	'PERCENTAGE OF VARIATION FOR TP1_Y/TIP_ELLIPSE_MINOR [SKETCH Y AXIS]
	'TIP POINT 2
	scaleRanges.Add("TP2_X_SCALE", ".05:.50")	'PERCENTAGE OF VARIATION FOR TP2_X/TIP_ELLIPSE_MAJOR [SKETCH X AXIS]
	scaleRanges.Add("TP2_Y_SCALE", ".40:.90")	'PERCENTAGE OF VARIATION FOR TP2_Y/TIP_ELLIPSE_MINOR [SKETCH Y AXIS]
	'TIP POINT 3
	scaleRanges.Add("TP3_X_SCALE", ".40:.90")	'PERCENTAGE OF VARIATION FOR TP3_X/TIP_ELLIPSE_MAJOR [SKETCH X AXIS]
	scaleRanges.Add("TP3_Y_SCALE", ".05:.40")	'PERCENTAGE OF VARIATION FOR TP3_Y/TIP_ELLIPSE_MINOR [SKETCH Y AXIS]
	
	Call Randomizer(scaleRanges, Iterations)
		
End Sub

Sub Randomizer(Scales As NameValueMap, Count As Integer)
	
	For i As Integer = 1 To Count
		
		For j As Integer = 1 To Scales.Count 
			Dim isStatic As Boolean = False
			Dim splitString As String() = Split(Scales.Value(Scales.Name(j)), ":")
			If splitString.Length < 2 Then isStatic = True
			
			If isStatic = True
				actExpression = splitString(0)
			Else
				actExpression = RandomizeString(splitString)
			End If
			Logger.Trace(Scales.Name(j) & " = " & actExpression)
			Parameter.Param(Scales.Name(j)).Expression = actExpression
			
		Next
		
		InventorVb.DocumentUpdate()
		MessageBox.Show(i, "Iteration")
		
	Next
		
	Exit Sub
	
End Sub

Function RandomizeString(sRange As String()) As String
	Dim Result As String = Nothing
	
	Dim lower As Double = Val(sRange(0))
	Dim upper As Double = Val(sRange(1))
	Dim Random As Double = Round((((upper-lower)*Rnd)+lower), 2) 
	Result = Random.ToString
	
	Return Result
End Function

 

Let me know if you have any questions, or if it is not working as intended

Message 11 of 11

morrig14
Participant
Participant

Thankyou so much! This will be a lot of help, I'll let you know if I need any more help!

0 Likes