iLogic to verify multiple measurements

iLogic to verify multiple measurements

jfenter
Enthusiast Enthusiast
746 Views
6 Replies
Message 1 of 7

iLogic to verify multiple measurements

jfenter
Enthusiast
Enthusiast

I would like to write a rule to verify that a group of various dimensions all exceed a baseline dimension.  If a given distance is less than the baseline dimension, I will have a message box pop up to alert the user of the situation.  I would like this rule to run after the parameters have been updated.  Is there a way to check these measurements simultaneously against the baseline?   I'm sure I could write a series of If-Then statements to satisfy each variable.  I am a beginner using iLogic and assume there would be a better way to achieve the same result.

 

 

'Rule to get distance between rails

'Distance between left rail and single rail
myDist1 = Measure.MinimumDistance("Work Plane22", "Work Plane12")

'Distance between right rail and single rail
myDist2 = Measure.MinimumDistance("Work Plane23", "Work Plane13")

'Distance between left rail and double rail
myDist3 = Measure.MinimumDistance("Work Plane22", "Work Plane20")

'Distance between right rail and double rail
myDist4 = Measure.MinimumDistance("Work Plane23", "Work Plane21")

'Distance between single rail and double rail
myDist5 = Measure.MinimumDistance("Work Plane13", "Work Plane20")

honeycombmin=230

 

0 Likes
Accepted solutions (1)
747 Views
6 Replies
Replies (6)
Message 2 of 7

Owner2229
Advisor
Advisor

Hi, do you want to do the measuring between all workplanes or just some specific ones?

I'm asking because we can either go through all of them (using "For Each") or just through a list of them.

I mean, you can use it like this if the workplanes (or their names) don't change.

 

In this case I'll use the later option:

Sub Main()
	AddMeasurement("Work Plane22", "Work Plane12") ' Left rail and single rail
	AddMeasurement("Work Plane23", "Work Plane13") ' Right rail and single rail
	AddMeasurement("Work Plane22", "Work Plane20") ' Left rail and double rail
	AddMeasurement("Work Plane23", "Work Plane21") ' Right rail and double rail
	AddMeasurement("Work Plane13", "Work Plane20") ' Single rail and double rail
	Dim HoneyCombMin As Double = 230
	Dim MOL As String = vbnullstring
	For i = 0 To MyDist.Lenght - 1 'Go through each measurement
		If MyDist(i) >= HoneyCombMin Then Continue For
		If MOL <> vbnullstring Then MOL = MOL & vbnewline
		MOL = MOL & "Value " & i + 1 & " is less than " & HoneyCombMin
	Next
	If MOL <> vbnullstring Then MsgBox(MOL) 'Show the results (if any)
End Sub

Private MyDist(0) As Double 'Local variable to store the measurements

Private Sub AddMeasurement(WorkPlaneA As String, WorkPlaneB As String)
	If Not MyDist(MyDist.Lenght - 1) Is Nothing Then
		ReDim Preserve MyDist(MyDist.Lenght)
	End If
	MyDist(MyDist.Lenght - 1) = Measure.MinimumDistance(WorkPlaneA, WorkPlaneB)
End Sub

We could also add the workplanes' names to an array, so we could use them in the result instead of "value x", so let me know if this is the way you want it to go.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 7

jfenter
Enthusiast
Enthusiast

Owner2229,

 

First, thanks for the help!  Upon loading the code you have written, I did get a return error on the follow line:

 

 

If Not MyDist(MyDist.Length - 1) Is Nothing Then

"Error on line 20:  'Is' operator does not accept operands of type 'Double'.  Operands must be reference or nullable types."

 

 

The assembly this code will work with is going to be a template assembly for the other engineers in my department to create various panels.  The panel assemblies could exist in one of three ways: 

 

1) With no inner rails at all - Single and Double Rail would be inactive

2) With one inner rail - Single rail active, double rail inactive (The x-axis position of the inner rails can vary as well as the width of the rails)

3) With two inners rails - both Single and Double rails are active (The x-axis position of the inner rails can vary as well as the width of the rails)

 

