As I understand it, acedGetCorner() will only ever draw the rectangle in the XY coordinate system of the drawing as currently displayed. So if you rotate the UCS in the Z axis by 45 degrees, it makes no difference; the rectangle still draws up and to the right.
If you select the RECTANGLE command, however, the dragging rectangle draws as per the UCS, as expected.
Is there a way to achieve this with acedGetCorner()?
I have seen mention of acedGrDraw() to draw our own lines, which is all very well, but it gives zero information on how to make these calls during a user input operation - if that is even possible. I am perfectly willing to use acedGetPoint() and manually draw the rectangle if it is possible.
How does RECTANGLE do it? Is there a more modern way to get a rectangle from the user then acedGetCorner()? Is there a way to specify a callback function where we can manually draw lines using acedGrDraw() during acedGetCorner()? Can I influence the DCS to get it to match the UCS somehow - if that makes sense?
Expecting the user to work with it as it stands or to rotate the UCS to suit the graphics engine is bad karma - they shouldn't have to.
Solved! Go to Solution.
Solved by owenwengerd. Go to Solution.
What you describe is called a jig. See the AcEdJig class for more information.
Good point! I had forgotten about jigs. We have already used them for other areas of our software so I will look into creating one for this. I'm just a little grumpy that there isn't a built-in way of doing this - seems a bit of an oversight! 🙂
Thank you.
jig is prefered, but if you want exactly repeate RECTANGLE command, you can just use native command in your code 🙂
for example ( for acad 2010-2015):
struct resbuf rb; acedGetVar(_T("CMDNAMES"), &rb); CString cmd_ok( rb.resval.rstring ); AcDbObjectId rectId = NULL; ads_name entcont_before, _entcont; acdbEntLast(entcont_before); int resRect = RTFAIL; #if defined(_MSC_VER) && (_MSC_VER == 1500) // acad2010-2012 resRect = acedCommand( RTSTR,_T("_rectang"),RTSTR,PAUSE,RTNONE); #elif defined(_MSC_VER) && (_MSC_VER > 1500) // acad2013-2015 resRect = acedCommandS(RTSTR,_T("_rectang"),RTSTR,PAUSE,RTNONE); #endif if ( resRect == RTNORM ) { while( true ) { acedGetVar(_T("CMDNAMES"), &rb); CString cmd_now( rb.resval.rstring ); if ( cmd_ok != cmd_now ) { #if defined(_MSC_VER) && (_MSC_VER == 1500) // acad2010-2012 acedCommand(RTSTR, PAUSE, 0); #elif defined(_MSC_VER) && (_MSC_VER > 1500) // acad2013-2015 acedCommandS(RTSTR, PAUSE, 0); #endif } else break; } if (acdbEntLast(_entcont) == RTNORM) { if (_entcont[0]==entcont_before[0] && _entcont[1]==entcont_before[1]) { acutPrintf(_T("\nCommand canceled")); return; } } } else { acutPrintf(_T("\nCommand canceled")); return; } acdbGetObjectId(rectId,_entcont); if (rectId == NULL) return; // here you can do what you want with created rectangle (rectId) //... // for example, let's change color AcDbObject *myobj = NULL; if ( acdbOpenObject( myobj, rectId, AcDb::kForWrite ) == Acad::eOk ) { AcDbCurve *pCurve = AcDbCurve::cast( myobj ); if ( pCurve ) { pCurve->setColorIndex(1); pCurve->downgradeOpen(); } myobj->close(); } else { acutPrintf(_T("\nObject is blocked by Autocad")); return; } return;