Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

What is the best practive for using ObjectCollection?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
nnikbin
399 Views, 3 Replies

What is the best practive for using ObjectCollection?

I am a little confused about using ObjectCollection vs. native or standard library containers defined in C++ and Python.

 

For example I do not know which criteria should I use to decide between returning std::vector<Ptr<SketchCurve>> or std::vector<Ptr<Base>> vs. returning Ptr<ObjectCollection> from a method.

 

In some cases, the result of a method is homogeneous (to some degree). For example all elements are SketchLine(s), or in a less homogeneous case, all elements are SketchCurve(s). So it seems using  native or standard library containers is better in these cases, but when I want to feed the result to some Fusion API methods down the road, I should convert the result to ObjectCollection, because the API accepts ObjectCollection. Sometimes the opposite happes and I should convert ObjectCollection to a homogeneous container.

 

I would be glad to know the story behind ObjectCollection. Why @BrianEkins  has created them instead of using available containers like Base[] (or std::vector<Ptr<Base>> in C++) and why he used ObjectCollection for returning the result of some methods like Sketch.findConnectedCurves while he used SketchEntity[] (or a std::vector<Ptr<SketchEntity>> in C++) for returning the result of some other methods like Sketch.projectToSurface.

 

What is the best practice for using ObjectCollection vs native or standard library containers?

Labels (2)
3 REPLIES 3
Message 2 of 4
nnikbin
in reply to: nnikbin

Sorry for the typo in the title. 

What is the best practive practice for using ObjectCollection? 

Message 3 of 4
BrianEkins
in reply to: nnikbin

This is a part of the API I wish could be changed.  There were some concepts in the Inventor API that were needed to better support both C++ and other COM languages.  One of these is a common currency for arrays.  The ObjectCollection was the solution.

 

For Fusion, it was assumed we had the same issue and the ObjectCollection class would provide the same solution.  However, it turns out it's not needed in Fusion.  The API design defines an array of a certain type and when that gets converted into the implementation, it is a vector of a certain type in C++ and a List in Python.  The ObjectCollection class isn't needed.  When you do see it, that's all it's used for; the equivalent of an array.  I believe all the new API functionality is using arrays rather than ObjectCollections.  Unfortunately, the functions that use an ObjectCollection can't be changed or it would break any existing programs.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 4 of 4
nnikbin
in reply to: nnikbin

Thank you @BrianEkins for your comprehensive answer.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report