Author Topic: My Fisrt Arx  (Read 3236 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
My Fisrt Arx
« on: November 04, 2006, 05:19:24 AM »
Yee ha my first ObjectArx program, well kind of, I borrowed a lot from the curves sample. I am a total greenhorn when it comes to c++. How do I strcat in ObjectArx? Please see the lines  //this is here because I don't know how to strcat in c++. What other mistakes did I make?
Thanks

Daniel

Code: [Select]
// Permission to use, copy, modify, and distribute this software in
// source code form for any purpose and without fee is hereby granted,
// provided that the below code is never translated into that ugly looking
// vb visual basic stuff. no offence I'm sure it's a fine language but .. geez
// is it ugly -- hehe just kidding

#if defined(_DEBUG) && !defined(AC_FULL_DEBUG)
#error _DEBUG should not be defined except in internal Adesk debug builds
#endif
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-
#include <stdlib.h>
#include <string.h>
#include <rxobject.h>
#include <rxregsvc.h>
#include <aced.h>
#include <dbsymtb.h>
#include <adslib.h>
#include <geassign.h>
#include <dbapserv.h>
#include "tchar.h"
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-
void dualoffset();
int GetERRNO();
void offset(AcDbObjectId eId , ads_real roffset);
//
Acad::ErrorStatus addToModelSpace(AcDbObjectId&, AcDbEntity*);
void initApp();
void unloadApp();
extern "C"
AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*);
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-

void dualoffset()
{
struct resbuf rb1; //"OFFSETDIST"
struct resbuf rb2; //"LUNITS"
struct resbuf rb3; //"LUPREC"
struct resbuf rb4; //"ERRNO"
struct resbuf rb5; //"OFFSETDIST"
//
ACHAR strValue; //Temp str for OFFSETDIST
ads_real roffset; //Temp str for acedGetReal
ads_name en; //ename
AcGePoint3d pt; //Point3d
AcDbObjectId eId; //ObjectId
AcDbObject *pObj; //pointer Object

//default offset distance
acedGetVar(_T("OFFSETDIST"), &rb1);

//units to be using in acdbRToS
acedGetVar(_T("LUNITS"), &rb2);

//precision to be using in acdbRToS
acedGetVar(_T("LUPREC"), &rb3);

//format the default offset distance
acdbRToS(rb1.resval.rreal, rb2.resval.rint , rb3.resval.rint, &strValue);

//this is here because I don't know how to strcat in c++
acutPrintf(_T("\nEnter offset distance <"));

//this is here because I don't know how to strcat in c++
acutPrintf(&strValue);

//Gets a double to be used in offset distance
int retval = acedGetReal(_T(">: "), &roffset);
switch(retval)
{
case RTNONE:
roffset = rb1.resval.rreal;
break;
case RTCAN:
return;
case RTERROR:
return;
}

//Hmmm this is cool, is this in c#?
entget:

//Selects the entity
int rtval = acedEntSel(_T("\nSelect object to offset: "), en, asDblArray(pt));
if ((rtval == RTERROR) && (GetERRNO() != 52))
{
goto entget;
}
if (rtval == RTCAN)
{
return;
}

//Resets sysvar ERRNO
rb4.restype = RTLONG;
rb4.resval.rlong = 0;
acedSetVar(_T("ERRNO"), &rb4);

//sets sysvar OFFSETDIST
rb5.restype = RTREAL;
rb5.resval.rreal = roffset;
acedSetVar(_T("OFFSETDIST"), &rb5);
//
acdbGetObjectId(eId, en);
acdbOpenObject(pObj, eId, AcDb::kForRead);
pObj->close();
offset(eId , (roffset / 2));
offset(eId , (-roffset / 2));
acdbEntDel(en);
}
//
int GetERRNO()
{
struct resbuf rb1;
acedGetVar(_T("ERRNO"), &rb1);
return rb1.resval.rint;
}
//the rest is borrowed from the curves Sample
void offset(AcDbObjectId eId , ads_real roffset)
{
AcDbCurve *pCurve;
acdbOpenObject(pCurve, eId, AcDb::kForRead);
AcDbVoidPtrArray curves;
pCurve->getOffsetCurves(roffset, curves);
pCurve->close();
AcDbObjectId newCurveId;
addToModelSpace(newCurveId, (AcDbEntity*)curves[0]);
}
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-
Acad::ErrorStatus
addToModelSpace(AcDbObjectId &objId, AcDbEntity* pEntity)
{
AcDbBlockTable *pBlockTable;
AcDbBlockTableRecord *pSpaceRecord;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);
pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord,
AcDb::kForWrite);
pBlockTable->close();
pSpaceRecord->appendAcDbEntity(objId, pEntity);
pEntity->close();
pSpaceRecord->close();
return Acad::eOk;
}
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-
void
initApp()
{
acedRegCmds->addCommand(_T("CRPD_DOFTEST"), _T("CRPD_dof"),
_T("dof"), ACRX_CMD_MODAL, dualoffset);
}
//
void
unloadApp()
{
acedRegCmds->removeGroup(_T("CRPD_DOFTEST"));
}
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-
// ARX entry point
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-
AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
switch (msg) {
case AcRx::kInitAppMsg:
acrxDynamicLinker->unlockApplication(appId);
acrxDynamicLinker->registerAppMDIAware(appId);
initApp();
break;
case AcRx::kUnloadAppMsg:
unloadApp();
}
return AcRx::kRetOK;
}
edited spelling
« Last Edit: November 04, 2006, 10:31:44 AM by Danielm103 »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: My Fisrt Arx
« Reply #1 on: November 04, 2006, 11:56:52 AM »
I found a way!