I planned on having a single measurement rule to run controlled by a Case statement for each panel type, but again, if there is a better way I'm all for it.  The work plane names won't change, but they will toggle on and off with each different panel type.  I should also mention the corresponding rails are created as solid bodies, but since the measurement is between the work planes I don't think that should matter.  This rule would run as a check to be sure that each of the dimensions exceed the honeycomb minimum of 230mm.  If any one of the dimensions would be less than 230, the message box would pop up to alert the user to change parameters to an acceptable distance.  The message box would not have to specifically call out which dimension is at fault, simply just notify the user of the discrepancy.

 

I'd also like to ask where I can get more information about the specific code you're writing.  I have limited iLogic experience and no Visual Basic experience at all.  Most of the code you have written I do not understand.

 

 

 

 

0 Likes
Message 4 of 7

MechMachineMan
Advisor
Advisor

Change the "Is" in that line to an "=".

 

The Is keyword is only valid when doing comparisons of objects, but for variables of basic types the "=" sign performs the same function.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 5 of 7

Owner2229
Advisor
Advisor
Accepted solution

Alright, my misstake, here's the corrected code with some more descriptions, so you could learn from it.

First of I have put the main part of the rule in the sub routine "Main". It's required by iLogic when you want to split your code to more parts (sub routines and functions) and it has to be called "Main" so iLogic know it has to be executed when the rule starts.

Sub routine is a part of code that will execute before the code goes to another line.

Function does the same, except it also returns a value.

I hope it's clear enough, ask if you need futher explenation.

 

 

Sub Main()
	' Here I'm adding all measurements using the new sub routine called "AddMeasurement"
	AddMeasurement("Work Plane22", "Work Plane12") ' Left rail and single rail
	AddMeasurement("Work Plane23", "Work Plane13") ' Right rail and single rail
	AddMeasurement("Work Plane22", "Work Plane20") ' Left rail and double rail
	AddMeasurement("Work Plane23", "Work Plane21") ' Right rail and double rail
	AddMeasurement("Work Plane13", "Work Plane20") ' Single rail and double rail
	Dim HoneyCombMin As Double = 230 ' Definine the value for comparison
	' Here I'm defining a text variable with no value
	Dim MOL As String = vbnullstring
	' Loop throught all measurements stored in the "MyDist" variable array
	For i = 0 To MyDist.Lenght - 1 'Go through each measurement
		' If the value in the array is bigger or equal to HoneyCombMin skipp this value
		If MyDist(i) >= HoneyCombMin Then Continue For
		' If the variable "MOL" isn't empty add a new row to it, so the new value goes there
		If MOL <> vbnullstring Then MOL = MOL & vbnewline
		' Add the value to the "MOL" variable along with some text
		MOL = MOL & "Value Nr." & i + 1 & " (" & MyDist(i) & ") is less than " & HoneyCombMin
	Next
	' If the "MOL" variable is not empty show a message with it's content
	If MOL <> vbnullstring Then MsgBox(MOL) 'Show the results (if any)
End Sub

' The definition of "MyDist" variable of the type "Double" = number with decimals
' The zero defines this variable as array with one "slot", as the counting starts from zero
Private MyDist(0) As Double 'Local variable to store the measurements
' The definition of the sub routine "AddMeasurement".
' In the brackets are required input values.
' "As String" means the accepted values must be text
Private Sub AddMeasurement(WorkPlaneA As String, WorkPlaneB As String) ' If the variable "MyDist" is not empty we need to add another "slot" If Not MyDist(MyDist.Lenght - 1) = Nothing Then ' Since the lenght is 1 and the counting starts from 0, the value will grow by 1 ReDim Preserve MyDist(MyDist.Lenght) End If ' Store the measurement in the last slot. Number of slots - 1 (counting starts from zero) MyDist(MyDist.Lenght - 1) = Measure.MinimumDistance(WorkPlaneA, WorkPlaneB) End Sub ' The end of the sub routine
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 6 of 7

jfenter
Enthusiast
Enthusiast

Owner 2229 - Thank you very much!  It's been quite a challenge for me learning iLogic coding on what's proving to be a fairly complex assembly.  The lack of a true manual that describes different commands is frustrating at times.  I greatly appreciate you taking the time to explain things so thoroughly for me.  The code works perfectly, by the way.  Thanks!!!!

0 Likes
Message 7 of 7

Owner2229
Advisor
Advisor

You're welcomed. You can find some API tutorials in Inventor:

"HELP" > "Programming / API Help"

And there search for what you're looking for.

 

Or just ask here on forum and describe what you need.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods