THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/03/2006 at 08:26, xxxxxxxx wrote:
Ok, I boiled it down to a simple test plugin to try a few things. Could someone tell me what I'm doing wrong? Here's the tester plugin:
//===============================================================
// Ngon Tester : MAIN MODULE
//===============================================================
#include "c4d.h"
// #include "c4d_symbols.h"
enum
{
_FIRST_ELEMENT_ = 10000,
// Global string definitions start here
IDS_NGON,
// Global string definitions end here
// End of symbol definition
_DUMMY_ELEMENT_
};
#define NGONTEST_PLUGID 1019532
class NgonPluginData : public CommandData
{
public:
virtual Bool Execute(BaseDocument *doc);
virtual LONG GetState(BaseDocument *doc);
};
//===============================================================
// try to create an Ngon from the currently selected polygons
// of the currently selected PolygonObject.
//===============================================================
Bool NgonPluginData::Execute(BaseDocument *doc)
{
if( !doc )
return false;
PolygonObject *pObj = ToPoly(doc->GetActiveObject());
if( !pObj )
return false;
if( pObj->GetType() != Opolygon )
return false;
BaseSelect *pBs = pObj->GetPolygonS();
if( !pBs )
return false;
LONG selCnt = pBs->GetCount();
if( selCnt < 2 )
return false;
Vector *pVerts = pObj->GetPoint();
CPolygon *pPolys = pObj->GetPolygon();
LONG numVerts = pObj->GetPointCount();;
LONG numPolys = pObj->GetPolygonCount();
LONG numNgons = pObj->GetNgonCount();
NgonBase *pNgonBase = pObj->GetNgonBase();
if( !pNgonBase )
return false;
pObj->ResizeObject(numVerts, numPolys, numNgons+1);
LONG *array = (LONG * )GeAlloc(selCnt * sizeof(LONG));
LONG i, j, a, b;
j = 0;
for (i=0;pBs->GetRange(i,&a,&b);i++)
{
for (;a<=b;a++)
{
array[j++] = a;
if( j == selCnt ) j--; // sanity check
}
}
LONG result = pNgonBase->BuildNgonFromPolys(array, NULL, selCnt, 0, pPolys, pVerts);
GePrint("result = "+LongToString(result));
pNgonBase->InitMap();
pObj->Message(MSG_UPDATE);
GeFree(array);
return true;
}
LONG NgonPluginData::GetState(BaseDocument *doc)
{
BaseObject *pbObj = doc->GetActiveObject();
if( pbObj && pbObj->GetType() == Opolygon )
return CMD_ENABLED;
else
return 0;
}
//===============================================================
// plugin stuff below
//===============================================================
Bool RegisterNgonTest(void)
{
String name=GeLoadString(IDS_NGON); if (!name.Content()) return TRUE;
return RegisterCommandPlugin(NGONTEST_PLUGID,name,0,"ngon.tif","",gNew NgonPluginData);
}
Bool PluginStart(void)
{
LONG c4dversion = GetC4DVersion();
if (!resource.Init()) return FALSE;
if ( c4dversion < 9000 ) return false;
if (!RegisterNgonTest()) return false;
GePrint(String("Ngon Tester v1.0 by Keith Young"));
return true;
}
void PluginEnd(void){}
Bool PluginMessage(LONG id, void *data){return false;}
//-------- END OF FILE - SNIP HERE -------------------------
...this plugin tries to combine the currently selected polygons into an Ngon - seems fairly straight forward, but does not work, so I assume that I'm just confused and/or missing some steps somewhere along the line.
Any help would be appreciated - thanks,
- Keith