Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

AddFitted and AddByTwoPoints problems...(C++/COM)

oransen
Collaborator
Collaborator

AddFitted and AddByTwoPoints problems...(C++/COM)

oransen
Collaborator
Collaborator

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...

 

0 Likes
Reply
Accepted solutions (1)
384 Views
2 Replies
Replies (2)

oransen
Collaborator
Collaborator
Accepted solution

Dear Owen,

 

You have to bracket the addition of lines and text etc into a DrawingSketch with...

 

    pDrawingSketch->Edit();

    ...add stuff to the sketch...

    pDrawingSketch->ExitEdit();

Edit and ExitEdit. Ha! Odd, but works...

 

 

0 Likes

chandra.shekar.g
Autodesk Support
Autodesk Support

@oransen,

 

That's right way of editing / adding entities to drawing sketch.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network