Code: [Select]
acutPrintf( _T("\nEnter offset distance <%s>: ") , &strValue );

Code: [Select]
// Permission to use, copy, modify, and distribute this software in
// source code form for any purpose and without fee is hereby granted,
// provided that the below code is never translated into that ugly looking
// vb visual basic stuff. no offence I'm sufe it's a fine language but .. geez
// is it ugly -- hehe just kidding

#if defined(_DEBUG) && !defined(AC_FULL_DEBUG)
#error _DEBUG should not be defined except in internal debug builds
#endif
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-
#include <stdlib.h>
#include <string.h>
#include <rxobject.h>
#include <rxregsvc.h>
#include <aced.h>
#include <dbsymtb.h>
#include <adslib.h>
#include <geassign.h>
#include <dbapserv.h>
#include "tchar.h"
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-
void dualoffset();
int GetERRNO();
void offset(AcDbObjectId eId , ads_real roffset);
//
Acad::ErrorStatus addToModelSpace(AcDbObjectId&, AcDbEntity*);
void initApp();
void unloadApp();
extern "C"
AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*);
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-
void dualoffset()
{
struct resbuf rb1; //"OFFSETDIST"
struct resbuf rb2; //"LUNITS"
struct resbuf rb3; //"LUPREC"
struct resbuf rb4; //"ERRNO"
struct resbuf rb5; //"OFFSETDIST"
//
ACHAR strValue; //Temp str for OFFSETDIST
ads_real roffset; //Temp str for acedGetReal
ads_name en; //ename
AcGePoint3d pt; //Point3d
AcDbObjectId eId; //ObjectId
AcDbObject *pObj; //pointer Object
//default offset distance
acedGetVar(_T("OFFSETDIST"), &rb1);
//units to be using in acdbRToS
acedGetVar(_T("LUNITS"), &rb2);
//precision to be using in acdbRToS
acedGetVar(_T("LUPREC"), &rb3);
//format the default offset distance
acdbRToS(rb1.resval.rreal, rb2.resval.rint , rb3.resval.rint, &strValue);
//
acutPrintf( _T("\nEnter offset distance <%s>: ") , &strValue );
//Gets a double to be used in offset distance
int retval = acedGetReal(NULL, &roffset);
switch(retval)
{
case RTNONE:
roffset = rb1.resval.rreal;
break;
case RTCAN:
return;
case RTERROR:
return;
}
rb4.restype = RTLONG;
rb4.resval.rlong = 0;
//Hmmm this is cool, is this in c#?
entget:
//Selects the entity
int rtval = acedEntSel(_T("\nSelect object to offset: "), en, asDblArray(pt));

if ((rtval == RTERROR) && (GetERRNO() != 52))
{
goto entget;
}
if (rtval == RTCAN)
{
acedSetVar(_T("ERRNO"), &rb4);
return;
}
if (rtval == RTERROR)
{
acedSetVar(_T("ERRNO"), &rb4);
return;
}
//Resets sysvar ERRNO
acedSetVar(_T("ERRNO"), &rb4);
//sets sysvar OFFSETDIST
rb5.restype = RTREAL;
rb5.resval.rreal = roffset;
acedSetVar(_T("OFFSETDIST"), &rb5);
//
acdbGetObjectId(eId, en);
acdbOpenObject(pObj, eId, AcDb::kForRead);
pObj->close();
offset(eId , (roffset / 2));
offset(eId , (-roffset / 2));
acdbEntDel(en);
}
//
int GetERRNO()
{
struct resbuf rb1;
acedGetVar(_T("ERRNO"), &rb1);
return rb1.resval.rint;
}
//the rest is borrowed from the curves Sample
void offset(AcDbObjectId eId , ads_real roffset)
{
AcDbCurve *pCurve;
acdbOpenObject(pCurve, eId, AcDb::kForRead);
AcDbVoidPtrArray curves;
pCurve->getOffsetCurves(roffset, curves);
pCurve->close();
AcDbObjectId newCurveId;
addToModelSpace(newCurveId, (AcDbEntity*)curves[0]);
}
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-
Acad::ErrorStatus
addToModelSpace(AcDbObjectId &objId, AcDbEntity* pEntity)
{
AcDbBlockTable *pBlockTable;
AcDbBlockTableRecord *pSpaceRecord;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);
pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord,
AcDb::kForWrite);
pBlockTable->close();
pSpaceRecord->appendAcDbEntity(objId, pEntity);
pEntity->close();
pSpaceRecord->close();
return Acad::eOk;
}
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-
void
initApp()
{
acedRegCmds->addCommand(_T("CRPD_DOFTEST"), _T("CRPD_dof"),
_T("dof"), ACRX_CMD_MODAL, dualoffset);
}
//
void
unloadApp()
{
acedRegCmds->removeGroup(_T("CRPD_DOFTEST"));
}
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-
// ARX entry point
//-==-==-==-==-=-==-=-=-==-=-=-==-==-==-==-=-=-==-==-=-=-
AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
switch (msg) {
case AcRx::kInitAppMsg:
acrxDynamicLinker->unlockApplication(appId);
acrxDynamicLinker->registerAppMDIAware(appId);
initApp();
break;
case AcRx::kUnloadAppMsg:
unloadApp();
}
return AcRx::kRetOK;
}
« Last Edit: November 04, 2006, 12:51:51 PM by Danielm103 »

