Mecway API functions

hello

currently it is not possible to call external programs using the API functions, isn't it.
Is there a way I can create the program in Fortran, and then call that exe from Iron Python? Are there any plans to include such functions?

Regards

Comments

  • hello

    currently it is not possible to call external programs using the API functions, isn't it.
    Is there a way I can create the program in Fortran, and then call that exe from Iron Python? Are there any plans to include such functions?

    Saving files and loading files would also be nice...

    Regards
  • There are a few ways. Here's one that starts an external process and waits for it to exit before continuing with the script:
    
    import subprocess
    subprocess.call("notepad.exe")
    
  • @Hengre, there is a post with a few API that have been shared.
    https://mecway.com/forum/discussion/comment/5109
    I'm particularly interested in leveraging this functionality, if you work out how to call your Fortran, please consider sharing! That would be very handy here.
  • Hello Victor
    thank you very much for your information. I tried the following:
    test.exe is a small program like "Hello world" compiled with both Freebasic and Fortran, it also applies to a more complex Fortran program with graphics output. So it should not depend on the compiler used.

    While testing the following lines I made the following observations

    import subprocess
    subprocess.call("notepad.exe") Works!

    import subprocess
    subprocess.call("test.exe") works only if test.exe is in the folder Mecway14

    import subprocess
    subprocess.call("C:\temp\test.exe") does not work if it is located elsewhere and the path is specified. Resulting in error message:
    "Error from Microsoft.Dynamic
    System.ComponentModel.Win32Exception
    Windows.Error"



    On the other hand, the following works even if a path is specified

    import subprocess
    subprocess.call("D:\gmsh-4.8.4-Windows64\gmsh.exe")

    I am wondering about what's the difference?

    My intention is to generate an *.inp file in a project folder with Mecway. Then run a specific Fortran program (the EXE should be located in a dedicated folder) that writes a *.frd that can be read again with Mecway to show the result.

    That would make it neccessary not only to run the program, but also to pass the name of the input file including path. Would that be possible with ironphyton?



    Regards

  • @JohnM
    you are right. If a solution for running external programs becomes more clear I can post the final way in that API post.
  • @Hengre, "\" indicates a special character in Python. For an actual backslash use two:

    subprocess.call("C:\\temp\\test.exe")

    I guess the Gmsh one works because \g isn't anything while \t is tab.

    I prefer forward slash for paths. It works in Windows just about everywhere and you don't usually need to escape it.
  • Hello Victor,
    thanks for your reply.
    Yes, it seems to ne the "\" problem,
    subprocess.call("C:\\temp\\test.exe") works well
    subprocess.call("C:/temp/test.exe") works well, too

    Can you suggest a good reference about ironphyton to?
  • edited February 2022
    Boom! Double slash did it for me.

  • #Hengre, I just look up things for Python 2 and they usually work in IronPython 2.7. The manual for IronPython is just a link to the manual for Python ;) https://ironpython.net/documentation/
  • edited August 2022
    Playing with scripting lately.

    Is there a way to suspend the execution of a Mecway script mid-way, so that user can mouse-select nodes/faces/elements when prompted?
  • @cwharpe, no, sorry. I looked into that and couldn't work out anything.

    You can make use of the order of selection to identify individual nodes/faces/elements, or put them in named selections.
  • edited August 2022
    @Victor: Yes, that can work. Creates possibilities for some other scripts in mind.
    Thanks.

    # Cloud of nodes stored previously in Named Range
    # Hub is only active node in screen selection set. Might be part of Cloud.
    # Re-assign selection
    hub = mw.selected_nodes()
    mw.remove_from_named_selection("Cloud",hub[0])
    fog = mw.named_selection("Cloud")
    nn = len(fog)
    .
    .
    .
    # Restore node count to Cloud range
    mw.add_to_named_selection("Cloud",hub[0])

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!