This event is generated when a command from the object's dynamic menu is selected.
Syntax: |
---|
function OnDynamicRunMenu(obj, cmd) |
Parameters
Parameter | Description |
---|---|
obj | An object of a class derived from DlxObject. |
cmd | Index of the command as defined in the OnDynamicGetMenu function. |
Remarks
The purpose of this function is to execute the action corresponding to the selected command.
Example
For the complete code see "dynamic star.clxjob" in the sample files.
Copy code | |
---|---|
function OnDynamicRunMenu(obj, cmd)
{
if (obj.GetType() != DlxApp.OBJTYPE_SHAPE)
return;
// load parameters
var rays = obj.GetParamNumber("dyndata/shape", 1, 8);
var height = obj.GetParamNumber("dyndata/shape", 2, 5);
var radius = obj.GetParamNumber("dyndata/shape", 3, 30);
var rotation = obj.GetParamNumber("dyndata/shape", 4, 0);
var width = obj.GetParamNumber("dyndata/shape", 5, 180/36);
switch (cmd)
{
case 0 : // Star 5
rays = 5;
break;
case 1 : // Star 6
rays = 6;
break;
case 2 : // Star 12
rays = 12;
break;
case 3:
{
var dlg = new DlxDialog(300, 150, "Star Shape");
if (dlg.IsValid())
{
dlg.AddStaticText(20, 33, 60, "Rays:");
var ctrl = dlg.AddComboBox(90, 30, 180);
for (var i = 3; i <= 36; i++)
ctrl.AddString(i.toString() + " rays", i, i==5);
dlg.AddOkButton(180, 120, 50, 25);
dlg.AddCancelButton(240, 120, 50, 25);
if (!dlg.DoModal())
return;
rays = ctrl.GetNumber();
}
}; break;
default :
return;
}
// limit values
rays = Math.limit(rays, 3, 36);
radius = Math.limit(radius, 1, 100);
height = Math.limit(height, -radius, 10 * radius);
width = Math.limit(width, 1, 360 / rays);
// save parameters
obj.SetParam("dyndata/shape", 1, rays);
obj.SetParam("dyndata/shape", 2, height);
obj.SetParam("dyndata/shape", 3, radius);
obj.SetParam("dyndata/shape", 4, rotation);
obj.SetParam("dyndata/shape", 5, width);
var hs = obj.GetBoundingBox().CenterPoint();
DrawShape(obj, hs, rays, height, radius, rotation, width);
}
|