Alternatives for storing parameters, such as a List(Of ArrayList)?

Alternatives for storing parameters, such as a List(Of ArrayList)?

Anonymous
Not applicable
1,761 Views
14 Replies
Message 1 of 15

Alternatives for storing parameters, such as a List(Of ArrayList)?

Anonymous
Not applicable

I have used following two methods of storing parameters, both of which have huge limitations:

  • Inventor Parameters - Can only store Int, Float, String, Bool
  • Excel files - Slow, requires Excel to be installed (which my corporation is trying to move away for in favor of Google Docs, and I'm fighting it)

One of my use cases is that I have a List of items (size of list can vary between 2 and ~60) of items, and each item has ~20 parameters (position, height, width, hasHinge, etc). Basically it is a List(Of ArrayList).

Currently I store the data in an excel file, with each item being a row, and each parameter being a column. I then read each row to populate a List(Of ArrayList). The issue is that I need to do this every single time I need to grab a parameter, so it takes a lot of time.

 

Storing it in Inventor parameters doesn't seem like an option.

Either I would have to predefine 60x20 Parameters (item1_height, item2_height, etc), or store everything in a huge string, separate parameters by one character, separate items by another character, and then use String.Split to populate my List(Of ArrayList).

 

Are there any other options?

0 Likes
1,762 Views
14 Replies
Replies (14)
Message 2 of 15

Ralf_Krieg
Advisor
Advisor

Hello

 

Take a look at AttributeSets and Attributes. And the functions of the AttributeManager to handle them.

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 15

Anonymous
Not applicable

@Ralf_Krieg Thanks! I've seen AttributeSets mentioned before, but not knowing what they do, I glossed over them.

 

Will try to read up on them. Just shame the iLogic documentation is so abysmal..

0 Likes
Message 4 of 15

bradeneuropeArthur
Mentor
Mentor

You can write it as Xml file in Inventor directly!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 15

Ralf_Krieg
Advisor
Advisor

Hello

 

Can you please explain it? Where and how is a XML file stored in Inventor?


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 6 of 15

SometimesInventorMakesMeAngry
Advocate
Advocate

@Ralf_Krieg wrote:

Hello

 

Can you please explain it? Where and how is a XML file stored in Inventor?



I believe you can use AttributeSet.DataIO.ReadDataFromFile

0 Likes
Message 7 of 15

bradeneuropeArthur_0-1618253269199.png

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 8 of 15

Anonymous
Not applicable

@Ralf_Krieg Now that I looked into Attributes a bit, it seems like they only support simple data types. If an AttributeSet could contain another AttributeSet, that would be nifty..

How do you handle the List in my example? Basically create up to 80 AttributeSets, and name them with a number at the end, and then iterate through them in a for-loop? Or is there a smarter way?

0 Likes
Message 9 of 15

Anonymous
Not applicable

@bradeneuropeArthur 

Thanks, but that doesn't help. I guess I wasn't clear enough in my original post, my bad.

I'm trying to save parameters/variables from iLogic code. When I wrote the title I didn't think about the fact that it could be confused with Inventor Parameters..

 

Storing them as Inventor Parameters isn't an option, since it only supports simple data types, and I'm trying to store a List(Of ArrayList)

0 Likes
Message 10 of 15

pball
Mentor
Mentor

@Anonymousit might not be exactly what you'd like as you mentioned it in your first post. But if turn your data into a delimited string you can store it in a single attribute. You'd just need a list to string and string to list function, which shouldn't be too hard to make.

 

I made a quick and dirty example using a list(of list(of string)) getting saved to an attribute. I didn't turn that string back into a list but it should show the general process if you're interested. The attribute code was found on the Mod the Machine blog.

 

'iLogic code
AddReference "System.Linq"
Imports System.Linq
Public Sub main
Dim somelist As New List(Of List(Of String))
somelist.Add(New List(Of String)({"M", "B", "W", "S", "R"}))
somelist.Add(New List(Of String)({"Blue","Red","Green"}))
somelist.Add(New List(Of String)({"Coby","Peperjack","Blue"}))

Dim SomeString As String = LiString(somelist)

Dim doc As Document = ThisDoc.Document

' Get the AttributeSets object from the selected entity.
Dim attribSets As AttributeSets = doc.AttributeSets

' Create an attribute set.
Dim attribSet As AttributeSet
Try
attribSet = attribSets.Add("pball")
Catch
	attribSet = attribSets.Item("pball")
End Try

' Create an attribute on the set.
Dim attrib As Inventor.Attribute 
Try
attrib = attribSet.Add("data", kStringType, somestring)
Catch
	attribSet.Item("data").Value = SomeString
End Try

' Get the attribute manager.
Dim attribMgr As AttributeManager = doc.AttributeManager 

' Find all attribute sets named "SampleSet"
Dim foundEntities As AttributeSetsEnumerator = attribMgr.FindAttributeSets("pball","data")

MsgBox( "Found " & foundEntities.Count  & " entities." & vbNewLine & foundEntities.Item(1).Item(1).Value  )

End Sub

Private Function LiString(Li As List(Of List(Of String))) As String
	Dim ReturnString As String
	Dim TempString As String
	
	For Each list As List(Of String) In Li
		For Each item As String In list
			TempString += IIf (TempString <> "", ",", "") & item
		Next
		ReturnString += IIf (ReturnString <> "", ";", "") & TempString
		TempString = ""
	Next
	
	Return ReturnString
End Function
 

 

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 11 of 15

_dscholtes_
Advocate
Advocate

I'm not sure if it's slow on large data sets, but I store configuration info of my macros in a <macro name>.ini file (e.g. start-up position, which check boxes / radio buttons / options were set, etc.). Ini files use a 'section' > 'key' = 'value' structure. Example:

[FormLocation]
RememberLastPosition=true
Top=296
Left=361

[LastInput]
PipeSize=20x2.6

[CheckBoxes]
IncludeConnected=True

 Here the 'keys' have descriptive names, but you can also use "Item_xx" as key (and use a loop to get all the items).

0 Likes
Message 12 of 15

Anonymous
Not applicable

@pball Thanks for the code! Before your last reply, I had actually started rewriting my code, with each item being a separate AttributeSet, named Item_0, Item_1 etc. I had to write a few functions to easily loop through the AttributeSets and get/add the Attributes, but it works fine! I think I'll stick with this for now. Thanks for putting me on the right path!

0 Likes
Message 13 of 15

Anonymous
Not applicable

@_dscholtes_ 

That looks like it could be useful!

Does iLogic has any built in API to communicate with the ini-file (something like "Dim inclConnCheckBoxes As Boolean = ReadFromIni(myIniFile.ini, FormLocation.RememberLastPosition)"), or would I need to write all the functionality myself?

0 Likes
Message 14 of 15

_dscholtes_
Advocate
Advocate

Ah, well. I write all my macro's in VBA actually. The ini read and write code is not that complicated (see here) and can easily be translated to iLogic, but a quick try shows that I don't know enough iLogic to correctly declare the two external functions. Here's a VBA declaration of one of them as example:

Declare Function GetPrivateProfileString Lib "kernel32" Alias _
                 "GetPrivateProfileStringA" (ByVal lpApplicationName _
                 As String, ByVal lpKeyName As Any, ByVal lpDefault _
                 As String, ByVal lpReturnedString As String, ByVal _
                 nSize As Long, ByVal lpFileName As String) As Long

 

0 Likes
Message 15 of 15

WCrihfield
Mentor
Mentor

Do the values need to be stored 'on disk' somehow, or can they just be stored in 'memory', temporarily?  How are you using the data once it is stored?  Have you considered a Dictionary or KeyedCollection type collection, where each entry has a 'Key' (usually a String), and a 'Value' (can by any data Type, including other collection objects).

If you don't (or may soon not have) Excel, there are usually also built-in ways to deal with spreadsheet type data files, without having to use Excel specifically.  I believe these links help explain more about that process:

To Configure iLogic Options 

iLogic Configuration Excel Options - 2021 Update 

https://www.libxl.com/ 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes