Hi everybody! I am learning objectarx now (2011 version) and I want to create my custom object with some custom properties (which can be edited throug com, for example with VBA). There is a good example in SDK called square wrapper. Everything is ok with it, I have added some extra functionality to square and It works fine, but the question is: how to implement add function , which will be adding my custom entity to autocad drawing. The function should be the same as AddCircle or AddLine. Any suggestions?
You can implement a COM class for your application, then add a AddMyEntity method on an interface exposed by that class. The main point is that you have to implement it yourself; AutoCAD has no way of doing it for you.
--
Owen Wengerd
ManuSoft
That right! I have wrote this function already, but it is actually empty 😃 What should be inside of this function?
I think the question is how to reach the autocad database pointer from the com wrapper and then use it to add an custom object
Sorry, I guess I don't understand the problem. If you already have an entity, and you're writing a function on the entity's COM wrapper class to add the existing entity to a database, then you need some way to specify where to add it, either as an argument to the function or some other way. I would probably use a single argument to specify the block table record to add the entity to.
--
Owen Wengerd
ManuSoft
I meant my function don't work. Here is the code:
STDMETHODIMP CMyClass::AddFunction (DOUBLE val, LONG node, SHORT type)
{
// TODO: Add your implementation code here
CComPtr<IAsdkSquareWrapper> pSquare;
CComQIPtr<IAcadBaseObject2> pSquareBase;
CComQIPtr<IConnectionPointContainer> pConnectionPts;
CComPtr<IConnectionPoint> pConnection;
HRESULT hr = S_OK;
hr = pSquare.CoCreateInstance(CLSID_AsdkSquareWrapper);
pSquareBase = pSquare;
hr = pSquareBase->CreateObject();
// Set the square object up for OPM
//acedSetIUnknownForCurrentCommand(pSquare);
AcAxPoint3d pnt3d(0, 0, 0);
pSquare->put_CenterPoint(*(pnt3d.asVariantPtr()));
pSquare->put_SquareSize(val);
//pSquare->put_Number (val);
AcDbObjectId squareId;
hr = pSquareBase->AddToDb(squareId, curDoc()->database()->currentSpaceId());
return S_OK;
}
The problem is in the curdoc(). It doesn't know what is the current document. I hope you will understand me 😃
You can use acdbHostApplicationServices()->workingDatabase() to get the working database, but your code must handle the case when this function returns NULL.
Can't find what you're looking for? Ask the community or share your knowledge.