AnsweredAssumed Answered

Can we attach annotation to Sketch Point using IAnnotation::SetAttachedEntities() method?

Question asked by Mahadev Dharme on Aug 29, 2019

Hi,

We are trying to attach SketchPoint in opened SolidWorks part using IAnnotation::SetAttachedEntities() method. The point coordinates will be specified explicitly. We have successfully attach edge and face to annotation and now trying to attach SketchPoint using the following code.

 

//=================================================
CComPtr<ISldWorks> m_pSwApp;// This will be the addin application.
CComPtr<IModelDoc2> m_pModelDoc;//This will be the active model doc.

CComPtr<ISketchManager> pSketchMgr = NULL;
m_pModelDoc->get_SketchManager(&pSketchMgr)) && pSketchMgr != NULL, return E_FAIL;);

pSketchMgr->Insert3DSketch(VARIANT_TRUE);


if (SUCCEEDED(pSketchMgr->put_AddToDB(VARIANT_TRUE)))
{
      pSketchMgr->CreatePoint(-0.124229, 0.09779, -0.014756, &pPoint);

      // Remove the selection of Sketch point.
      m_pModelDoc->ClearSelection2(VARIANT_TRUE);
}

pSketchMgr->Insert3DSketch(VARIANT_TRUE);
pSketchMgr->put_AddToDB(VARIANT_FALSE);

std::vector<CComPtr<IDispatch>> annotationAttachEntities;
annotationAttachEntities.push_back(CComQIPtr<IDispatch, &IID_IDispatch>(pPoint));

if (!annotationAttachEntities.empty())
{
      VARIANT pointVar;

      //This function will create VARIANT of sketch point
      GetPackedVariantWithIDispatchSafeArray(m_pSwApp, annotationAttachEntities, pointVar);

            
      VARIANT_BOOL status;

      //pPmiAnnotation is annotation get from INote using INote::GetAnnotation() method (INote is inserted using        IModelDoc2::InsertNote() method)
      pPmiAnnotation->SetAttachedEntities(pointVar, &status);

           
}

//=================================================

 

Anybody knows, Why "pPmiAnnotation->SetAttachedEntities()" API didn't work while attaching SketchPoint to annotation?

 

Thanks and Regards,
Mahadev

Outcomes