Log in

View Full Version : Solved: vc++ to c#.net conversion



shamsam1
05-14-2009, 08:32 AM
we have developed code in vc++ i want convert vc++code to c# and output file is dll file.
in vc++ output file is arx.

this is one of the .cpp file i want to convert to c# file.and compile it
how to convert the header files(.h)

fist cpp file


#include "stdafx.h"
#include "resource.h"
#include "AcSSGetFilterEntityType.h"
#include "Func.h"

#include <adslib.h>
#include <acedads.h>


// CAcSSGetFilterEntityTypeDst construction

CAcSSGetFilterEntityType::CAcSSGetFilterEntityType()
: m_bPrintInfo( TRUE )
{
}

CAcSSGetFilterEntityType::~CAcSSGetFilterEntityType()
{
}

void CAcSSGetFilterEntityType::ssgetAddFilter(
int ssgetFlags,
AcEdSelectionSetService &service,
const AcDbObjectIdArray& selectionSet,
const AcDbObjectIdArray& subSelectionSet)
{
ads_name eName;
AcDbObjectId id;
int i;

BOOL bRemove = FALSE;

for( i = 0; i < subSelectionSet.length(); i++)
{
resbuf *prbHead = NULL, *prbNext;

service.ssNameX(true, i, prbHead);

prbNext = prbHead;
while( NULL != prbNext )
{
if( RTENAME == prbNext->restype )
{
eName[0] = prbNext->resval.rlname[0];
eName[1] = prbNext->resval.rlname[1];
if(Acad::eOk == acdbGetObjectId(id, eName))
{
sptEntityType eType = AcGetEntityType( id );

if( (eType & (m_nEntityTypeAllowed) ) == 0 ) // Kontroll att typen ska gå att välja
{
bRemove = TRUE;
service.remove( i );
}
}
}
prbNext = prbNext->rbnext;
}

acutRelRb(prbHead);
}
if( m_bPrintInfo && bRemove)
acutPrintf( "\nEntitet som inte stöds valdes." );
}


second cpp file


//
// Func.cpp : Functions

#include "stdafx.h"
#include "Func.h"
#include "DLLVersion.h"
#include "math.h"

#include <dbapserv.h>
#include <AcExtensionModule.h>
#include <acestext.h>
#include <dbxutil.h>
#include <geassign.h>
#include <dbhatch.h>

AC_DECLARE_EXTENSION_MODULE(theArxDLL);

