Add a sketch to an assembly or part |
Top Previous Next |
You can use these two functions:
// Adds a sketch to one of the three standard workplanes in a part bool AddSketchToStdPartWorkplane (CComPtr<PlanarSketch>& pNewSketch, CComPtr<PartComponentDefinition>& pPartCompDef, const wchar_t* const pszNewSketchName, const UINT ikWorkPlaneNumber) // gikXIndex, gikYIndex, gikZIndex { if ((pszNewSketchName == nullptr) || (wcslen(pszNewSketchName) == 0)) { gLogger.Printf (ekErrMsg,L"ASTSPW, workplane name incorrect") ; return false; }
CComPtr<WorkPlane> pWorkPlane; bool bOk = GetStdWorkPlaneByIndex(pWorkPlane, ikWorkPlaneNumber, pPartCompDef); if (!bOk) { return false; }
// Get the list of sketches CComPtr<PlanarSketches> pSketchList ; HRESULT hRes = pPartCompDef->get_Sketches (&pSketchList); if (FAILED(hRes)) { ShowCOMError (hRes,L"ASTSPW, could not get planar sketches") ; return false; }
hRes = pSketchList->Add (_variant_t((IDispatch *)pWorkPlane),VARIANT_FALSE,&pNewSketch) ; if (FAILED(hRes)) { ShowCOMError (hRes,L"ASTSPW, could not get planar sketches") ; return false; }
pNewSketch->put_Name (CComBSTR (pszNewSketchName)) ;
return true; }
/*******************************************************************************************************/
bool AddSketchToStdAssemblyWorkplane(CComPtr<PlanarSketch>& pNewSketch, CComPtr<AssemblyComponentDefinition>& pAsmCompDef, const wchar_t* const pszNewSketchName, const UINT ikWorkPlaneNumber) // gikXIndex, gikYIndex, gikZIndex { // Get the work plane from the list of work planes in the part... CComPtr<WorkPlane> pWorkPlane; HRESULT hRes = pAsmCompDef->WorkPlanes->get_Item(CComVariant(ikWorkPlaneNumber), &pWorkPlane); if (FAILED(hRes)) { ShowCOMError (hRes,L"ASTSAW but 'get' %d failed\n",ikWorkPlaneNumber); return false ; }
// Get the list of sketches CComPtr<PlanarSketches> pSketchList ; hRes = pAsmCompDef->get_Sketches (&pSketchList); if (FAILED(hRes)) { ShowCOMError (hRes,L"ASTSAW, could not get planar sketches") ; return false; }
hRes = pSketchList->Add (_variant_t((IDispatch *)pWorkPlane),VARIANT_FALSE,&pNewSketch) ; if (FAILED(hRes)) { ShowCOMError (hRes,L"ASTSAW, could not get planar sketches") ; return false; }
pNewSketch->put_Name (CComBSTR (pszNewSketchName)) ;
return true; }
|
Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)