iLogic: Create and populate a New instance of ObjectsEnumerator Object

iLogic: Create and populate a New instance of ObjectsEnumerator Object

j.pavlicek
Collaborator Collaborator
1,711 Views
5 Replies
Message 1 of 6

iLogic: Create and populate a New instance of ObjectsEnumerator Object

j.pavlicek
Collaborator
Collaborator

Hello,
is possible to create and populate a New instance of ObjectsEnumerator Object?

 

I'm trying to add functionality to a class for selection provided by @JhoelForshav in Let user select multiple objects at once thread. I want to use an existing selection (Document.SelectSet) - if exists. But no idea how to put Items from SelectSet Object to ObjectsEnumerator Object which is used here as output object clsSelect.SelectedObjects, because it's object returned by SelectEvents.SelectedEntities Property used here.

 

Yes, there is no necessity to use ObjectsEnumerator Object. ObjectCollection Object or any other Collection-like object. But I'd like to know.

 

Also is there better way how to transfer items from ObjectsEnumerator Object to other Collection than following?

For Each item In oObjectEnumerator
	oCollection.Add(item)
Next

 

Thanks for help.



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
Accepted solutions (1)
1,712 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

I believe the ObjectsEnumerator objects found within Inventor's API are unique to Autodesk, not to VB.NET or VBA.  The only known way to build one is through the SelectEnvents.  There are other collections within Inventor that use an ObjectsEnumerator, but they only have Properties, and no Methods exposed to the API.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

JhoelForshav
Mentor
Mentor

Hi @j.pavlicek @WCrihfield 

An enumerator is actually the object used to traverse a collection. For example "For each"-loops uses an enumerator to step through a collection. So the ObjectsEnumerator isn't the collection of objects, therefore you cannot add to the collection through it.

0 Likes
Message 4 of 6

j.pavlicek
Collaborator
Collaborator

@WCrihfield, @JhoelForshav  Thanks for replies.

 

After extensive googling I figure out that Interfaces (what Inventor.ObjectsEnumerator is) are like definition of set of neccessary {Properties, Functions, Subs, Events, Interfaces, Classes, Structures} which must this a Class implements.

 

"ObjectsEnumerator Type Class" must have implemented {Count As Integer, Item as Object, Type as ObjectsTypeEnum} properties (but how you get these values is up to you).

 

Is not allowed to create a new "interface object" like

Dim oOE As New ObjectsEnumerator

You get 'New' cannot be used on an interface Error. But you can create a new instance of a Class which implements Inventor.Enumerator.

Sub Main
	Dim oOE As ObjectsEnumerator
End Sub
Class myObjectsEnumerator
	Implements Inventor.ObjectsEnumerator
End Class

But here I ends getting this Compile Errors:

Error on Line X : Class - myObjectsEnumerator must implement member Function GetEnumerator() As IEnumerator for interface System.Collections.IEnumerable.

Error on Line X : Class - myObjectsEnumerator must implement member Function GetEnumerator() As System.Collections.IEnumerator for interface Inventor.ObjectsEnumerator.

Error on Line X : Class - myObjectsEnumerator must implement member ReadOnly Default Property Item(Index As Integer) As Object for interface Inventor.ObjectsEnumerator.  Implementing property must have matching ReadOnly/WriteOnly specifiers.

Error on Line X : Class - myObjectsEnumerator must implement ReadOnly Property Count As Integer for interface Inventor.ObjectsEnumerator.  Implementing property must have matching ReadOnly/WriteOnly specifiers.

Error on Line X : Class - myObjectsEnumerator must implement member ReadOnly Property Type As ObjectTypeEnum for interface Inventor.ObjectsEnumerator.  Implementing property must have matching ReadOnly/WriteOnly specifiers.

It's obvious, because interface only defines what must be provided, but nothing about code for these functions/properties. But now this is above my knowledge level.



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
Message 5 of 6

j.pavlicek
Collaborator
Collaborator
Accepted solution

Ok, there is no need to create a custom class for a New instance of ObjectsEnunumerator.

 

Don't ask my why, but you can use ObjectCollection and its constructor method TransientObjects.CreateObjectCollection Method instead of ObjectsEnumerator.

 

Proof of Concept:

Dim oDoc As Document = ThisDoc.Document
Dim oSel As SelectSet = oDoc.SelectSet
Dim MyObjectsEnumerator As ObjectsEnumerator
MyObjectsEnumerator = ThisApplication.TransientObjects.CreateObjectCollection
'Logs type of MyObjectsEnumerator (kObjectCollectionObject)
Logger.Debug("MyObjectsEnumerator.Type = " & [Enum].GetName(GetType(ObjectTypeEnum), MyObjectsEnumerator.Type))
For Each item As Object In oSel
	MyObjectsEnumerator.Add(item)
Next
'Logs item count in MyObjectsEnumerator = items selected before running this rule
Logger.Debug("MyObjectsEnumerator.Count = " & MyObjectsEnumerator.Count)

If you know about any documentation explaining this, please share a link here.

 

 

 



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Here are a few links you can look at for the ObjectCollection object (which is actually derived from the ObjectsEnumerator).

ObjectCollection Object 

TransientObjects Object 

And since these two terms are used on the help page, I thought I would attach a couple of links for them too.

IDispatch interface 

Strong and weak typing 

And here's another helpful link for Collections.

Collections (Visual Basic) 

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes