2 Replies Latest reply on Oct 6, 2016 2:16 PM by john.fonseca@ni.com

    Grow/Shrink Rectangle


      Trying to write a method that will grow/shrink an object, however there is nothing in the shapes collection.  I have added the correct pSafeArrayOfPoints and I can see the array populate, Im not sure why shapes is empty.  Here is my code in C#.  Curious if anyone has done something similar or could help point me where I may be doing something wrong.


      public Array GrowShrink(Array newPntArray, string growShrinkValue)


                  Array pointsArray = null;          

                  double resizeAmt = double.Parse(growShrinkValue);

                  int length = newPntArray.GetLength(1);



                  var maskEngine = Com.Dispatch<MaskEngine>("MGCPCBEngines.MaskEngine");                                  

                  Mask mask = maskEngine.Masks.Add();                       

                  object pSafeArrayOfPoints = (object) newPntArray;

                  mask.Shapes.AddByPointsArray(length, ref pSafeArrayOfPoints);          

                  mask.Oversize(resizeAmt, EMaskEngineOversizeType.emeOversizeTypeSquare);

                  Shapes shapes = mask.Shapes;                                



                      foreach (Shape item in shapes)


                          pointsArray = item.PointsArray;



                return pointsArray;


        • 1. Re: Grow/Shrink Rectangle

          I always include the optional arguments when adding the shape by pointsarray:


          shps.AddByPointsArray(pts, ptary, True, 0)


          It doesn't seem like that should matter, but I've had success using it like that.


          I also specify the oversize values with integers, as in:


          mskout.Oversize(1, 0)


          In your case it would be


          mskout.Oversize(1, 1)


          for square oversize type.


          Other things:


          - Do you have a reference to the MASKENGINEAUTOMATIONCONTROLLERLib?  If not, you need to add one to your project references.

          - I declare the mask engine like this (vb):

          Public mskeng As MASKENGINEAUTOMATIONCONTROLLERLib.MaskEngine

          but I see you are declaring it as type var. Not sure if it matters but worth a try to set it to the right data type.


          I have used methods like this many times and had good luck with them.  Once you get it right the mask engine is reliable and very powerful.

          • 2. Re: Grow/Shrink Rectangle

            Patrick thanks very much for the response.  Adding the optional arguments for pointsarray is what fixed it for me.  Its strange because the arguments added are the default values.  I will keep this in mind going forward.  Thanks again!