THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 30/08/2011 at 09:42, xxxxxxxx wrote:
The state of the menu entry is controled via the MenuPlugin::GetState method. Override it for your own plugins. The other points are explained in my example.
class MPPlugin : MenuPlugin
{
public:
MPPlugin();
GetID();
GetName();
GetState();
GetHelp();
Execute(doc);
}
MPPlugin::MPPlugin()
{
super();
}
MPPlugin::GetID()
{
return 1001150;
}
MPPlugin::GetState()
{
var doc = GetActiveDocument();
if (!doc) return 0;
// is polygon mode checked
if (!IsCommandChecked(12187)) return 0;
// is there an selected object and is it a polygon object
var op = doc->GetActiveObject();
if (!op || op->GetType() != Opolygon) return 0;
// is at least one polyogn selected
var sel = op->GetPolygonSelection();
if (sel->GetCount() == 0) return 0;
return CMD_ENABLED;
}
MPPlugin::GetName()
{
return "Scale Test";
}
MPPlugin::GetHelp()
{
return "Scale Test";
}
MPPlugin::Execute(doc)
{
var op = doc->GetActiveObject();
if (!op || op->GetType() != Opolygon) return 0;
var sel = op->GetPolygonSelection();
if (sel->GetCount() == 0) return;
var fcnt = op->GetPolygonCount();
var vcnt = op->GetPointCount();
// create a vertex index array to store selection states for vertices of selected polygons
var vidx = new(array,vcnt);
if (!vidx) return;
var i = 0;
// initialize the array
for (i=0; i<vcnt; i++)
{
vidx[i] = FALSE;
}
// converts polygon selection into point selection
for (i=0; i<fcnt; i++)
{
if (sel->IsSelected(i))
{
var poly = op->GetPolygon(i);
vidx[poly->a] = TRUE;
vidx[poly->b] = TRUE;
vidx[poly->c] = TRUE;
vidx[poly->d] = TRUE; }
}
// go through the vertices and do something (e.g scale)
for (i=0; i<vcnt; i++)
{
if (vidx[i])
{
var vertex = op->GetPoint(i);
// do something with vertex
vertex.x *= 5.0;
//vertex.y *= 2.0;
//vertex.z *= 3.0;
op->SetPoint(i, vertex);
}
}
// must be called for object and editor update
op->Message(MSG_UPDATE);
EventAdd();
}
main()
{
Register(MPPlugin);
}
cheers,
Matthias