BOOL sptGetDllVersion( CString &osVersion )
{
BOOL bRet = FALSE;
CString sPath;

GetModuleFileName( theArxDLL.ModuleResourceInstance(), sPath.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
sPath.ReleaseBuffer();

CDLLVersion ver( (LPCSTR)sPath );
if( ( bRet = (ver.IsValid() == TRUE )) )
osVersion = ver.GetFullVersion();

return bRet;
}

/*************************************************************************** *************************************************************************** **
* Purpose: Gets the path to the directory where the application file resides
* Inputs:
* Outputs: ostrAppPath - Path to the application directory
* Assumes:
* Returns: TRUE if successful, otherwise FALSE
* Effects:
* Info:
*************************************************************************** *************************************************************************** **/
BOOL sptGetAppPath( CString &ostrAppPath )
{
if( ::GetModuleFileName( theArxDLL.ModuleResourceInstance(), ostrAppPath.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH ) != 0)
{
ostrAppPath.ReleaseBuffer();

sptGetPath( ostrAppPath, ostrAppPath );

return TRUE;
}

return FALSE;
}

void sptGetPath( const char *szPathFile, CString &osPath )
{
osPath = szPathFile;

int nPos = osPath.ReverseFind( _T( '\\' ) );
if( nPos >= 0 )
osPath = osPath.Left( nPos );
}

BOOL AcCreate3DPolyline( AcDb::Poly3dType type, AcGePoint3dArray& vertices, AcDbObjectId &oidPoly )
{
BOOL bRet = FALSE;
AcDbBlockTable *pBlockTable;
AcDbBlockTableRecord *pBlockTableRecord;

// Get pointer to Model space table block
acdbHostApplicationServices()->workingDatabase()->getBlockTable( pBlockTable, AcDb::kForRead );
pBlockTable->getAt( ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite );
pBlockTable->close();

AcDb3dPolyline *pPoly = new AcDb3dPolyline( type, vertices );
pPoly->setLayer( "0" );
if( pBlockTableRecord->appendAcDbEntity( oidPoly, pPoly ) == Acad::eOk )
{
pPoly->close();
bRet = TRUE;
}
else
{
delete pPoly;
LOG0( LevelError, TRUE, "Cannot add AcDb3DPolyline." );
}

pBlockTableRecord->close();

return bRet;
}

/*************************************************************************** *************************************************************************** **
* Purpose: Skapar en text med ptIns som insättningspunkt.
* Inputs: ptIns - Insättningspunkt för texten
* dAng - Rotation för texten i radianer, moturs och start kl 3
* szTextVal - Textvärde
* idLayer - Id på lager
* idTextStyle - Id på textstil
* dFontAngle - Textens lutning
* dSize - Textstorlek
* nColor - Textfärg, AutoCADs färgindex
* hor - Textjustering horisontellt. Använd AcDb::kTextLeft för vänster
* ver - Textjustering vertikalt. Använd AcDb::kTextBase för nedre
* Outputs: oidText - AcDbObjectId för skapad text
* Returns: TRUE - Text skapades
* FALSE - Text skapades inte
* Remarks:
*************************************************************************** *************************************************************************** **/
BOOL AcCreateText( AcGePoint3d ptIns, double dAng, const char *szTextVal, AcDbObjectId idLayer, AcDbObjectId idTextStyle, double dFontAngle, double dSize, int nColor, AcDb::TextHorzMode hor, AcDb::TextVertMode ver, AcDbObjectId &oidText )
{
Acad::ErrorStatus acErr;
BOOL bRet = FALSE;

AcDbText *pText = new AcDbText();
AcCmColor cmColor;

// Add Text to AutoCAD
cmColor.setColorIndex( nColor );
acErr = pText->setColor( cmColor );
acErr = pText->setLayer( idLayer );
acErr = pText->setHorizontalMode( hor );
acErr = pText->setVerticalMode( ver );
acErr = pText->setRotation( dAng );
acErr = pText->setPosition( ptIns );
acErr = pText->setAlignmentPoint( ptIns );
acErr = pText->setHeight( dSize );
acErr = pText->setOblique( dFontAngle );
acErr = pText->setTextString( szTextVal );
acErr = pText->setTextStyle( idTextStyle );

// Get pointer to Model space table block
AcDbBlockTable *pBlockTable;
AcDbBlockTableRecord *pBlockTableRecord;
acdbHostApplicationServices()->workingDatabase()->getBlockTable( pBlockTable, AcDb::kForRead );
pBlockTable->getAt( ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite );
pBlockTable->close();
if( pBlockTableRecord->appendAcDbEntity( oidText, pText ) == Acad::eOk )
{
pText->close();
bRet = TRUE;
}
else
{
delete pText;
LOG0( LevelError, TRUE, "Cannot add AcDbText." );
}
pBlockTableRecord->close();

return bRet;
}

BOOL AcCreateLine( AcGePoint3d ptStart, AcGePoint3d ptEnd, AcDbObjectId eLayerId )
{
BOOL bRet = FALSE;
AcDbBlockTable *pBlockTable;
AcDbBlockTableRecord *pBlockTableRecord;
AcDbObjectId id;

// Get pointer to Model space table block
acdbHostApplicationServices()->workingDatabase()->getBlockTable( pBlockTable, AcDb::kForRead );
pBlockTable->getAt( ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite );
pBlockTable->close();

AcDbLine *pLine = new AcDbLine( ptStart, ptEnd);
pLine->setLayer( eLayerId );

if( pBlockTableRecord->appendAcDbEntity( id, pLine ) == Acad::eOk )
{
pLine->close();
bRet = TRUE;
}
else
{
delete pLine;
LOG0( LevelError, TRUE, "Cannot add AcDbLine." );
}

pBlockTableRecord->close();

return bRet;
}

/*************************************************************************** *************************************************************************** **
* Purpose: Tranforms a point between WCS and a local 2D system defined by two points.
* Inputs: pt1 - First point in local system.
* pt2 - Second point in local system.
* pt - Point to transform.
* nDir - Direction of transformation, 0 - From WCS to local system, 1 - From local system to WCS.
* Outputs: optRes - Transformed point.
* Returns: TRUE if successful, FALSE otherwise.
*************************************************************************** *************************************************************************** **/
BOOL AcTrans2D( AcGePoint3d pt1, AcGePoint3d pt2, AcGePoint3d pt, int nDir, AcGePoint3d& optRes )
{
double dLen, dX, dY, dl, dm;

dX = pt2[0] - pt1[0];
dY = pt2[1] - pt1[1];
dLen = sqrt( dX * dX + dY * dY );
if( dLen < 1e-10 )
{
LOG0( LevelError, TRUE, "Divide by zero." );
return FALSE;
}

dl = dX / dLen;
dm = dY / dLen;

optRes[2] = 0.0;
if( nDir == 0 )
{
optRes[0] = dl * (pt[0] - pt1[0]) + dm * (pt[1] - pt1[1]);
optRes[1] = (-dm) * (pt[0] - pt1[0]) + dl * (pt[1] - pt1[1]);
}
else
{
optRes[0] = dl * pt[0] + (-dm) * pt[1] + pt1[0];
optRes[1] = dm * pt[0] + dl * pt[1] + pt1[1];
}

return TRUE;
}

#define MAX_SECTION_BUF 32000
BOOL sptGetINISection( const char *szSection, const char *szFile, CStringArray &oasSection )
{
char *pszValue = (char*)_alloca( MAX_SECTION_BUF );
long lRet;
BOOL bRet = TRUE;
CString sSecRow;

oasSection.RemoveAll();

lRet = ::GetPrivateProfileString( szSection, NULL, "", pszValue, MAX_SECTION_BUF, szFile );

if( lRet == MAX_SECTION_BUF - 1 || lRet == MAX_SECTION_BUF - 2 ) // Not big enough buffer
{
long lMaxBuffer = 100000;
lRet = lMaxBuffer - 2;
for( int i = 2; i < 5 && (lRet == lMaxBuffer - 1 || lRet == lMaxBuffer - 2); i++ )
{
lMaxBuffer *= i;
pszValue = (char *)_alloca( lMaxBuffer );
lRet = ::GetPrivateProfileString( szSection, NULL, "", pszValue, lMaxBuffer, szFile );
}
if( lRet == lMaxBuffer - 1 || lRet == lMaxBuffer - 2 ) // Not big enough buffer
bRet = FALSE;
}

if( bRet )
{
for( int nInd = 0; pszValue[nInd] != _T( '\0' ); nInd++ )
{
sSecRow = &pszValue[nInd];
sSecRow.TrimLeft();
sSecRow.TrimRight();
oasSection.Add( sSecRow );

nInd += strlen( &pszValue[nInd] );
}
}

return bRet;
}

BOOL AcSetVar( const char *szVarName, short nNewVal, short &onOldVal )
{
int nRet;
struct resbuf rb;
CString sErr;
short nOld;

acedGetVar( szVarName, &rb );

if( rb.restype == RTSHORT )
nOld = rb.resval.rint;
else
{
LOG1( LevelError, TRUE, "Invalid SETVAR type used for variable '%s'.", szVarName );
return FALSE;
}

rb.resval.rint = nNewVal;

nRet = acedSetVar( szVarName, &rb );

onOldVal = nOld;

if( nRet == RTNORM )
return TRUE;

LOG1( LevelError, TRUE, "SETVAR returned error for variable '%s'.", szVarName );

return FALSE;
}

BOOL AcSetVar( const char *szVarName, double dNewVal, double &odOldVal )
{
int nRet;
struct resbuf rb;
CString sErr;
double dOld;

acedGetVar( szVarName, &rb );

if( rb.restype == RTREAL )
dOld = rb.resval.rreal;
else
{
LOG1( LevelError, TRUE, "Invalid SETVAR type used for variable '%s'.", szVarName );
return FALSE;
}

rb.resval.rreal = dNewVal;

nRet = acedSetVar( szVarName, &rb );

odOldVal = dOld;

if( nRet == RTNORM )
return TRUE;

LOG1( LevelError, TRUE, "SETVAR returned error for variable '%s'.", szVarName );

return FALSE;
}

// Helper to split a string into a CStringArray. Takes one character as split character.
void sptSplit( const char *szText, const char chSplitChar, BOOL bTrim, CStringArray &oastrRes )
{
int nPos;
CString sTmp, sText( szText );

oastrRes.RemoveAll();

for( ; (nPos = sText.Find( chSplitChar )) >= 0; )
{
sTmp = sText.Left( nPos );
if( bTrim )
{
sTmp.TrimLeft();
sTmp.TrimRight();
}
oastrRes.Add( sTmp );
sText = sText.Mid( nPos + 1 );
}
if( !sText.IsEmpty() )
{
if( bTrim )
{
sText.TrimLeft();
sText.TrimRight();
}
oastrRes.Add( sText );
}
}

// Adds a layer to the drawing if it does not already exist.
BOOL AcAddLayer( const char* szLayerName, int nColor, AcDbObjectId eLineTypeId, int nLineWeight, AcDbObjectId& oeLayerId )
{
Acad::ErrorStatus acErr;
BOOL bRet = FALSE;
TCHAR szNum[10];
AcDbLayerTable* pLayerTable;

if( (acErr = acdbHostApplicationServices()->workingDatabase()->getLayerTable( pLayerTable, AcDb::kForWrite )) == Acad::eOk )
{
if( pLayerTable->getAt( szLayerName, oeLayerId ) != Acad::eOk )
{
if( nColor <= 0 || nColor >= 256 )
{
LOG1( LevelError, TRUE, _T( "Invalid color number '%s'." ), itoa(nColor, szNum, 10) );
nColor = 7; // Default color
}

AcCmColor cmColor;
cmColor.setColorIndex( (unsigned short)nColor );

AcDbLayerTableRecord* pLayerTableRecord = new AcDbLayerTableRecord;
pLayerTableRecord->setName( szLayerName );
pLayerTableRecord->setColor( cmColor );
if( eLineTypeId )
pLayerTableRecord->setLinetypeObjectId( eLineTypeId );
if( pLayerTableRecord->setLineWeight( (AcDb::LineWeight)nLineWeight ) != Acad::eOk )
LOG2( LevelError, TRUE, _T( "Invalid linetype weight '%s' for layer '%s'." ), itoa( nLineWeight, szNum, 10), szLayerName );

if( pLayerTable->add( oeLayerId, pLayerTableRecord ) != Acad::eOk )
{
LOG2( LevelError, TRUE, "Unable to add layer '%s', error '%s'.", szLayerName, acadErrorStatusText( acErr ) );
delete pLayerTableRecord;
}
else // Succeded to create new layer
{
pLayerTableRecord->close( );
bRet = TRUE;
}
}
else
bRet = TRUE;

pLayerTable->close( );
}
else
LOG1( LevelError, TRUE, "Unable to open layer table, error '%s'.", acadErrorStatusText( acErr ) );

return bRet;
}

// Gets a layer in the drawing
BOOL AcGetLayer( const char* szLayerName, AcDbObjectId& eLayerId )
{
Acad::ErrorStatus acErr;
BOOL bRet = FALSE;
AcDbLayerTable* pLayerTable;

if( (acErr = acdbHostApplicationServices()->workingDatabase()->getLayerTable( pLayerTable, AcDb::kForWrite )) == Acad::eOk )
{
if( (acErr = pLayerTable->getAt( szLayerName, eLayerId )) == Acad::eOk )
bRet = TRUE;
else
LOG2( LevelError, TRUE, "Unable to find layer '%s', error '%s'.", szLayerName, acadErrorStatusText( acErr ) );
pLayerTable->close( );
}
else
LOG1( LevelError, TRUE, "Unable to open layer table, error '%s'.", acadErrorStatusText( acErr ) );

return bRet;
}

// Returnera lagret ett objekt ligger på
CString AcGetLayerForObject( AcDbObjectId idObj )
{
Acad::ErrorStatus acErr;
AcDbEntity* pEnt;
CString sRet;

if( (acErr = acdbOpenAcDbEntity(pEnt, idObj, AcDb::kForRead)) != Acad::eOk)
{
LOG1( LevelError, TRUE, "Unable to open object, error '%s'.", acadErrorStatusText( acErr ) );
return "";
}

sRet = pEnt->layer();
pEnt->close();

return sRet;
}

// Returns all nodes (vertices) for a polyline in WCS
// If nArcNum = 0 arcs are considered to be straight lines, i.e. the start- and endpoint of the arc are added to the list
// If nArcNum > 0 arcs are approximated with start- and endpoint plus the number of points specified by nArcNum.
BOOL AcGetPolylineNodes( AcDbPolyline *pPoly, int nArcNum, AcGePoint3dArray &oaptNodes )
{
AcGePoint3d pt;

// Loop all segments
int numVerts = pPoly->numVerts();
for(int i=0; i<numVerts; i++)
{
pPoly->getPointAt( i, pt );
oaptNodes.append( pt );
if( i<(numVerts-1) && nArcNum > 0 )
{
double dBulge, dStartParam, dEndParam, dIncParam;

pPoly->getBulgeAt( i, dBulge );
if( fabs( dBulge ) > 0.0 )
{
pPoly->getParamAtPoint( pt, dStartParam );
pPoly->getPointAt( i+1, pt );
pPoly->getParamAtPoint( pt, dEndParam );

// Start- och slutpunkterna för bågen läggs till oaptNodes automatiskt.
// Räkna ut mellanliggande punkter
dIncParam = (dEndParam - dStartParam) / (1+nArcNum);
for( int j=1; j<=nArcNum; j++ )
{
pPoly->getPointAtParam( dStartParam + j*dIncParam, pt );
oaptNodes.append( pt );
}
}
}
}
if( pPoly->isClosed() )
oaptNodes.append( oaptNodes.at( 0 ) );

return TRUE;
}

// Returns all nodes (vertices) for a polyline in WCS
// Arcs are considered to be straight lines, i.e. the start- and endpoint of the arc are added to the list
BOOL AcGetPolylineNodes( AcDb3dPolyline *pPoly3d, AcGePoint3dArray &oaptNodes )
{
AcGePoint3d pt;
AcDbObjectIterator *pVertIter= pPoly3d->vertexIterator();
AcDb3dPolylineVertex *pVertex;

for(; !pVertIter->done(); pVertIter->step())
{
acdbOpenObject(pVertex, pVertIter->objectId(), AcDb::kForRead);

pt = pVertex->position();
pVertex->close();
oaptNodes.append( pt );
}
delete pVertIter;

if( pPoly3d->isClosed() )
oaptNodes.append( oaptNodes.at( 0 ) );

return TRUE;
}

BOOL AcOpenBlock( ads_name eBlock, AcDb::OpenMode mode, AcDbBlockReference *&opBlock )
{
Acad::ErrorStatus acErr;
AcDbObjectId id;

acdbGetObjectId( id, eBlock );
if( (acErr = acdbOpenObject( opBlock, id, mode)) == Acad::eOk )
return TRUE;
else
LOG1( LevelError, TRUE, "Unable to open block for write acces, error '%s'.", acadErrorStatusText( acErr ) );

return FALSE;
}

// Returns TRUE if ent is AcDbPolyline or AcDb3dPolyline
BOOL IsSupportedPolyline( ads_name ent, BOOL bAllowClosed )
{
Acad::ErrorStatus acErr;
BOOL bRet = TRUE;
AcDbObjectId id;
AcDbPolyline *pPoly;
AcDb3dPolyline *pPoly3d;

acdbGetObjectId( id, ent );
if( (acErr = acdbOpenObject( pPoly, id, AcDb::kForRead)) == Acad::eOk )
{
if( !bAllowClosed && pPoly->isClosed() )
bRet = FALSE;
pPoly->close();
return bRet;
}
else if( (acErr = acdbOpenObject( pPoly3d, id, AcDb::kForRead)) == Acad::eOk )
{
if( !bAllowClosed && pPoly3d->isClosed() )
bRet = FALSE;
pPoly3d->close();
return bRet;
}
else
bRet = FALSE;

return bRet;
}

double GetCurveLength( AcDbCurve *pCurve )
{
double dEndParam, dLength = 0.0;

pCurve->getEndParam( dEndParam );
pCurve->getDistAtParam( dEndParam, dLength );

return dLength;
}

long AcGetObjectIds( ads_name ss, AcDbObjectIdArray& oaidEntities )
{
long l, len = 0;
AcDbObjectId id;
ads_name e;

acedSSLength( ss, &len );
for( l=0; l<len; l++ )
{
acedSSName( ss, l, e );
if( acdbGetObjectId( id, e ) != Acad::eOk )
return -1;
oaidEntities.append( id );
}

return len;
}


sptEntityType AcGetEntityType( AcDbObjectId idObj )
{
sptEntityType eRet = kOther;
Acad::ErrorStatus acErr;
AcDbEntity* pEnt;

if( (acErr = acdbOpenAcDbEntity(pEnt, idObj, AcDb::kForRead)) != Acad::eOk)
{
LOG1( LevelError, TRUE, "Unable to open object, error '%s'.", acadErrorStatusText( acErr ) );
return eRet;
}

eRet = AcGetEntityType( pEnt );
pEnt->close();

return eRet;
}

sptEntityType AcGetEntityType( AcDbEntity* pEnt )
{
sptEntityType eRet = kOther;

// Kontrollera objektets typ
if( pEnt->isKindOf( AcDbLine::desc() ))
eRet = kAcDbLine;
else if( pEnt->isKindOf( AcDbPolyline::desc() ))
eRet = kAcDbPolyline;
else if( pEnt->isKindOf( AcDb2dPolyline::desc() ))
eRet = kAcDb2dPolyline;
else if( pEnt->isKindOf( AcDb3dPolyline::desc() ))
eRet = kAcDb3dPolyline;
else if( pEnt->isKindOf( AcDbText::desc() ))
eRet = kAcDbText;
else if( pEnt->isKindOf( AcDbBlockReference::desc() ))
eRet = kAcDbBlockReference;
else if( pEnt->isKindOf( AcDbHatch::desc() ))
eRet = kAcDbHatch;

return eRet;
}


long AcGetSelSet( const AcDbObjectIdArray& aidEntities, ads_name ss )
{
long lRes = aidEntities.length();
ads_name e;

acedSSAdd( NULL, NULL, ss );
for( long l=0; l<lRes; l++ )
{
if( acdbGetAdsName( e, aidEntities.at(l) ) != Acad::eOk )
lRes = -1;
if( acedSSAdd( e, ss, ss ) != RTNORM )
lRes = -1;
}

if( lRes == -1 )
acedSSFree( ss );

return lRes;
}


long AcGetSelSet( const AcDbObjectId& idEnt, ads_name ss )
{
AcDbObjectIdArray aid;
aid.append( idEnt );
return AcGetSelSet( aid, ss );
}

BOOL sptGetEndPoints( const AcDbObjectId& id, AcGePoint3d &optStart, AcGePoint3d &optEnd )
{
BOOL bRet = FALSE;
AcDbCurve *pCurve;

if( sptOpenCurve( FALSE, id, pCurve ) )
{
pCurve->getStartPoint( optStart );
pCurve->getEndPoint( optEnd );
bRet = TRUE;

pCurve->close();
}

return bRet;
}


double sptDistanceToCurve( BOOL b2D, AcDbObjectId idEnt, AcGePoint3d ptGiven, AcGePoint3d &optOnCurve, double &odDistOnCurve )
{
Acad::ErrorStatus acErr;
AcDbCurve *pCurve;

if( sptOpenCurve( b2D, idEnt, pCurve ) )
{
acErr = pCurve->getClosestPointTo( ptGiven, AcGeVector3d::kZAxis, optOnCurve );
acErr = pCurve->getDistAtPoint( optOnCurve, odDistOnCurve );

if( b2D )
delete pCurve;
else
pCurve->close();

return ptGiven.distanceTo( optOnCurve );
}

return -1.0;
}


double sptDistanceToCurve( BOOL b2D, AcDbObjectId idEnt, AcGePoint3d ptGiven )
{
AcGePoint3d ptOnCurve;
double dDistOnCurve;

return sptDistanceToCurve( b2D, idEnt, ptGiven, ptOnCurve, dDistOnCurve );
}

BOOL sptOpenCurve( BOOL b2D, AcDbObjectId idEnt, AcDbCurve *&opCurve )
{
Acad::ErrorStatus acErr;

AcDbEntity *pEnt;
if( (acErr=acdbOpenAcDbEntity( pEnt, idEnt, AcDb::kForRead, false )) != Acad::eOk )
{
LOG1( LevelError, TRUE, "Unable to open object, error '%s'.", acadErrorStatusText( acErr ) );
return FALSE;
}
AcDbCurve *pCurve = AcDbCurve::cast( pEnt );
if( !pCurve )
{
pEnt->close();
LOG1( LevelError, TRUE, "Unsupported entity type, handle '%s'.", AcGetHandle( pEnt->objectId() ) );
return FALSE;
}
if( b2D )
{
pCurve->getOrthoProjectedCurve( AcGePlane(), opCurve );
pCurve->close();
}
else
opCurve = pCurve;

return TRUE;
}

CString AcGetHandle( const AcDbObjectId& id )
{
CString sHandle;
id.handle().getIntoAsciiBuffer( sHandle.GetBuffer( 17 ) );
sHandle.ReleaseBuffer();

return sHandle;
}

BOOL AcEraseEntity( const AcDbObjectId& id, BOOL bErase /* = TRUE */ )
{
Acad::ErrorStatus acErr;
AcDbEntity *pEnt;

Adesk::Boolean erasing = bErase ? Adesk::kTrue : Adesk::kFalse;

if( (acErr = acdbOpenAcDbEntity(pEnt, id, AcDb::kForWrite, true)) != Acad::eOk)
{
LOG1( LevelError, TRUE, "Unable to open object, error '%s'.", acadErrorStatusText( acErr ) );
return FALSE;
}

if( (acErr = pEnt->erase( erasing )) != Acad::eOk)
{
LOG1( LevelError, TRUE, "Unable to erase object, error '%s'.", acadErrorStatusText( acErr ) );
pEnt->close();
return FALSE;
}

pEnt->close();

return TRUE;
}