By Adam Nagy
I started with the C:\Users\Public\Documents\Autodesk\Inventor 2013\SDK\DeveloperTools\Samples\VC++\AddIns\SimpleAddIn sample project. I added to the resources a bitmap file, which got the resource ID IDB_BITMAP1 assigned and was using a palette – as mentioned in the code in that case it seems that the LR_CREATEDIBSECTION flag is needed when loading the resource. Then replaced the code inside one of the ButtonDefinitionEvents_OnExecute with the below code. I tested this on a 64 bit OS.
HRESULT hr;
CComPtr<Document> doc =
CComPtr<Document> doc =
m_pApplication->ActiveDocument;
if (doc)
{
// LR_CREATEDIBSECTION was needed for my bitmap with palette
HBITMAP hBmp = (HBITMAP) LoadImage(
_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(IDB_BITMAP1),
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
ATLASSERT(hBmp);
if (NULL == hBmp) return E_FAIL;
// Create the picture
PICTDESC pdesc;
pdesc.cbSizeofstruct = sizeof(pdesc);
pdesc.picType = PICTYPE_BITMAP;
pdesc.bmp.hbitmap = hBmp;
pdesc.bmp.hpal = 0;
CComPtr<IPictureDisp> pPictureDisp;
hr = ::OleCreatePictureIndirect(
&pdesc, IID_IPictureDisp, FALSE, (LPVOID*)&pPictureDisp );
&pdesc, IID_IPictureDisp, FALSE, (LPVOID*)&pPictureDisp );
if(FAILED(hr)) return hr;
// Add to data set
CComPtr<GraphicsDataSets> dataSet;
hr = doc->GraphicsDataSetsCollection->Add(_bstr_t("MyDataSet"), &dataSet);
CComPtr<GraphicsImageSet> imageSet;
hr = dataSet->CreateImageSet(2, &imageSet);
hr = imageSet->Add(1, pPictureDisp, vtMissing, 0, 0);
// Add to custom graphics
CComQIPtr<PartDocument> partDoc = doc;
CComPtr<ClientGraphics> cg;
hr = partDoc->ComponentDefinition->ClientGraphicsCollection->Add(
_bstr_t("MyGraphics"), &cg);
_bstr_t("MyGraphics"), &cg);
CComPtr<GraphicsNode> gn;
hr = cg->AddNode(1, &gn);
CComPtr<PointGraphics> pg;
hr = gn->AddPointGraphics(&pg);
CComPtr<GraphicsCoordinateSet> cs;
hr = dataSet->CreateCoordinateSet(1, &cs);
CComPtr<Point> pt;
hr = m_pApplication->TransientGeometry->CreatePoint(0, 0, 0, &pt);
cs->Add(1, pt);
pg->PutCoordinateSet(cs);
hr = pg->SetCustomImage(imageSet, 1);
m_pApplication->ActiveView->Update();
}
And here is the result:



Leave a Reply