Skip to main content

Hi All,

I am looking for a template to create a user-defined surface dll in c#.

Can someone provide me with this. I'm new to C# and UD surfaces.

Many Thanks!

Hans-Jürgen

 


oMod note: moved to the DLL subforum] 

Hi Hans-Jürgen,

Here is one example to change the surface type to User Defined and you can choose one of .DLL file in the surface property (e.g., us_anasp.dll here I used with index of 3).

Please let me know if you have any questions.

 

 // Add your custom code here...

            // creates a new API directory
            string strPath = System.IO.Path.Combine(TheApplication.SamplesDir, @"API\\CS4");
            System.IO.Directory.CreateDirectory(strPath);

            // Set up primary optical system
            string sampleDir = TheApplication.SamplesDir;
            string testFile = sampleDir + "\\API\\CS4\\e01_new_file_and_quickfocus.zos";

            // Make new file
            TheSystem.New(false);
            TheSystem.SaveAs(testFile);

            TheSystem.SystemData.MaterialCatalogs.AddCatalog("SCHOTT");

            // Aperture
            ISystemData TheSystemData = TheSystem.SystemData;
            TheSystemData.Aperture.ApertureValue = 40;

            // Fields
            IField Field_1 = TheSystemData.Fields.GetField(1);
            IField NewField_2 = TheSystemData.Fields.AddField(0, 5.0, 1.0);

            // Wavelength preset
            bool slPreset = TheSystemData.Wavelengths.SelectWavelengthPreset(WavelengthPreset.d_0p587);

            // Lens data 
            ILensDataEditor TheLDE = TheSystem.LDE;
            TheLDE.InsertNewSurfaceAt(2);
            TheLDE.InsertNewSurfaceAt(2);
            ILDERow Surface_1 = TheLDE.GetSurfaceAt(1);
            ILDERow Surface_2 = TheLDE.GetSurfaceAt(2);
            ILDERow Surface_3 = TheLDE.GetSurfaceAt(3);

            // Changes surface cells in LDE
            Surface_1.Thickness = 50.0;
            Surface_1.Comment = "Stop is free to move";
            Surface_2.Radius = 100.0;
            Surface_2.Thickness = 10.0;
            Surface_2.Comment = "front of lens";
            Surface_2.Material = "N-BK7";
            Surface_3.Comment = "rear of lens";

            // Changes surface type to User Defined
            ISurfaceTypeSettings SurfaceType_UD = TheLDE.GetSurfaceAt(2).GetSurfaceTypeSettings(SurfaceType.UserDefined);
            string>] aFiles =  SurfaceType_UD.GetFileNames();
            SurfaceType_UD.Filename = aFiles.GetValue(3).ToString();
            TheLDE.GetSurfaceAt(2).ChangeType(SurfaceType_UD);           

            // Solver
            ISolveData Solver = Surface_3.RadiusCell.CreateSolveType(SolveType.FNumber);
            Solver._S_FNumber.FNumber = 10;
            Surface_3.RadiusCell.SetSolveData(Solver);

            // QuickFocus
            IQuickFocus quickFocus = TheSystem.Tools.OpenQuickFocus();
            quickFocus.Criterion = QuickFocusCriterion.SpotSizeRadial;
            quickFocus.UseCentroid = true;
            quickFocus.RunAndWaitForCompletion();
            quickFocus.Close();

            // Save and close
            TheSystem.Save();
 

 


Hi Xianglei,

thanks but what I am looking for, to create/built an user-defined surface DLL written in c#

BR


Hi @Hans-Jürgen Feige,

Unfortunately User-defined DLL`s can only be applied within a C or C++ environment. It might be quite difficult to adapt some sort of a converter from a scripting language such as C#. However, I will dig a bit into that, as we would also internally welcome to have some new language preferences in that sense.

I`ll keep you posted here.

Let me know if you have any other questions,


Hi Hans-Jürgen,

Here is one example to change the surface type to User Defined and you can choose one of .DLL file in the surface property (e.g., us_anasp.dll here I used with index of 3).

Please let me know if you have any questions.

 

 // Add your custom code here...

            // creates a new API directory
            string strPath = System.IO.Path.Combine(TheApplication.SamplesDir, @"API\\CS4");
            System.IO.Directory.CreateDirectory(strPath);

            // Set up primary optical system
            string sampleDir = TheApplication.SamplesDir;
            string testFile = sampleDir + "\\API\\CS4\\e01_new_file_and_quickfocus.zos";

            // Make new file
            TheSystem.New(false);
            TheSystem.SaveAs(testFile);

            TheSystem.SystemData.MaterialCatalogs.AddCatalog("SCHOTT");

            // Aperture
            ISystemData TheSystemData = TheSystem.SystemData;
            TheSystemData.Aperture.ApertureValue = 40;

            // Fields
            IField Field_1 = TheSystemData.Fields.GetField(1);
            IField NewField_2 = TheSystemData.Fields.AddField(0, 5.0, 1.0);

            // Wavelength preset
            bool slPreset = TheSystemData.Wavelengths.SelectWavelengthPreset(WavelengthPreset.d_0p587);

            // Lens data 
            ILensDataEditor TheLDE = TheSystem.LDE;
            TheLDE.InsertNewSurfaceAt(2);
            TheLDE.InsertNewSurfaceAt(2);
            ILDERow Surface_1 = TheLDE.GetSurfaceAt(1);
            ILDERow Surface_2 = TheLDE.GetSurfaceAt(2);
            ILDERow Surface_3 = TheLDE.GetSurfaceAt(3);

            // Changes surface cells in LDE
            Surface_1.Thickness = 50.0;
            Surface_1.Comment = "Stop is free to move";
            Surface_2.Radius = 100.0;
            Surface_2.Thickness = 10.0;
            Surface_2.Comment = "front of lens";
            Surface_2.Material = "N-BK7";
            Surface_3.Comment = "rear of lens";

            // Changes surface type to User Defined
            ISurfaceTypeSettings SurfaceType_UD = TheLDE.GetSurfaceAt(2).GetSurfaceTypeSettings(SurfaceType.UserDefined);
            string ] aFiles =  SurfaceType_UD.GetFileNames();
            SurfaceType_UD.Filename = aFiles.GetValue(3).ToString();
            TheLDE.GetSurfaceAt(2).ChangeType(SurfaceType_UD);           

            // Solver
            ISolveData Solver = Surface_3.RadiusCell.CreateSolveType(SolveType.FNumber);
            Solver._S_FNumber.FNumber = 10;
            Surface_3.RadiusCell.SetSolveData(Solver);

            // QuickFocus
            IQuickFocus quickFocus = TheSystem.Tools.OpenQuickFocus();
            quickFocus.Criterion = QuickFocusCriterion.SpotSizeRadial;
            quickFocus.UseCentroid = true;
            quickFocus.RunAndWaitForCompletion();
            quickFocus.Close();

            // Save and close
            TheSystem.Save();
 

 

Hello 

 

https://www.onlinegdb.com/#

Hi Xianglei,

thanks but what I am looking for, to create/built an user-defined surface DLL written in c#

BR

Hello Hans-Jürgen Feige

You can try this out, and see if it works; https://www.onlinegdb.com/# you can change the programming language using the options located at upside right 

 

alternatively, chatGPT is somewhat a solution which might be unavailable due to high demand.

 

 


Reply