Nevron Forum

Nudge/Align

https://www.nevron.com/Forum/Topic3880.aspx

By Ron Sawyer - Monday, July 26, 2010

I am performing a nudge or an align by iterating through the view's selected nodes and setting each shape's location.

Is there a better way to do this?

(example of nudge left)

if (nDrawingView1.Selection.NodesCount < 1)

      return;

 

NShape LclShape = nDrawingView1.Selection.Nodes[0] as NShape;

if (LclShape != null)

{

      foreach (INNode Tmp in nDrawingView1.Selection.Nodes)

      {

            LclShape = Tmp as NShape;

            if (LclShape == null)

                  continue;

 

            NPointF TargetPoint = new NPointF(LclShape.Location.X - 1, LclShape.Location.Y);

            if (TargetPoint.X < 0)

            {

                  TargetPoint = new NPointF(0, LclShape.Location.Y);

            }

 

            LclShape.Location = TargetPoint;

      }

}

By Nevron Support - Tuesday, July 27, 2010

Hi,

Your code works, but there’s an easier way to move the currently selected nodes in a direction of your choice:

 

if (view.Selection.NodesCount < 1)

      return;

 

float step = document.Settings.NudgeLeft / view.SceneScaleToDeviceX;

view.Selection.BatchTranslate.Translate(CompassDirection.West, step, false, false);

view.SmartRefresh();

 

 

This moves all currently selected shapes the distance specified by the NudgeLeft document setting. If you want to move the shapes exactly a fixed number of pixels you can use the following code:

 

if (view.Selection.NodesCount < 1)

      return;

 

view.Selection.BatchTranslate.Translate(-10, 0, false, false);

view.SmartRefresh();

 

By Ron Sawyer - Wednesday, August 11, 2010

Fantastic! Thank you.