


{"id":311826,"date":"2023-10-17T14:05:38","date_gmt":"2023-10-17T14:05:38","guid":{"rendered":"\/forum\/forums\/topic\/run-macro-with-pyansys\/"},"modified":"2023-10-17T14:05:38","modified_gmt":"2023-10-17T14:05:38","slug":"run-macro-with-pyansys","status":"closed","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/run-macro-with-pyansys\/","title":{"rendered":"Run macro with PyAnsys"},"content":{"rendered":"<p>Hi all,<\/p>\n<p>I&#8217;m trying to get a macro that is normally used in Ansys Mechan<\/p>\n<p>ical, working in PyAnsys scripting. Normally, the macro is called in a &#8216;Commands (APDL)&#8217; section under the Solution tree of my Modal analysis:<\/p>\n<p><img decoding=\"async\" src=\"\/forum\/wp-content\/uploads\/sites\/2\/2023\/10\/17-10-2023-1697550972-mceclip1.png\"><\/p>\n<p>Containing the following lines:<\/p>\n<p>&nbsp; &nbsp; finish<br \/>&nbsp; &nbsp; \/psearch, C:<br \/>&nbsp; &nbsp; moma<\/p>\n<p>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 &#8216;Save MPADL db&#8217; to Yes in Mechanical.<\/p>\n<p>In PyAnsys, I set the path to the simulation folder containing the .db file:<\/p>\n<p>&nbsp; &nbsp; mapdl=launch_mapdl(run_location=path)<\/p>\n<p>And read the .db file:<\/p>\n<p>&nbsp; &nbsp; mapdl.run(&#8220;cdread,db,file.db&#8221;)<\/p>\n<p>I run the psearch command and execute the macro in the same way as in Workbench:<\/p>\n<p>&nbsp; &nbsp; mapdl.run(&#8220;\/psearch,C:&#8221;)<br \/>&nbsp; &nbsp; mapdl.run(&#8220;moma&#8221;)<\/p>\n<p>This gives me the output &#8220;USE COMMAND MACRO moma&#8221;, but I&#8217;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?<\/p>\n<p>Thanks in advance!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"template":"","class_list":["post-311826","topic","type-topic","status-closed","hentry","topic-tag-ansys-apdl","topic-tag-ansys-mapdl-1","topic-tag-ansys-mechanical-apdl","topic-tag-apdl","topic-tag-macro-1","topic-tag-pyansys-1"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_subscription":["283755","58821"],"_bbp_author_ip":["96.7.218.239"]," _bbp_last_reply_id":["0"]," _bbp_likes_count":["0"],"_btv_view_count":["1236"],"_bbp_topic_status":["unanswered"],"_bbp_status":["publish"],"_bbp_topic_id":["311826"],"_bbp_forum_id":["27791"],"_bbp_engagement":["58821","283755"],"_bbp_voice_count":["2"],"_bbp_reply_count":["3"],"_bbp_last_reply_id":["311999"],"_bbp_last_active_id":["311999"],"_bbp_last_active_time":["2023-10-18 08:22:39"]},"test":"koen-fransedemcon-com"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/311826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/311826\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=311826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}