LE

  • Guest
Re: My Fisrt Arx
« Reply #2 on: January 06, 2007, 12:35:46 PM »
Daniel;

Little late, but it still might help you... This is what I use:

Code: [Select]
static double defWallThickness = 6.0;
static void GenerateWalls(void)
{
Acad::ErrorStatus es;
ads_name sel;
resbuf *rbFilter = acutBuildList(RTDXF0, _T("LINE"), RTNONE);

acutPrintf(_T("\nSelect lines to generate walls: "));
if (acedSSGet(NULL, NULL, NULL, rbFilter, sel) != RTNORM)
{
acutRelRb(rbFilter);
return;
}

acutRelRb(rbFilter);

long lth = 0;

if (acedSSLength(sel, &lth) != RTNORM || lth == 0)
{
acedSSFree(sel);
return;
}

double ort = PI / 2.0, wallThickness;
int tst = 1, tst1 = 1;

CString prompt;
ACHAR resultStr[512];
acdbRToS(defWallThickness, -1, -1, resultStr);
prompt.Format(_T("\nWall thickness <%s>: "), resultStr);

int result;
acedInitGet(RSG_NOZERO+RSG_NONEG,_T(""));
result = acedGetDist(NULL, prompt, &wallThickness);
switch(result)
{
case RTNORM:
acdbRToS(wallThickness, -1, -1, resultStr);
acutPrintf(_T("\nWall thickness value returned is %s"), resultStr);
defWallThickness = wallThickness;
break;
case RTNONE:
wallThickness = defWallThickness;
acdbRToS(wallThickness, -1, -1, resultStr);
acutPrintf(_T("\nWall thickness value returned is %s"), resultStr);
break;
case RTCAN:
return;
break;
}

for (int cont = 0; cont < lth; cont++)
{

}
acedSSFree(sel);
}
« Last Edit: January 06, 2007, 12:39:09 PM by LE »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: My Fisrt Arx
« Reply #3 on: January 06, 2007, 09:49:29 PM »
Thank you for the great example Luis,
After looking at your code, mine seems to be a total kludge.   :?
« Last Edit: January 06, 2007, 10:00:19 PM by Danielm103 »