Sketches in an Inventor Part

Top  Previous  Next

This diagram shows you how sketches are contained inside a part:

 

 

Sketches-in-a-part1

 

They are inside a list which is itself inside a component definition. Programatically here is how to get a sketch by name:

 

   // Get the component definition inside the PartDoc...

   CComPtr<PartComponentDefinition> pPartCompDef;

   hRes = pPartDoc->get_ComponentDefinition(&pPartCompDef);

 

   // Get the sketch in the part by name...

   CComPtr<PlanarSketch> pSketch = NULL;

   hRes = pPartCompDef->Sketches->get_Item(CComVariant(L"MAIN_TUBE_CIRCS"), &pSketch);

   if (FAILED(hRes)) {

       ShowCOMError (hRes,L"AddSolid but could not 'get' sketch\n");

       return (false) ;

   }

 

You can get hold of sketches by index (starting from #1)

 

   CComPtr<PlanarSketch> pSketch ;

   // Get the first sketch in the part

   hRes = pPartCompDef->Sketches->get_Item(CComVariant(1), &pSketch);

 

Of course both these sketch getting methods require that the named sketch you are looking for, or the index, are present in the Sketches list of the Inventor Part.

 

 

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