3 Replies Latest reply on May 13, 2013 1:23 AM by Artem Taturevych

    How to correctly use IGetAppliedAnnotations

    Karthik Laxminarayana

      Hello,

       

      Have been stuck with the correct usage of IGetAppliedAnnotations in my C++/COM code.

       

      Here's what I'm doing, given a IDimXpertFeature *pDXPFeat, I call:

       

       

       

       

       

      long annotCnt = pDXPFeat->GetAppliedAnnotationCount();

        

      IDimXpertAnnotationPtr pDXPAnnots = pDXPFeat->IGetAppliedAnnotations(annotCnt);

       

       

      // Now iterate over the array of annotations

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

      {

           BSTR dxpSWAnnotName; 

           swDimXpertAnnotationType_e eAnnotType;

       

           pDXPAnnots[i].get_Type(&eAnnotType);

       

      }

      // Works fine only for the first annotation, but all the next entries in the array are corrupt!!!

       

      The API documentation says that IGetAppliedAnnotations retuns a pointer to an array of IDimXpertAnnotations. But, seems like the above function signature returns a pointer to just the first IDimXpertAnnotation under that DimXpertFeature.

      Any ideas on what I'm doing wrong here???

      FYI - To use the DimXpert APIs, I imported the swdimxpert type library and upon compilation, got the automatically generated header and implementation files (swdimxpert.tlh and swdimxpert.tli) with the following function signature for this API call:

      inline IDimXpertAnnotationPtr IDimXpertFeature::IGetAppliedAnnotations ( long Count )

       

      I've not used these COM smart pointers (such as, IDimXpertAnnotationPtr) before, so it's very likely that I'm completely missing the point when it comes to using the correct syntax accessing the returned array of these annotation pointers.

       

      Please enlighten if anyone knows how!!!

      Thanks.

      Never had to import type libraries for using other SolidWorks APIs before, just had to include their header files and that's it. But did not find any header files for dimxpert in the installation (just a type library).

        • Re: How to correctly use IGetAppliedAnnotations
          Artem Taturevych

          Just looking on this method syntax in the API Help. It looks like the count parameter here is input parameter rather than output and the return value doesn’t look like an array. Have you tried to use this as the index of the annotation you want to return? Something like this:

           

          long annotCnt = pDXPFeat->GetAppliedAnnotationCount();

            

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

          {

               BSTR dxpSWAnnotName;

               swDimXpertAnnotationType_e eAnnotType;

               IDimXpertAnnotationPtr pDXPAnnots = pDXPFeat->IGetAppliedAnnotations(i);

               pDXPAnnots->get_Type(&eAnnotType);

           

          }

          ____________________________________________________

          Regards,

          Artem Taturevych, Application Engineer at Intercad (Australia)

           

          translationXpert – add-in to translate SolidWorks models

          LinkedIn SolidWorks API Education Group

            • Re: How to correctly use IGetAppliedAnnotations
              Karthik Laxminarayana

              Hello Artem,

               

              Thanks for the quick reply!

               

              I tried the approach you recommended in the past because as you mentioned, I thought that the count parameter must be an input parameter. However, I get back null pointers for cases where i != annotCnt. So, seems like they want me to pass in the value returned from the GetAppliedAnnotationCount call directly into the IGetAppliedAnnotations call.

               

              Here's a snippet from their API help page (remarks section) for IGetAppliedAnnotations:

               

              Before calling this method, call IDimXpertFeature::GetAppliedAnnotationCount to get the value for the Count parameter.

               

              Also,

              Return Value

               

              Since it was returning an array, I figured that this must be an array of all the applied annotations and not just an annotation at a specific index!

               

              Thanks.