Run a python macro from extension action

Pol D
Pol D Altair Community Member
edited September 10 in Community Q&A

Hello, I have asked a question in one of your online formation earlier this week which has been left unanswered.

I am trying to run python macros from custom buttons. I have managed to create my extension to show a custom ribbon with icons. However I have trouble linking my python macro (macro1.py, located within my extension, next to the ribbon.xml file) to the action tag.

I know the documentation contains two examples :

command="py: filemenu.OpenFile()"command="py: hwf.frwk.test()" and

I can't see how to adapt these examples to run my macro file from the command : 

<action tag="my_action_tag" text="My Text" tooltip="My tooltip" image="tools_logo_80.png" command="py: ????"/>
And similarly, I am interested in running tcl macros this same way: command="tcl: ???"
 
I am working in HyperMesh OptiStruct
Thank you for your help.
Tagged:

Answers

  • Ben Buchanan
    Ben Buchanan
    Altair Employee
    edited September 10

    There are different ways to do this. I would recommend including your code in procs/functions/methods in a file that you call with the "tclscript" or "script" (for python files) entry in the extension.xml file which gets run when the extension is loaded. Then those functions are available to call in the command entry.

    You can also use source command to source a tcl file directly from the command entry or run to run a python file.