ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding custom objects to autocad drawing through com

6 REPLIES 6
Reply
Message 1 of 7
scatler
818 Views, 6 Replies

Adding custom objects to autocad drawing through com

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?

6 REPLIES 6
Message 2 of 7
owenwengerd
in reply to: scatler

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

 

--
Owen Wengerd
ManuSoft
Message 3 of 7
scatler
in reply to: owenwengerd

That right! I have wrote this function already, but it is actually empty 😃 What should be inside of this function?

Message 4 of 7
scatler
in reply to: scatler

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

Message 5 of 7
owenwengerd
in reply to: scatler

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

 

--
Owen Wengerd
ManuSoft
Message 6 of 7
scatler
in reply to: scatler

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 😃

Message 7 of 7
owenwengerd
in reply to: scatler

You can use acdbHostApplicationServices()->workingDatabase() to get the working database, but your code must handle the case when this function returns NULL.

--
Owen Wengerd
ManuSoft

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost