ObjectARX

Reply
Member
scatler
Posts: 4
Registered: ‎03-29-2012
Message 1 of 7 (347 Views)

Adding custom objects to autocad drawing through com

347 Views, 6 Replies
03-29-2012 10:59 AM

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?

Distinguished Mentor
owenwengerd
Posts: 593
Registered: ‎08-06-2002
Message 2 of 7 (342 Views)

Re: Adding custom objects to autocad drawing through com

03-29-2012 11:31 AM 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
Member
scatler
Posts: 4
Registered: ‎03-29-2012
Message 3 of 7 (340 Views)

Re: Adding custom objects to autocad drawing through com

03-29-2012 11:36 AM in reply to: owenwengerd

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

Member
scatler
Posts: 4
Registered: ‎03-29-2012
Message 4 of 7 (338 Views)

Re: Adding custom objects to autocad drawing through com

03-29-2012 11:44 AM 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

Distinguished Mentor
owenwengerd
Posts: 593
Registered: ‎08-06-2002
Message 5 of 7 (327 Views)

Re: Adding custom objects to autocad drawing through com

03-29-2012 05:50 PM 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
Member
scatler
Posts: 4
Registered: ‎03-29-2012
Message 6 of 7 (324 Views)

Re: Adding custom objects to autocad drawing through com

03-29-2012 09:04 PM 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 =)

Distinguished Mentor
owenwengerd
Posts: 593
Registered: ‎08-06-2002
Message 7 of 7 (322 Views)

Re: Adding custom objects to autocad drawing through com

03-29-2012 09:13 PM 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community