I'm missing something in this C++ code. I'm trying to add a line and a text box to a DrawingSketch. Neither work. Maybe it is a cast or pointer problem?
// Get the (assumed) single sheet inside the IDW. Remember the first object // in a COM list had index 1... CComPtr<Sheet> pSheet = nullptr ; hRes = pSheets->get_Item (CComVariant(1),&pSheet) ; if (FAILED(hRes)) { ShowCOMError (hRes,L"ASTI, could not get 1st sheet of drawing."); return ; } CComPtr<DrawingSketches> pSketches = nullptr ; hRes = pSheet->get_Sketches(&pSketches); if (FAILED(hRes)) { ShowCOMError (hRes,L"ASTI, could not get drawing sketches."); return ; } CComPtr<DrawingSketch> pDrawingSketch = nullptr ; hRes = pSketches->Add(&pDrawingSketch); if (FAILED(hRes)) { ShowCOMError (hRes,L"ASTI, could not aad sketch."); return ; } CComPtr<SketchLines> pSketchLines; pDrawingSketch->get_SketchLines(&pSketchLines); if (FAILED(hRes)) { ShowCOMError (hRes,L"ASTI, could not get sketch lines."); return ; } CComPtr<TransientGeometry> pTrGeom = theApp.GetTransGeomPtr() ; CComPtr<Point2d> pTextPos,pDimPos1,pDimPos2; hRes = pTrGeom->CreatePoint2d(1.0,3.0,&pTextPos); CComPtr<Point2d> pStartPoint; hRes = pTrGeom->CreatePoint2d(3.0,1.0,&pStartPoint); CComPtr<Point2d> pEndPoint; hRes = pTrGeom->CreatePoint2d(1.0,8.0,&pEndPoint);
// This call fails... hRes = pSketchLines->AddByTwoPoints((IDispatch*)pStartPoint,(IDispatch*)pEndPoint); if (FAILED(hRes)) { ShowCOMError (hRes,L"ASTI, AddLine failed."); return ; } CComBSTR TestText(L"Hello"); CComVariant StyleName(L"Note Text (ISO)");
// This call fails hRes = pDrawingSketch->TextBoxes->AddFitted(pTextPos, TestText, StyleName); if (FAILED(hRes)) { ShowCOMError (hRes,L"ASTI, AddFitted failed."); return ; }
There are no other errors and the sketch is created in the drawing document. I suspect a COM/C++ error on my part...
Solved! Go to Solution.
Link copied