2 Replies Latest reply on Nov 6, 2014 2:07 PM by Chuan Hung

    SolidWorks C++ API IAssemblyDoc IGetComponents HRESULT 0x800706f4

    Chuan Hung

      Hi,

       

      I'm trying to read an assembly file and get the components it has. I'm able to retrieve the number of components using IAssemblyDoc->GetComponentCount function but unable to retrieve the components with the GetComponents function. Below is a code snippet I wrote.

       

      long count = 0;

      swAssy->GetComponentCount ( VARIANT_FALSE, &count );

      printf ( "\n%i components", count );

      IComponent2** components = NULL;

      HRESULT hres = swAssy->IGetComponents ( VARIANT_FALSE, count, components );

      printf ( "\nIGetComponents 0x%08lx\n", hres );

       

       

      Output:

      31 components

      IGetComponents 0x800706f4

       

       

      Does anyone know what I'm missing here? Thanks in advance!

        • Re: SolidWorks C++ API IAssemblyDoc IGetComponents HRESULT 0x800706f4
          Chuan Hung

          I searched through the forum and found this post which uses GetComponents instead of IGetComponents but I don't get results back correctly.

           

          https://forum.solidworks.com/message/268800#268800

           

          for (int i = 0; i < count; i++)

          {

              IComponent2 *nextComp = NULL;

              hr = pDispData[i]->QueryInterface(IID_IComponent2, (void**)&nextComp);

           

              long val;

              nextComp->IGetTessTriangleCount ( &val );

           

              // my val always come out to be zero.

          }

           

           

           

           

           

          Below is the approach with IGetComponent call and I'm getting the same result back

           

           

          IComponent2** pChildren = NULL;

          pChildren = new IComponent2*[count];

          hres = swAssy->IGetComponents ( VARIANT_FALSE, count, pChildren );

          for ( int i = 0; i < count; i++ ) {

                  IComponent2Ptr comp = pChildren[i];

                  long val;

                  comp->IGetTessTriangleCount ( &val );

           

                  // val is also 0

            }

           

          I'd really appreciate if anyone can give me a pointer. I've been stuck for a while now. Thanks.

          • Re: SolidWorks C++ API IAssemblyDoc IGetComponents HRESULT 0x800706f4
            Chuan Hung

            Here's the answer I received from API support:

             

            "IGetTessTriangleCount Method (IComponent2) gets the number of triangles that make up the shaded picture tessellation for the components. And this tessellation information is available only when the components is loaded as lightweight."

             

            All I had to do was to add these lines prior to calling IGetTessTriangleCount.

             

             

            long lSuppressError;

            // set suppression state of component to Lightweight

            nextComp->SetSuppression2(swComponentLightweight,&lSuppressError);