Adding lines, text, and circles to a DrawingSketch

Top  Previous  Next

A DrawingSketch is a 2D sketch created on an Inventor drawing, an IDW. Here is an example which creates a DrawingSketch and then adds some radial lines and some text to it:

 

   // Find the sheets of the drawing document...

   CComPtr<Sheets> pSheets = nullptr ;

   HRESULT hRes = pDrawingDoc->get_Sheets(&pSheets) ;

   if (FAILED(hRes)) {

       ShowCOMError (hRes,L"ASTI, could not get sheets of drawing document.");

       return ;

   }

 

   // 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 ;

   hRes = pSheet->get_Sketches(&pSketches);

   if (FAILED(hRes)) {

       ShowCOMError (hRes,L"ASTI, could not get drawing sketches.");

       return ;

   }

 

   CComPtr<DrawingSketch> pDrawingSketch ;

   hRes = pSketches->Add(&pDrawingSketch);

   if (FAILED(hRes)) {

       ShowCOMError (hRes,L"ASTI, could not aad sketch.");

       return ;

   }

 

   pDrawingSketch->Edit();

 

   CComPtr<SketchLines> pSketchLines;

   pDrawingSketch->get_SketchLines(&pSketchLines);

   if (FAILED(hRes)) {

       ShowCOMError (hRes,L"ASTI, could not get sketch lines.");

       return ;

   }

 

   CComPtr<TransientGeometry> pTrGeom = GetTransGeomPtr() ;

 

   for (int iDegs = 0; iDegs < 360; iDegs+=15) {

       CComPtr<Point2d> pStartPoint;

       pTrGeom->CreatePoint2d(0.0,0.0,&pStartPoint); 

 

       const double x = 100 * cos(RadsFromDegs(iDegs));

       const double y = 100 * sin(RadsFromDegs(iDegs));

 

       CComPtr<Point2d> pEndPoint;

       pTrGeom->CreatePoint2d(x,y,&pEndPoint); 

 

       pSketchLines->AddByTwoPoints((IDispatch*)pStartPoint,(IDispatch*)pEndPoint);

   }

 

 

   CComPtr<Point2d> pTextPos,pDimPos1,pDimPos2;

   hRes = pTrGeom->CreatePoint2d(1.0,3.0,&pTextPos); 

 

   CComBSTR TestText(L"Hello");

   CComVariant StyleName(L"Note Text (ISO)");

 

   hRes = pDrawingSketch->TextBoxes->AddFitted(pTextPos, TestText, StyleName);

   if (FAILED(hRes)) {

       ShowCOMError (hRes,L"ASTI, AddFitted failed.");

       return ;

   }

 

   pDrawingSketch->ExitEdit(); // Close the sketch editing

 

You'll get this, note the origin and that it is not clipped.

 

 

Drawing-on-a-Sketch

 

The first part of the above code can be encapsulated as shown here.

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)