Create a Python extension

Pierre_20718
Pierre_20718 Altair Community Member
edited March 3 in Community Q&A

Hi,

I'm trying to create a Python extension for Hyperview (2024), with a button in the ribbon for an existing script.

I got this error:

Traceback (most recent call last):
File "S:/GitLab-Runner/builds/TqqBBs8CP/0/altairengineering/modvis/common/common/framework/win64/hwx/bin/win64/hwsigslot.py", line 1620, in _Emit
File "/users/altairbuilds6/gitlab-runner-dir/builds/qUzuQUGTh/1/altairengineering/modvis/hwx/hwdesktop/unity/scripts/python/hwx/xmlui/factory/ribbonfactory.py", line 1115, in _onCommand
File "/users/altairbuilds6/gitlab-runner-dir/builds/qUzuQUGTh/1/altairengineering/modvis/hwx/hwdesktop/unity/scripts/python/hwx/xmlui/utils.py", line 225, in execcallback
File "<string>", line 1
rescale(<generator object execcallback.<locals>.<genexpr> at 0x000001EE3EC14740>)
^
SyntaxError: invalid syntax

And my source files are :

extension.xml :

<section name="Extension">
	<! … some stuff with name, version, etc. —>
	<entry name="tclscript"			value="global-init.tcl" />
	<entry name="script"			value="global-init.py" />
	<section name="profile" value="HyperView">
		<entry name="ribbonxml" value="hv/hv-ribbon.xml" />
		<entry name="script" value="hv/hv-init.py" />
	</section>

</section>

Global-init.py and global-init.tcl are pretty empty (I start with a first button before to do more) :

import hw
from hw import hv
package require postquery
namespace eval ::MyExtension {
global env
variable workDir [file normalize [[::hwp::GetSession] GetSystemVariable CURRENTWORKINGDIR]]
}

hv/hv-ribbon.xml

<root>
<actionlist>
<action
tag="Ext_Ribbon_HV_Action_rescale"
text="Rescale legend"
tooltip="Rescale the legend with an exponential scale"
image="scale.png"
command="py: rescale"
/> </actionlist> <page tag="Ext_Ribbon_HV_Ribbon_testone" text="TEST ONE"> <group tag="Ext_Ribbon_HV_Ribbon_testonegroupone" text="GROUP ONE"> <action actiontag="Ext_Ribbon_HV_Action_rescale"/> </group> </page> </root>

hv/hv-init.py :

import sys
import hw
from hw import hv
def rescale(*a, **kwargs):

print("hello world!")
#return _rescale() # not working, so I try to only run a print…
return 0

What's wrong ?

Thanks,

Pierre

Tagged:

Answers

  • Michael Herve
    Michael Herve
    Altair Employee

    Hello @Pierre_20718 ,

    The function rescale must belong to a module, and then () must be added to the end as a function call. The path to the modeul "themodulename" must be added to sys.path

    command="py: rescale"
    
    command="py: themodulename.rescale()"
    

    Best Regards,

    Michael