Nevron Forum

Copy/Paste FailedRolledback

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

By Ron Sawyer - Monday, July 19, 2010

I have created a simple custom shape. When I try to copy and paste it I get the following:

The Paste transaction FailedRolledback
Error Log:
1. Paste failed on a single node: Object reference not set to an instance of an object.

The following shape is a very simplistic-cut-down class to show what I am trying to do:

 

class TestClass : NGroup, ICloneable

{ 

      public TestClass()

      {

            // add a rectangle shape as base

            NRectangleShape rect = new NRectangleShape(new NRectangleF(0, 0, 100, 300));

            rect.DestroyShapeElements(ShapeElementsMask.All);

            rect.Protection = new NAbilities(AbilitiesMask.Select | AbilitiesMask.InplaceEdit | AbilitiesMask.Copy);

            Shapes.AddChild(rect); 

 

            // update the model bounds with the rectangle bounds        UpdateModelBounds(rect.Transform.TransformBounds(rect.ModelBounds));

 

            CreateShapeElements(ShapeElementsMask.Labels);

            NRotatedBoundsLabel label = new NRotatedBoundsLabel("", rect.UniqueId, new Nevron.Diagram.NMargins(10));

 

            Labels.AddChild(label);

            Labels.DefaultLabelUniqueId = label.UniqueId; 

      } 

 

      public TestClass(TestClass PassedClass)

      {

            NRectangleShape LclRect = PassedClass.Shapes.GetChildAt(0) as NRectangleShape;

            if (LclRect != null)

            {

                  NRectangleShape TmpRect = LclRect.Clone() as NRectangleShape;

 

                  Shapes.AddChild(TmpRect);

                  UpdateModelBounds(TmpRect.Transform.TransformBounds(LclRect.ModelBounds));

                  NRotatedBoundsLabel label = new NRotatedBoundsLabel("", TmpRect.UniqueId, new Nevron.Diagram.NMargins(10));

                  CreateShapeElements(ShapeElementsMask.Labels);

                  Labels.AddChild(label);

                  Labels.DefaultLabelUniqueId = label.UniqueId;

            }

      }

 

      object ICloneable.Clone()

      {

            return new TestClass(this);

      }

}

 

By Nevron Support - Monday, July 19, 2010

Hi,

In order to make your custom class copy/pasteable in the diagram all you have to do is to apply the Serializable attribute to it. Your class should look as this:

 

[Serializable]

class TestClass : NGroup

{

      public TestClass()

      {

            // add a rectangle shape as base

            NRectangleShape rect = new NRectangleShape(new NRectangleF(0, 0, 100, 300));

            rect.DestroyShapeElements(ShapeElementsMask.All);

            rect.Protection = new NAbilities(AbilitiesMask.Select | AbilitiesMask.InplaceEdit | AbilitiesMask.Copy);

            Shapes.AddChild(rect);

 

            // update the model bounds with the rectangle bounds

            UpdateModelBounds(rect.Transform.TransformBounds(rect.ModelBounds));

 

            CreateShapeElements(ShapeElementsMask.Labels);

            NRotatedBoundsLabel label = new NRotatedBoundsLabel("", rect.UniqueId, new Nevron.Diagram.NMargins(10));

 

            Labels.AddChild(label);

            Labels.DefaultLabelUniqueId = label.UniqueId;

      }

}

 

By Ron Sawyer - Monday, July 19, 2010

Thanks for the reply. I misunderstood this post:

http://forum.nevron.com/shwmessage.aspx?forumid=3&messageid=2593#bm2603

Your help worked and is much appreciated.
By Steve Warner - Tuesday, January 4, 2011

I'm having this same issue, but using a NTextShape with a Serializable object as a tag. Any ideas what is causing the Paste failure?