AnsweredAssumed Answered

"pSketchMgr->CreatePoint()" API didn't work in CMacroFeatureManager::Regenerate() callback function.

Question asked by Mahadev Dharme on Aug 13, 2019
Latest reply on Aug 14, 2019 by Mahadev Dharme


We are trying to create point geometry in opened SolidWorks part using C++ APIs. The point coordinates will be specified explicitly. We are trying to create point using following code.

CComPtr<ISldWorks> m_pSwApp;// This will be the addin application.

CComPtr<IModelDoc2> pCADPart;
PS_IF_FAILED_ACTION(SUCCEEDED(m_pSwApp->get_IActiveDoc2(&pCADPart)) && pCADPart != NULL, return E_FAIL;);
CComPtr<ISketchManager> pSketchMgr = NULL;
PS_IF_FAILED_ACTION(SUCCEEDED(pCADPart->get_SketchManager(&pSketchMgr)), return E_FAIL;);

HRESULT hRes = pSketchMgr->Insert3DSketch(TRUE);
hRes = pSketchMgr->put_AddToDB(TRUE);

CComPtr<ISketchPoint> point;
hRes = pSketchMgr->CreatePoint(-0.124229, 0.09779, -0.014756, &point);

hRes = pCADPart->ClearSelection2(TRUE);

hRes = pSketchMgr->Insert3DSketch(TRUE);

hRes = pSketchMgr->put_AddToDB(FALSE);

hRes = pSketchMgr->put_DisplayWhenAdded(TRUE);


With the use of above code in callback action (on action of customized button event) in SolidWorks addin, point gets created and displayed in 3D scene.

However if we use the same code inside the "CMacroFeatureManager::Regenerate(IDispatch* app, IDispatch* modelDoc, IDispatch* feature, VARIANT* pOutput)" function then point is not created. The "pSketchMgr->CreatePoint()" API returns the NULL value.

Anybody knows, Why "pSketchMgr->CreatePoint()" API didn't work in CMacroFeatureManager::Regenerate() callback function?


Thanks and Regards,