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

OLE ObjectArx - my misapprehension?

1 REPLY 1
Reply
Message 1 of 2
Kyudos
106 Views, 1 Reply

OLE ObjectArx - my misapprehension?

So, the documentation for AcDbOle2Frame::setOleObject says:

 

Sets the AcDbOle2Frame object to use the MFC COleClientItem object pointed to by pItem.
The COleClientItem class used by AutoCAD is a modified version of the class that ships from Microsoft. This means that it is not possible for applications to create their own COleClientItem objects for use by this function. This function can only be used with COleClientItem objects created by AutoCAD (that is, the object from another AcDbOle2Frame object).

 

I took this to mean that OLE items couldn't be created in ObjectARX and added to my DWG. Admittedly, I never actually tried it until now. However, something like this does actually work:

 

 

 

Acad::ErrorStatus es = Acad::eOk;
CADManager.StartTransaction(__FUNCTION__);

AcDbOle2Frame* pNewFrame = new AcDbOle2Frame();
pNewFrame->setDatabaseDefaults();

AcDbDatabase* db = acdbHostApplicationServices()->workingDatabase();

AcDbBlockTable* blockTable;
es = db->getBlockTable(blockTable, AcDb::kForRead);

AcDbBlockTableRecord* modelSpace;
es = blockTable->getAt(ACDB_MODEL_SPACE, modelSpace, AcDb::kForWrite);

es = modelSpace->appendAcDbEntity(pNewFrame);
es = acdbTransactionManager->addNewlyCreatedDBRObject(pNewFrame);

AcApDocument* pActiveDoc = acDocManager->mdiActiveDocument();
COleDocument* pDoc = (COleDocument *)pActiveDoc->cDoc();

COleClientItem* pItem = new COleClientItem(pDoc);
if (pItem->CreateFromFile(sReportFile))
{
    es = pNewFrame->setOleClientItem(pItem);
}

AcGePoint3d point3d;
point3d.x = -3220;
point3d.y = 5230;
pNewFrame->setLocation(point3d);

CRectangle3d rect3d;
rect3d.lowLeft.x = -3220;
rect3d.lowLeft.y = 5230;
rect3d.lowLeft.z = 0;
rect3d.lowRight.x = -3120;
rect3d.lowRight.y = 5230;
rect3d.lowRight.z = 0;
rect3d.upLeft.x = -3220;
rect3d.upLeft.y = 5330;
rect3d.upLeft.z = 0;
rect3d.upRight.x = -3120;
rect3d.upRight.y = 5330;
rect3d.upRight.z = 0;

pNewFrame->setPosition(rect3d);

pNewFrame->setScaleHeight(100);
pNewFrame->setScaleWidth(100);

// Clean up
es = pNewFrame->close();
es = modelSpace->close();
es = blockTable->close();


CADManager.EndTransaction(__FUNCTION__);

 

 

 

So my question is - is it supposed to work? Am I going to run into problems if I use code like this?

 
Tags (1)
Labels (1)
  • ole
1 REPLY 1
Message 2 of 2
daniel_cadext
in reply to: Kyudos

never used Ole, there's also a AcDbHostApplicationServices::getNewOleClientItem

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report