How to add views to a drawing sheet (Inventor API) |
Top Previous Next |
If you have a new or exisiting drawing it is likely that you want to add views of the 3D object into the sheet. Here is a commented code fragment which shows you to do it (error checking removed). Note also that we open the assembly invisibly so the user does not have to wait for the display of the assembly.
// Choose the IDW drawing template file CComBSTR strTemplateFilename; strTemplateFilename = L"C:\\Users\\Public\\Documents\\Autodesk\\Inventor 2014\\Templates\\Ransen.idw" ;
// Get the list of documents so we can add a new one to it (an IDW) CComPtr<Documents> pDocuments; pInvApp->get_Documents (&pDocuments) ;
// create a new IDW drawing from the selected template CComPtr<Document> pDocument ; HRESULT hRes = pDocuments->Add(kDrawingDocumentObject, strTemplateFilename, VARIANT_TRUE, // true = create the document visible &pDocument);
// Convert from the "general document" type into the "drawing document" type... CComQIPtr<DrawingDocument> pDrawingDoc ; pDrawingDoc = pDocument ;
// Get the sheets in the drawing document. Since this IDW has only just been // created there will be a single sheet CComPtr<Sheets> pSheets ; hRes = pDrawingDoc->get_Sheets(&pSheets) ;
// Get the single sheet inside the IDW. Remember the first object // in a COM list had index 1... CComPtr<Sheet> pSheet ; hRes = pSheets->get_Item (CComVariant(1),&pSheet) ;
// Just for fun, get some data about the sheet... double SheetHeight,SheetWidth ; CComBSTR bstrSheetName ; pSheet->get_Name (&bstrSheetName) ; pSheet->get_Width(&SheetWidth) ; pSheet->get_Height(&SheetHeight) ;
TRACE (L"The first sheet is called <%s> and is %.1f %.1f\n", bstrSheetName,SheetWidth,SheetHeight) ;
// Now, we are going to add 2 views to the sheet, so get the list of views // Since this is a new drawing there will be no views yet, but we need // the list to add a view... CComPtr<DrawingViews> pViews ; hRes = pSheet->get_DrawingViews (&pViews) ;
// Create two points (using the transient geometry machine) which will // position the views in the sheet... CComPtr<TransientGeometry> pTrGeom = GetTransGeomPtr(); CComPtr<Point2d> pPt1; CComPtr<Point2d> pPt2; pTrGeom->CreatePoint2d(10.0,10.0,&pPt1); pTrGeom->CreatePoint2d(10.0,30.0,&pPt2);
// Set the view scales that we need. const double kViewScale1 = 0.25 ; const double kViewScale2 = 0.125 ;
// Now get hold of the assembly which we want to show in the view // (We'll open it invisibly) CComBSTR strAssemblyFilename ; strAssemblyFilename = L"C:\\CollMakeV2\\Coll_IPT_IAM\\new test.iam" ;
CComPtr<Document> pDoc ; hRes = pDocuments->Open (strAssemblyFilename, // what to open VARIANT_FALSE, // open it invisible &pDoc) ; // result
// The 6th parameter of AddBaseView requires a proper BSTR type object // else you'll get out of memory errors CComBSTR bstrModelViewName1 = CString (L"PLUTO") ; CComBSTR bstrModelViewName2 = CString (L"NEPTUNE") ;
// Now create our two views, first the base view on which all the others are based... CComVariant varEmpty ; CComPtr<DrawingView> pBaseView1 ; pViews->AddBaseView (pDoc, // what to show pPt1, // center of view kViewScale1, // size, scale, of view kBottomViewOrientation, // from where to view the doc kHiddenLineDrawingViewStyle, // DrawingViewStyleEnum bstrModel, // must be a BSTR varEmpty,varEmpty, // unused in this case &pBaseView1) ; // the created view
CComPtr<DrawingView> pBaseView2 ; pViews->AddBaseView (pDoc, pPt2, kViewScale2, kRightViewOrientation, kShadedDrawingViewStyle, // DrawingViewStyleEnum bstrModelViewName2, varEmpty,varEmpty, &pBaseView2) ;
pDoc->Close (VARIANT_TRUE) ; // VARIANT_TRUE = close skipping save, obviously
As far as the "where are we looking from" option, these are the most common:
kBottomViewOrientation kBackViewOrientation kCurrentViewOrientation kFrontViewOrientation kLeftViewOrientation kRightViewOrientation kTopViewOrientation
These correspond in the user interface, to the view cube:
|
Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)