I edited the elipsjig example shipped with objectarx I added calls to acedDefun and acedRegFunc to define a lisp function called (VELLIPSE). It does the same as the command. If you're calling the lisp function, using wireframe 2d andzoom out too much during the drag sequenece other entities disapear.
#if defined(_DEBUG) && !defined(AC_FULL_DEBUG)
#error _DEBUG should not be defined
#endif
#include <Windows.h>
#include <adslib.h>
#include <dbjig.h>
#include <dbelipse.h>
#include <aced.h>
#include <geassign.h>
#include <dbapserv.h>
#include "tchar.h"
class AsdkEllipseJig : public AcEdJig
{
public:
AsdkEllipseJig(const AcGePoint3d&, const AcGeVector3d&);
void doIt();
virtual DragStatus sampler();
virtual Adesk::Boolean update();
virtual AcDbEntity* entity() const;
private:
AcDbEllipse *mpEllipse;
AcGePoint3d mCenterPt, mAxisPt;
AcGeVector3d mMajorAxis, mNormal;
double mRadiusRatio;
int mPromptCounter;
};
AsdkEllipseJig::AsdkEllipseJig(
const AcGePoint3d& pt,
const AcGeVector3d& normal)
: mCenterPt(pt),
mNormal(normal),
mRadiusRatio(0.00001),
mPromptCounter(0)
{
resbuf rb;
memset (&rb, 0, sizeof (resbuf));
acedGetVar (_T("VIEWSIZE"), &rb);
double majorAxisInitialOffset = rb.resval.rreal/1000.0;
mMajorAxis = AcGeVector3d(majorAxisInitialOffset,0,0); // Offset the major axis a bit from the center point.
}
void AsdkEllipseJig::doIt()
{
mpEllipse = new AcDbEllipse();
mpEllipse->set(mCenterPt, mNormal, mMajorAxis, mRadiusRatio); // Set default parameters for the ellipse.
setDispPrompt(_T("\nEllipse major axis: "));
AcEdJig::DragStatus stat = drag();
mPromptCounter++; // now == 1
setDispPrompt(_T("\nEllipse minor axis: "));
stat = drag();
append();
}
AcEdJig::DragStatus AsdkEllipseJig::sampler()
{
DragStatus stat;
setUserInputControls((UserInputControls)(AcEdJig::kAccept3dCoordinates | AcEdJig::kNoNegativeResponseAccepted | AcEdJig::kNoZeroResponseAccepted));
if (mPromptCounter == 0)
{
static AcGePoint3d axisPointTemp;
stat = acquirePoint(mAxisPt, mCenterPt);
if (axisPointTemp != mAxisPt)
axisPointTemp = mAxisPt;
else if (stat == AcEdJig::kNormal)
return AcEdJig::kNoChange;
}
else if (mPromptCounter == 1)
{
static double radiusRatioTemp = -1;
stat = acquireDist(mRadiusRatio, mCenterPt);
if (radiusRatioTemp != mRadiusRatio)
radiusRatioTemp = mRadiusRatio;
else if (stat == AcEdJig::kNormal)
return AcEdJig::kNoChange;
}
return stat;
}
Adesk::Boolean AsdkEllipseJig::update()
{
switch (mPromptCounter)
{
case 0:
mMajorAxis = mAxisPt - mCenterPt;
break;
case 1:
mRadiusRatio = mRadiusRatio / mMajorAxis.length();
break;
}
mpEllipse->set(mCenterPt, mNormal, mMajorAxis,
mRadiusRatio);
return Adesk::kTrue;
}
AcDbEntity* AsdkEllipseJig::entity() const
{
return mpEllipse;
}
void createEllipse()
{
AcGePoint3d tempPt;
struct resbuf rbFrom, rbTo;
acedGetPoint(NULL, _T("\nEllipse center point: "), asDblArray(tempPt));
rbFrom.restype = RTSHORT;
rbFrom.resval.rint = 1; // from UCS
rbTo.restype = RTSHORT;
rbTo.resval.rint = 0; // to WCS
acedTrans(asDblArray(tempPt), &rbFrom, &rbTo,
Adesk::kFalse, asDblArray(tempPt));
AcGeVector3d x = acdbHostApplicationServices()->workingDatabase()->ucsxdir();
AcGeVector3d y = acdbHostApplicationServices()->workingDatabase()->ucsydir();
AcGeVector3d normalVec = x.crossProduct(y);
normalVec.normalize();
AsdkEllipseJig *pJig = new AsdkEllipseJig(tempPt, normalVec);
pJig->doIt();
delete pJig;
}
int createElipseWithLisp()
{
createEllipse();
return RTNORM;
}
void initApp()
{
acedRegCmds->addCommand(_T("ASDK_VISUAL_ELLIPSE"), _T("ASDK_VELLIPSE"), _T("VELLIPSE"), ACRX_CMD_MODAL, createEllipse);
acedDefun(_T("VELLIPSE"), 999);
acedRegFunc(createElipseWithLisp, 999);
}
void unloadApp()
{
acedRegCmds->removeGroup(_T("ASDK_VISUAL_ELLIPSE"));
}
extern "C" 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;
}