Open assembly with specific design view representation in C++

By Xiaodong Liang

If you want to open in a specific design view, you need to use OpenWithOptions, while the Open method can only open the assembly with LOD (Level of Detail) option.

Following is a code to open an assembly with last active LOD and last active design view

static HRESULT GetInventorInformation()
{
    HRESULT Result = NOERROR;

    // Assume Inventor application pInvApp is available
    CComPtr<Inventor::Documents> pAllDocs = NULL;
    Result = pInvApp->get_Documents(&pAllDocs);

    CComPtr<Inventor::FileManager> pFileManager;
    Result = pInvApp->get_FileManager(&pFileManager);

    _bstr_t bsCurrentDocumentName(L"C:\\test.iam");

    // get last LOD
    BSTR strLastActiveLOD;
    Result = pFileManager->
        GetLastActiveLevelOfDetailRepresentation(bsCurrentDocumentName,
        &strLastActiveLOD);

    // get last Design View Representation
    BSTR strLastActiveView;
    Result = pFileManager->
        GetLastActiveDesignViewRepresentation(bsCurrentDocumentName,
        &strLastActiveView);

    BSTR strFullDocumentName;
    Result = pFileManager->
        GetFullDocumentName(bsCurrentDocumentName, strLastActiveLOD,
        &strFullDocumentName);

    CComPtr<Inventor::NameValueMap> nameValueMap = NULL;
    pInvApp->TransientObjects->CreateNameValueMap(&nameValueMap);

    nameValueMap->
        Add(_bstr_t("LevelOfDetailRepresentation"),
        _variant_t( strLastActiveLOD) );
    
    nameValueMap->
        Add(_bstr_t("DesignViewRepresentation"),
        _variant_t( strLastActiveView ));

    CComPtr<Inventor::Document> pDocument = NULL;
    //pDocument = pAllDocs->MethodOpen(strFullDocumentName,VARIANT_TRUE);
    pDocument = pAllDocs->
        MethodOpenWithOptions(bsCurrentDocumentName, nameValueMap,
        _variant_t(VARIANT_TRUE));

    return Result;
}

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading