70002077 Override the grip points actions

Article 70002077
Type HowTo
Product Engine
Version 8
Date Added 10/8/2021 12:00:00 AM
Fixed 9.9003.0.1 (10/8/2021 12:00:00 AM)
Submitted by Simone Vitale


How can I override the default grip points move action, like in a circle.


Here is an example that demonstrates how to cancel a default grip action for a specific object type and specific grip
With this example if a user pick the grip of the center of a vdCircle then a new action is started that changes the vdCircle radius instead of the default grip action that moves the circle

You need to override the vdDocument ActionAdded event

 //doc is the active vdDocument object
doc.ActionAdded += Doc_ActionAdded;
And use a code like this in th event defined above:
private void Doc_ActionAdded(BaseAction action)
            //check a default move grip points action is started
            VectorDraw.Professional.ActionUtilities.CmdMoveGripPoints gripaction = action 
                                as VectorDraw.Professional.ActionUtilities.CmdMoveGripPoints;
            if (gripaction != null)
                //get the point that user pick over an existing grip on the screen in world coordinate system
                gPoint pt_world = gripaction.ReferencePoint;
                vdLayout layout = gripaction.Layout;
                //get the active grips selection
                vdSelection gripselection = doc.GetGripSelection();
                if (gripselection.Count > 0)
                    // iterate throw the grip selection until find a circle with 
                    // centerpoint grip throws the action reference point
                    foreach (vdFigure item in gripselection)
                        vdCircle circle = gripselection[0] as vdCircle;
                        if (circle != null)
                            gPoint pt_view = doc.World2ViewMatrix.Transform(pt_world);
                            Box gripbox = new Box();
                            gripbox.AddWidth(action.Render.GlobalProperties.GripSizeScaled * action.Render.PixelSize / 2.0d);
                            Int32Array gripIndexes = layout.getGripIndexes(circle, gripbox);
                            //user pick the circle grip on the center
                            if (gripIndexes.Count == 1 && gripIndexes[0] == 0)//controlled by  override gPoints 
                                     // GetGripPoints() of each vdfigure object type (vdCircle grippoints have 
                                     // the center point at the start of the grips collection)
                                //cancel the default action that moves the circle
                                //and begin a new action that will change the circle Radius instead
                                //begin a new user action reference the selected grip point
                                gPoints grippoints = circle.GetGripPoints();
                                pt_world = grippoints[0];
                                gPoint pt_usercs = doc.World2UserMatrix.Transform(pt_world);
                                doc.Prompt("select object radius");
                                gPoint newpt_usercs = doc.ActionUtility.getUserRefPoint(pt_usercs) as gPoint;
                                if (newpt_usercs != null)
                                    double radius = newpt_usercs.Distance3D(pt_usercs);
                                    circle.Radius = radius;

Send comments on this topic.