General Mechanical

General Mechanical

Topics relate to Mechanical Enterprise, Motion, Additive Print and more

Run macro with PyAnsys

    • Koen Franse
      Subscriber

      Hi all,

      I'm trying to get a macro that is normally used in Ansys Mechan

      ical, working in PyAnsys scripting. Normally, the macro is called in a 'Commands (APDL)' section under the Solution tree of my Modal analysis:

      Containing the following lines:

          finish
          /psearch, C:
          moma

      in which moma.mac is the macro. Now I want to be able to run the macro seperately, after the Modal analysis has finished, in PyAnsys scripting. Therefore I set 'Save MPADL db' to Yes in Mechanical.

      In PyAnsys, I set the path to the simulation folder containing the .db file:

          mapdl=launch_mapdl(run_location=path)

      And read the .db file:

          mapdl.run("cdread,db,file.db")

      I run the psearch command and execute the macro in the same way as in Workbench:

          mapdl.run("/psearch,C:")
          mapdl.run("moma")

      This gives me the output "USE COMMAND MACRO moma", but I'm not sure if the macro is actually ran, since the output file I expect is not created in the folder as it is when I run the macro in Mechanical. Is there something I am still doing wrong?

      Thanks in advance!

       

    • Erik Kostson
      Ansys Employee

       

       

      Hi

      I would suggest to post this in the pyAnsys/pyMAPDL forum – also is your macro post processing results, then we need to read in the rst file.

      See: FILE (ansys.com)

      All the best

      Erik

       

       

      • Koen Franse
        Subscriber

        Hey Erik,

        Thanks, I'll post it in the pyMAPDL forum on git!

    • Erik Kostson
      Ansys Employee

       

      Hi

      So if you are post processing which I think you are, then:

      Issue file so (if you are in the same directory as the file.rst results, otherwise give the file path - see file command in help manual for more info):

      mapdl.run(“file,,rst”)

      All the best

      Erik

       

Viewing 2 reply threads
  • The topic ‘Run macro with PyAnsys’ is closed to new replies.