Skip to main content
Solved

ZPL Question with SPRO


Brian

I’m converting ZPL macros to ZOS API using C#

I’ve having a hard time finding the corresponding API for the macro SPRO(surf, code) with Code = 18

From the macro documentation, code 18 will return the Glass Number (an integer?) for a Surface.

Does anyone know the corresponding   ZOS API code?

 

I currently use OpticalSystem.LDE.GetGlass() to get the glass name. How about accessing the glass number?

 

Best answer by MichaelH

Hi Brian,

There is no “glass number” in the API.  In the ZPL, this is simply the order of the glass as they appear in the AGF/BGF glass catalog.  If you have multiple catalogs loaded, then the 2nd catalog starts as the n+1 glass number.  C# code to achieve this would be as follows (note that since this isn’t a built-in function and not documented in the Help Files, this is subject to change without warning):

private static int GlassNumber(IOpticalSystem opticalSystem, int surf)
        {
            int result = -1;
            int gnum = 0;

            var tool = opticalSystem.Tools.OpenMaterialsCatalog();
            string[] catalogs = opticalSystem.SystemData.MaterialCatalogs.GetCatalogsInUse();
            for (int i = 0; i < catalogs.Length; i++)
            {
                tool.SelectedCatalog = catalogs[i];
                string[] glasses = tool.GetAllMaterials();

                for (int j = 0; j < glasses.Length; j++)
                {
                    gnum++;
                    if (glasses[j].ToUpper() == opticalSystem.LDE.GetSurfaceAt(surf).Material.ToUpper())
                    {
                        tool.Close();
                        return gnum;
                    }

                }
            }

            tool.Close();
            return result;
        }

 

View original
Did this topic help you find an answer to your question?

2 replies

MichaelH
Ansys Staff
Forum|alt.badge.img+2
  • Ansys Staff
  • 358 replies
  • Answer
  • August 10, 2022

Hi Brian,

There is no “glass number” in the API.  In the ZPL, this is simply the order of the glass as they appear in the AGF/BGF glass catalog.  If you have multiple catalogs loaded, then the 2nd catalog starts as the n+1 glass number.  C# code to achieve this would be as follows (note that since this isn’t a built-in function and not documented in the Help Files, this is subject to change without warning):

private static int GlassNumber(IOpticalSystem opticalSystem, int surf)
        {
            int result = -1;
            int gnum = 0;

            var tool = opticalSystem.Tools.OpenMaterialsCatalog();
            string[] catalogs = opticalSystem.SystemData.MaterialCatalogs.GetCatalogsInUse();
            for (int i = 0; i < catalogs.Length; i++)
            {
                tool.SelectedCatalog = catalogs[i];
                string[] glasses = tool.GetAllMaterials();

                for (int j = 0; j < glasses.Length; j++)
                {
                    gnum++;
                    if (glasses[j].ToUpper() == opticalSystem.LDE.GetSurfaceAt(surf).Material.ToUpper())
                    {
                        tool.Close();
                        return gnum;
                    }

                }
            }

            tool.Close();
            return result;
        }

 


Brian
  • Author
  • Monochrome
  • 4 replies
  • August 10, 2022

Hi Michael,

Thanks for the quick reply.

I was thinking that it was associated with the catalogs but I didn’t think of going into the Tools part of the
code.  I’m giving this a try now.

Thanks again.
B.
 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings