GithubHelp home page GithubHelp logo

Comments (6)

fizxmike avatar fizxmike commented on June 30, 2024

I apologize for the inconvenience. The solution is to create a DLL with a C# static method wrapping GetEditableParameters to return the editable parameters type explicitly. Then import the DLL with pyesapi.clr (which is interface to pythonnet). I have an example somewhere, I'll try to find it and paste it here.

from pyesapi.

chrisrose100 avatar chrisrose100 commented on June 30, 2024

If you could find an example that would be brilliant. thanks.

from pyesapi.

fizxmike avatar fizxmike commented on June 30, 2024

DLL code

namespace ProtonHelperNS
{
  public static class ProtonHelper
  {
    public static IonBeamParameters GetEditableIonBeamParameters(IonBeam iBeam)
    {
            return (iBeam.GetEditableParameters() as IonBeamParameters); // soo casted
    }
  }
}

from pyesapi.

fizxmike avatar fizxmike commented on June 30, 2024

PyESAPI code

# ...

# path to compiled proton helper DLL:
sys.path.append(r'C:\\Users\\Varian\\Documents\\Eclipse Scripting API\\Projects\\ProtonHelper\\bin\\debug')
pyesapi.clr.AddReference('ProtonHelper')
from ProtonHelperNS import ProtonHelper

#...

editable_params = ProtonHelper.GetEditableIonBeamParameters(beam)

from pyesapi.

fizxmike avatar fizxmike commented on June 30, 2024

Note, I ran into an issue with .NET Framework 4.6.1 (target for next release of Eclipse). The namespace should be different than the DLL name, otherwise, import will fail (name collision perhaps). See here: https://github.com/pythonnet/pythonnet/wiki/How-to-call-a-dynamic-library

I've edited examples above.

from pyesapi.

fizxmike avatar fizxmike commented on June 30, 2024

The elegant solution was found using reflection (in C# reflection can do literally anything). The issue was the function was overloaded due to IonBeam basing off of Beam class and pythonnet called the base method (there is a bigger issue here related to how methods are differentiated by their input parameter types only in pythonnet, so when there are no input parameters, there is ambiguity... I personally think the output type should also be used to differentiate the method). Technically, the "override" modifier should have been set on the GetEditableIonBeamParameters method in IonBeam class (ESAPI source). Anyway, here is the fix, I'll roll this into PyESAPI proper sooner or later:

import pyesapi
import atexit
def get_editable_IonBeamParameters(beam):
    for mi in beam.GetType().GetMethods():
        if mi.ReturnType.ToString() == 'VMS.TPS.Common.Model.API.IonBeamParameters':
            return mi.Invoke(beam,[])
pyesapi.IonBeam.GetEditableIonBeamParameters = get_editable_IonBeamParameters  # monkey patch like a boss
if not 'app' in locals():
    app = pyesapi.CustomScriptExecutable.CreateApplication('python_demo')
    atexit.register(app.Dispose);

from pyesapi.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.