Message 1 of 4
Insert DXF or DWG into a planar sketch using COM/C++
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In the API help there is some VB code to do this and I'm translating it into COM/C++.
I think I'm there but I've probably used a bad cast or a wrong pointer type because the very last part crashes
// THIS CALL CRASHES, I SUSPECT THE LAST PARAMETER hRes = pDwgTranslator->Open(pDataMedium, pTranslationContext, pOptions, (IDispatch**)&pPartDoc);
I also suspect this line of mine:
pTranslationContext->OpenIntoExisting = pNewSketch ;
I'm also not sure about...
CComPtr<ApplicationAddIn> pAppAddIn; hRes = pAppAddIns->get_ItemById(CComBSTR("{C24E3AC2-122E-11D5-8E91-0010B541CD80}"), &pAppAddIn); if (FAILED(hRes)) { gLogger.Printf(ekErrMsg, L"get_ItemById failed"); return; } CComPtr<TranslatorAddIn> pDwgTranslator; pDwgTranslator = pAppAddIn; // Is this correct?
The full fragment is here...
hRes = pInvApp->get_ApplicationAddIns(&pAppAddIns); if (FAILED(hRes)) { gLogger.Printf(ekErrMsg, L"get_ApplicationAddIns failed"); return; } CComPtr<ApplicationAddIn> pAppAddIn; hRes = pAppAddIns->get_ItemById(CComBSTR("{C24E3AC2-122E-11D5-8E91-0010B541CD80}"), &pAppAddIn); if (FAILED(hRes)) { gLogger.Printf(ekErrMsg, L"get_ItemById failed"); return; } CComPtr<TranslatorAddIn> pDwgTranslator; pDwgTranslator = pAppAddIn; if (pDwgTranslator == nullptr) { gLogger.Printf(ekErrMsg, L"pDwgTranslator = pAppAddIn did not work"); return; } CComPtr<TransientObjects> pTransientObjects = GetTransientObjectsPtr(); CComPtr<DataMedium> pDataMedium; hRes = pTransientObjects->CreateDataMedium(&pDataMedium); if (FAILED(hRes)) { gLogger.Printf(ekErrMsg, L"CreateDataMedium failed"); return; } pDataMedium->put_FileName(CComBSTR("C:\\Users\\Owen\\TEST.dxf")); CComPtr<TranslationContext> pTranslationContext; hRes = pTransientObjects->CreateTranslationContext(&pTranslationContext); if (FAILED(hRes)) { gLogger.Printf(ekErrMsg, L"CreateTranslationContext failed"); return; } hRes = pNewSketch->Edit(); if (FAILED(hRes)) { gLogger.Printf(ekErrMsg, L"Edit failed"); return; } // !!! I SUSPECT THIS !!! pTranslationContext->OpenIntoExisting = pNewSketch ; CComPtr<NameValueMap> pOptions; hRes = pTransientObjects->CreateNameValueMap(&pOptions); if (FAILED(hRes)) { gLogger.Printf(ekErrMsg, L"Edit failed"); return; } // Specify the layers to import pOptions->Add(BSTR("SelectedLayers"), CComVariant("0")); pOptions->Add(BSTR("InvertLayersSelection"), CComVariant (VARIANT_TRUE)); // Specify the units pOptions->Add(BSTR("FileUnits"), CComVariant("Centimeters")); // ' Set to constraint the end points. pOptions->Add(BSTR("ConstrainEndPoints"), CComVariant (VARIANT_TRUE)); // !!!THIS CALL CRASHES I SUSPECT THE LAST PARAMETER!!! hRes = pDwgTranslator->Open(pDataMedium, pTranslationContext, pOptions, (IDispatch**)&pPartDoc); if (FAILED(hRes)) { gLogger.Printf(ekErrMsg, L"Open DataMedium failed"); return; } pNewSketch->ExitEdit();