Getting items from collections

Top  Previous  Next

You often want to get hold of items in various collections within Inventor objects. You can often use get_Item to do this.


   CComPtr<PlanarSketch> pSketch = NULL;

   hRes = piPartCompDef->Sketches->get_Item(CComVariant(_T("BaseCircles")), &pSketch);


The above code looks inside the list of sketches to find the one called "BaseCircles".


Sometimes you can simply pass an index:


    CComPtr<DrawingView> pThisView  ;

    hRes = pViews->get_Item(1,&pThisView) ;



Another way of getting an item from a collection uses get_Item with an cast index:


for (int j = 1 ; j <= ikNumConstraints ; j++) {

   CComPtr<AssemblyConstraint> pConstraint;

   pConstraintList->get_Item(CComVariant(j),&pConstraint) ;

   TRACE ("Got constraint %d\n"),j);



In the example above the index is passed as a CComVariant, CComVariant(j).


Here are some other ways of using get_Item:




    get_Item(CComVariant(j),... // i is an integer


    get_Item(_variant_t(3L, VT_I4),...  // 3 as a VT_I4



When using integer indices they always start from 1 (not 0).

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