ObjectCollections in the Inventor API (transient object collections).

Top  Previous  Next

Object collections can be used to make a list of already existing objects. This list can then be used by your program to do repeated operations on those objects. Although the objects already exist they may be in hard to get places, or in the wrong order to what you want. Or maybe the objects you want are a sub set of the all the objects in your part or assembly.


Anyway, you need to get hold of the transient objects pointer from the Inventor application:


   CComPtr<Application> pInvApp ... ;

   CComPtr<TransientObjects> pTransientObjects ;

   pInvApp->get_TransientObjects (&pTransientObjects) ;


Or, if basing your programs on the book sources, you can use GetTransGeomPtr().


The TransientObjects pointor is the thing which allows you to create object collections. Here is how to create an initially empty one:


   CComPtr<ObjectCollection> pObjCollection = nullptr ;

   pTransientObjects->CreateObjectCollection (varEmpty,&pObjCollection) ;


Simply use the Add function to add objects to the collection. Here is an example of adding a WorkPlaneProxy to an object collection:


   CComPtr<WorkPlaneProxy> pWPProxy = nullptr ;

   pTuboOcc->CreateGeometryProxy (pWP,(IDispatch**)&pWPProxy) ;

   pObjCollection->Add (pWPProxy) ;


Once you have created the list of objects you can get hold of them by passing the index to the get_Item function:


   CComPtr<WorkPlaneProxy> pHoleWPProxy = nullptr ;

   int iTroncNum = ..something starting a 1, 1 is the first object....

   pObjCollection->get_Item (iTroncNum,(IDispatch**)&pHoleWPProxy) ;


I've removed all error checking from the fragments above.

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)