Create a drawing file (IDW or DWG)

Top  Previous  Next

This code (with error checking omitted) creates a new empty drawing file:


    // Get the pointer to the Inventor application...

    CComPtr<Application> pInvApp = ...


    // Get IDW drawing template file

    CComBSTR strTemplateFilename; 

    CComPtr<FileManager> pFileManager  ;

    HRESULT hRes = pInvApp->get_FileManager(&pFileManager);

    hRes = pFileManager->GetTemplateFile(kDrawingDocumentObject, // i.e. an IDW or DWG



                                         CComVariant(),         // Empty and unused



    CComPtr<Documents> pDocuments;

    pInvApp->get_Documents (&pDocuments) ;


    // create a new drawing from the standard template

    CComPtr<Document> pDocument  ;

    hRes = pDocuments->Add (kDrawingDocumentObject,


                            VARIANT_TRUE, // Create Visible



    // Convert from the "general document" type into the "drawing document" type...

    CComQIPtr<DrawingDocument> pDrawingDoc ;

    pDrawingDoc = pDocument ;


When you do copy/paste of this code for other document types, remember to change the enumerator of the types in both calls.


Also note that the document you create will already have one sheet in it, you normally do not need to add any more. It is more likely that you want to add views to the sheet.



See also creating an assembly.




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