Inventor Customization

Reply
Mentor
MegaJerk
Posts: 266
Registered: ‎01-26-2011
Message 1 of 2 (405 Views)
Accepted Solution

Non-Defined (Dynamic) Arrays in iLogic

405 Views, 1 Replies
05-23-2012 05:22 AM

Is there a way to declare a non-bound array (dynamic array?) in iLogic?

There are examples of set bounds array:

 

MyDoubleValues = New Double(){1.2,2.2,3.3}

 

But doing something like:

 

Dim MyDoubleValues() As Double  ---Or---  MyDoubleValues = New Double()

 

Results in an error. On the other hand, the following totally works:

 

Dim MyDoubleValues(1) As Double

 

Which creates an array with a Ubound of 2

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, -
as it increases my power levels and will eventually help to elevate me towards outer space.

Check out my iLogic injection tool here : http://goo.gl/ce1Qg
--------------------------------------------------------------------------------------
Mentor
MegaJerk
Posts: 266
Registered: ‎01-26-2011
Message 2 of 2 (392 Views)

Re: Non-Defined (Dynamic) Arrays in iLogic

05-24-2012 09:49 AM in reply to: MegaJerk

Alright, I sort of solved my own problem. The code below is a test showing that you can make a single slot defined array, make it grow based on user inputs, sort it, and make it shrink to remove any duplicate entries. It's not pretty, but I never claimed that I was a coding genius :smileywink: 

What it does: Produces an input box asking for numerical inputs. When you are done hit cancel or simply hit enter (leaving the input blank), and you will be asked to confirm. Once you confirm, the array will be sorted from lowest to highest and returned to you via a message box. 

The intention of this test was to figure out a way to capture a series of user inputs in a dynamic (on the fly sort of) way, to allow for the later combination of the user array and any predefined array (or series of numbers) that existed in my Inventor assembly as calculated parameters. 

 

 

////////////////////////////////////

 

Oh one last note : This is sorting using the Bubble Sort method.

 

///////////////////////////////////

 

Dim holder As Object
Dim fakeArray(0) As String
Dim i As Integer
Dim holderList As String

i = 0

holder = InputBox("Please Enter Your Channel Possitions", "Number Muncher", "")

If IsNumeric(holder) = True Then
fakeArray(i) = holder

While holder <> ""

holderList = Join(fakeArray,",")
holder = InputBox("Please Enter Your Next Value" & vbCrLf &" The Current Values are : " & holderList, "Number Muncher", "") '

If IsNumeric(holder) = True Then
i = i+1
ReDim Preserve fakeArray(i)
fakeArray(i) = holder
Else

ButtonValueTest=MsgBox("Would You Like To Stop Entering Values?", vbYesNo,"Question Time!")
If ButtonValueTest = vbYes Then
'MessageBox.Show("You pressed : Yes","Results")
Exit While
Else
'MessageBox.Show("You pressed : No","Results")
holder = "1"
End If

End If
End While
End If

'MessageBox.Show(UBound(fakeArray),"")


Dim ArraySize As Integer
ArraySize = UBound(fakeArray)

Dim slot1, slot2, swapped As Double
Dim APos As Integer
Dim IdentCount As Integer

swapped = 2

If ArraySize < 1Then
MessageBox.Show("Array has been sorted: " & holderList, "")
Else If ArraySize > 0 And ArraySize < 2 Then
slot1 = fakeArray(0)
slot2 = fakeArray(1)
If slot1 < slot2 Then
holderList = Join(fakeArray,",")
MessageBox.Show("Array has been sorted: " & holderList,"")
Else If slot1 > slot2 Then
fakeArray(0) = slot2
fakeArray(1) = slot1
holderList = Join(fakeArray,",")
MessageBox.Show("Array has been sorted: " & holderList,"")
Else If slot1 = slot2 Then
'Remove(fakeArray(1))
ReDim Preserve fakeArray(0)
holderList = Join(fakeArray,",")
MessageBox.Show("An Array has been changed to: " & holderList,"")
End If
Else If ArraySize > 1 Then
'MessageBox.Show("Array Larger Than 1", "")
While swapped > 1
swapped = 1

For APos = 1 To UBound(fakeArray) Step 1
'MessageBox.Show("Looping through Array","")

slot1 = fakeArray(Apos-1)
slot2 = fakeArray(Apos)

If slot2 < slot1 Then
fakeArray(Apos-1) = slot2
fakeArray(Apos) = slot1
swapped = 2
Else If slot2 = slot1 Then

For IdentCount = APos To UBound(fakeArray) Step 1
'MessageBox.Show("Upper Bound: " & UBound(fakeArray) & " And Ident " & IdentCount, "")
If IdentCount = UBound(fakeArray) Then
ReDim Preserve fakeArray(IdentCount - 1)
Apos = 1
'MessageBox.Show("New UBound: " & UBound(fakeArray),"")





Exit For
End If
fakeArray(IdentCount) = fakeArray(IdentCount + 1)

Next
swapped = 2
End If
'MessageBox.Show("APos : " & APos,"")
If APos >= UBound(fakeArray)
Exit For
End If

Next

If swapped <> 2 Then
swapped = 0
End If
End While
holderList = Join(fakeArray,",")
MessageBox.Show("Array has been sorted down to: " & holderList,"")
End If

 


 

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, -
as it increases my power levels and will eventually help to elevate me towards outer space.

Check out my iLogic injection tool here : http://goo.gl/ce1Qg
--------------------------------------------------------------------------------------

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube