2 Replies Latest reply on Oct 22, 2013 10:44 AM by nathaniel.arbizu

    Error in API when creating user layer gfx?

    nathaniel.arbizu

      I have created a C# console project in Visual Studio 2012. I am trying to create a circle on a user layer, but I keep getting the following error on the highlighed line below:

           An unhandled exception of type 'System.ArgumentException' occurred in System.Dynamic.dll

           Additional information: Could not convert argument 1 for call to PutUserLayerGfx.

      I don't understand why it is trying to convert anything. All data types are correct and it compiles fine.

      I have attached the entire VS solution. This is on Expedition 7.9.4, Windows 7 Enterprise 64bit. The solution is set to AnyCPU.

       

      using System;

      using System.Collections.Generic;

      using System.Linq;

      using System.Text;

      using System.Threading.Tasks;

       

      namespace PutUserLayerGfxTest

      {

          class Program

          {

              static void Main(string[] args)

              {

                  MGCPCB.Application pcbApp = (MGCPCB.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("MGCPCB.Application");

                  MGCPCB.Document pcbDoc = pcbApp.ActiveDocument;

                  pcbDoc.Validate(new MGCPCBAutomationLicensing.Application().GetToken(pcbDoc.Validate(0)));

                  MGCPCB.UserLayer myLayer = null;

                  myLayer = pcbDoc.FindUserLayer("MYLAYER");

                  if (myLayer == null)

                      myLayer = pcbDoc.SetupParameter.PutUserLayer("MYLAYER");

                  dynamic pa = pcbApp.Utility.CreateCircleXYR(0.0, 0.0, 200.0);

                  MGCPCB.UserLayerGfx gfx = pcbDoc.PutUserLayerGfx(myLayer, 0.0, 3, pa, false, null, MGCPCB.EPcbUnit.epcbUnitCurrent);

                  if (gfx != null)

                      System.Console.Write(gfx.LayerName);

              }

          }

      }