HW v2022.2 Multi-client Extensions for Ribbons, Dropdowns and Toolbars

Ben Buchanan
Ben Buchanan
Altair Employee
edited August 2023 in Altair HyperWorks

Introduction

Extensions are a way to customize your Altair applications and to seamlessly include your scripts into the graphical user interface (GUI). In this blog I will focus on HyperMesh (HM) and will touch on HyperView (HV) and HyperGraph (HG), but other Altair Products also use extensions for customization. I will focus on explaining the framework so that what I show can be easily repurposed for your own customization. I will show how to add a button on ribbons, in menus and on toolbars.

image

Mechanics 

Each extension needs its own extension.xml file but one extension.xml file can point to multiple ribbons, menus, and toolbars for multiple clients (HM, HV, HG). The image below shows part of an extension.xml file (also attached) that adds a ribbon, menu, and toolbar in HM, HV and HG. The corresponding view of the Extension Manager with corresponding fields marked in both is also shown. 

image

The file called out with “tclscript” above (#6 in yellow), found in the same directory as the extension.xml file, runs when the extension is activated and when HyperWorks is open if the extension is left active. This file holds the procedures used in the extension, called by the “command” parameter in the xml file in the profile sections below. For this example, a simple message box is displayed when each button is pushed. 

image

In each profile section, there is a folder with the toolbar xml file(s) and file specified for the menu and ribbon xml files. These xml files control what is seen and done for each toolbar, menu, and ribbon. The actionlist section defines the behavior of the item/button and the page/toolbar section defines the organization of the button(s) in the GUI. 

Actionlist parameters (see images below) 

  • tag is the handle used to call the item and must be unique
  • text is the text that will show under the ribbon item or in the menu (toolbars do not have text)
  • tooltip is what will show on hovering over the item
  • image is the image that shows for that item
  • command is the action that will be performed if the button is pushed 

Page parameters for ribbons (see image below) 

  • group defines a part of the ribbon separated by vertical lines 
  • action defines a button/item on the ribbon 

image

Page parameter for menu (see image below) 

  • menu defines a dropdown menu
  • actiongroup is a submenu under the menu
  • action is an item either in the menu or submenu (actiongroup) 

image

Toolbar parameters: 

  • Just list the buttons/actions you want in order in the toolbar section 

This is certainly not an exhaustive view of extensions but should be enough to get started and at least get your script attached to a button. 

image

Here are some references about extensions and some actual extensions: 

https://help.altair.com/hwdesktop/hwd/topics/reference/extensions/extensions_r.htm 

https://community.altair.com/community?id=kb_article&sysparm_article=KB0120189 

https://community.altair.com/community?id=kb_article&sysparm_article=KB0121742 

https://community.altair.com/community?id=kb_article&sysparm_article=KB0121665 

TLDR 

  1. Download and extract AddAButtonHGHVHM.zip 
  1. In the Extension Manager point to the extracted folder 
  1. Change the command value in the xml files contained in the sub folders to you desired function 
  1. If the desired function is a TCL procedure add that procedure to the InitExtBB.tcl file 

 

Comments

  • FaForno
    FaForno Altair Community Member
    edited January 17

    Dear Ben,

    really interesting topic.

    How can I work if I would like to point different routine stored separately?

    I mean: I have routine on several files and I don't like to simply add them in InitExtBB.tcl file but I would keep in separate files (i.e.: start_model.tcl, loadmodel.tcl, frequencymodel.tcl), I suppose I will need to declare them in the InitExtBB.tcl, how can I?

     

    Another poit: if I want to create a button, not in the ribbon but a simple button for each macro, the image has to be one single image?

    (For ribbon I notice in the file ribbonExplosionStrip-80.png several picture one after the other, what is the meaning?)

     

    Thanks a lot for the topic.

     

    Regards,

    Fabio

  • Ben Buchanan
    Ben Buchanan
    Altair Employee
    edited January 17
    FaForno said:

    Dear Ben,

    really interesting topic.

    How can I work if I would like to point different routine stored separately?

    I mean: I have routine on several files and I don't like to simply add them in InitExtBB.tcl file but I would keep in separate files (i.e.: start_model.tcl, loadmodel.tcl, frequencymodel.tcl), I suppose I will need to declare them in the InitExtBB.tcl, how can I?

     

    Another poit: if I want to create a button, not in the ribbon but a simple button for each macro, the image has to be one single image?

    (For ribbon I notice in the file ribbonExplosionStrip-80.png several picture one after the other, what is the meaning?)

     

    Thanks a lot for the topic.

     

    Regards,

    Fabio

    Fabio,

    Thanks for reading!

    You can source your files from the InitExtBB.tcl file. Here is the help page:

    https://help.altair.com/hwdesktop/hwd/topics/reference/hm/running_scripts_r.htm?zoom_highlight=hwt

    but essentially you just use source or hwt::Source then your filename/path. The difference is just where they look if you don't give the full path.

    For the images you can use a single image and, especially if it has a blank background, it will work fine. The fancy multi-image image defines what the image looks like in different states (selected, unselected etc.)

    Thanks,

    Ben

     

  • FaForno
    FaForno Altair Community Member
    edited January 18

    Dear Ben,

    seems I'm been able to create a toolbar! 

    But the image is a broken picture on HyperMesh.

    I've simply tryed to use the attached image as picture but seems it doesn't work fine.

    Do you know why?

     

    Thanks a lot for precious help!

    Regards,

    Fabio

  • FaForno
    FaForno Altair Community Member
    edited January 18

    Dear Ben,

    I have fixed the topic of icon but now ...

    I am struggling adding the file with the script in the starting file.

    I don't understand how call an externalmacro and not a procedure inside the InitExt.tcl

    image

    And then I call this procedure in the Actionlist:

    image

    but seems there is something wrong...

     

    Can you, pleas, help me?

     

    Thanks a lot,

    Fabio

  • Ben Buchanan
    Ben Buchanan
    Altair Employee
    edited January 18
    FaForno said:

    Dear Ben,

    I have fixed the topic of icon but now ...

    I am struggling adding the file with the script in the starting file.

    I don't understand how call an externalmacro and not a procedure inside the InitExt.tcl

    image

    And then I call this procedure in the Actionlist:

    image

    but seems there is something wrong...

     

    Can you, pleas, help me?

     

    Thanks a lot,

    Fabio

    Try it with {} around the path.

    ::hwt::Source {c:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}

    Ooh and it looks like you have and extra } on the line afte the source command.

  • FaForno
    FaForno Altair Community Member
    edited January 18

    FaForno said:

    Dear Ben,

    I have fixed the topic of icon but now ...

    I am struggling adding the file with the script in the starting file.

    I don't understand how call an externalmacro and not a procedure inside the InitExt.tcl

    image

    And then I call this procedure in the Actionlist:

    image

    but seems there is something wrong...

     

    Can you, pleas, help me?

     

    Thanks a lot,

    Fabio

    Try it with {} around the path.

    ::hwt::Source {c:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}

    Ooh and it looks like you have and extra } on the line afte the source command.

    No, it doesn't work.

    I really don't understand where  is the mistake :(

     

    Fabio

  • FaForno
    FaForno Altair Community Member
    edited January 18
    FaForno said:

    FaForno said:

    Dear Ben,

    I have fixed the topic of icon but now ...

    I am struggling adding the file with the script in the starting file.

    I don't understand how call an externalmacro and not a procedure inside the InitExt.tcl

    image

    And then I call this procedure in the Actionlist:

    image

    but seems there is something wrong...

     

    Can you, pleas, help me?

     

    Thanks a lot,

    Fabio

    Try it with {} around the path.

    ::hwt::Source {c:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}

    Ooh and it looks like you have and extra } on the line afte the source command.

    No, it doesn't work.

    I really don't understand where  is the mistake :(

     

    Fabio

    And I don't see any extra } 

  • Ben Buchanan
    Ben Buchanan
    Altair Employee
    edited January 18
    FaForno said:

    FaForno said:

    FaForno said:

    Dear Ben,

    I have fixed the topic of icon but now ...

    I am struggling adding the file with the script in the starting file.

    I don't understand how call an externalmacro and not a procedure inside the InitExt.tcl

    image

    And then I call this procedure in the Actionlist:

    image

    but seems there is something wrong...

     

    Can you, pleas, help me?

     

    Thanks a lot,

    Fabio

    Try it with {} around the path.

    ::hwt::Source {c:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}

    Ooh and it looks like you have and extra } on the line afte the source command.

    No, it doesn't work.

    I really don't understand where  is the mistake :(

     

    Fabio

    And I don't see any extra } 

    This is the procedure you are showing:

    proc ::ExtBB::01_MyStart_rev04 {key} {     ::hwt::Source C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc     } }

    Without having more details I might expect something like this:

    proc ::ExtBB::01_MyStart_rev04 {} {     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc} }

    The next thing I would do to debug is add puts statements to see how far it is getting in your code. Maybe something like this.

    proc ::ExtBB::01_MyStart_rev04 {} {     puts "before source"     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}     puts "after source" }

    and maybe another puts statement in your file to see if it is actually reading it.

    You could also try sourcing your file straight from the xml.

  • Marc Arnold
    Marc Arnold
    Altair Employee
    edited February 10

    Great article @Ben Buchanan, very helpful !

    I have one question regarding the tags
    Do they need to be unique only in the extension itself, or in all imported extensions, or in all possible tags including core tags, printed out with "ctx:ui print"? 

    Can tags from different categories (page/group/menu) have the same name or should they be also always unique?

    I'm running often in issues when copy+pasting extensions :)

  • Ben Buchanan
    Ben Buchanan
    Altair Employee
    edited February 12

    Great article @Ben Buchanan, very helpful !

    I have one question regarding the tags
    Do they need to be unique only in the extension itself, or in all imported extensions, or in all possible tags including core tags, printed out with "ctx:ui print"? 

    Can tags from different categories (page/group/menu) have the same name or should they be also always unique?

    I'm running often in issues when copy+pasting extensions :)

    Hi Marc,

    Thanks for reading. Glad it was helpful. Yes the tags need to be unique throughout. This allows you to easily add existing functions into extensions. You can then have a mix of custom and core items in your custom ribbon/menu/toolbar. You could also reference items from other extensions but this becomes a little risky since if you turn off 1 extension it may break another.

    Thanks,

    Ben

  • Marc Arnold
    Marc Arnold
    Altair Employee
    edited February 13

    Great article @Ben Buchanan, very helpful !

    I have one question regarding the tags
    Do they need to be unique only in the extension itself, or in all imported extensions, or in all possible tags including core tags, printed out with "ctx:ui print"? 

    Can tags from different categories (page/group/menu) have the same name or should they be also always unique?

    I'm running often in issues when copy+pasting extensions :)

    Hi Marc,

    Thanks for reading. Glad it was helpful. Yes the tags need to be unique throughout. This allows you to easily add existing functions into extensions. You can then have a mix of custom and core items in your custom ribbon/menu/toolbar. You could also reference items from other extensions but this becomes a little risky since if you turn off 1 extension it may break another.

    Thanks,

    Ben

    Is there a possibility to check if a tag is used? 

    Thanks, 

    Marc 

  • Luke Dykstra
    Luke Dykstra Altair Community Member
    edited April 26

    FaForno said:

    FaForno said:

    FaForno said:

    Dear Ben,

    I have fixed the topic of icon but now ...

    I am struggling adding the file with the script in the starting file.

    I don't understand how call an externalmacro and not a procedure inside the InitExt.tcl

    image

    And then I call this procedure in the Actionlist:

    image

    but seems there is something wrong...

     

    Can you, pleas, help me?

     

    Thanks a lot,

    Fabio

    Try it with {} around the path.

    ::hwt::Source {c:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}

    Ooh and it looks like you have and extra } on the line afte the source command.

    No, it doesn't work.

    I really don't understand where  is the mistake :(

     

    Fabio

    And I don't see any extra } 

    This is the procedure you are showing:

    proc ::ExtBB::01_MyStart_rev04 {key} {     ::hwt::Source C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc     } }

    Without having more details I might expect something like this:

    proc ::ExtBB::01_MyStart_rev04 {} {     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc} }

    The next thing I would do to debug is add puts statements to see how far it is getting in your code. Maybe something like this.

    proc ::ExtBB::01_MyStart_rev04 {} {     puts "before source"     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}     puts "after source" }

    and maybe another puts statement in your file to see if it is actually reading it.

    You could also try sourcing your file straight from the xml.

    Helllo FaForno and Ben,

    Did you ever figure out how to get your .tcl script to work? I am having the same issue with trying to run a separate .tcl script inside of the InitExtBB.tcl file. I too am unable to get the ribbon icon in hyperview run the .tcl script that I want it to. I have tried many different avenues and inputs but only to get nothing working eachtime.

    If you have anyfeedback on this it would great if you shared.

    I have the following .

    image

    image

    Thank you.

  • Ben Buchanan
    Ben Buchanan
    Altair Employee
    edited April 26

    FaForno said:

    FaForno said:

    FaForno said:

    Dear Ben,

    I have fixed the topic of icon but now ...

    I am struggling adding the file with the script in the starting file.

    I don't understand how call an externalmacro and not a procedure inside the InitExt.tcl

    image

    And then I call this procedure in the Actionlist:

    image

    but seems there is something wrong...

     

    Can you, pleas, help me?

     

    Thanks a lot,

    Fabio

    Try it with {} around the path.

    ::hwt::Source {c:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}

    Ooh and it looks like you have and extra } on the line afte the source command.

    No, it doesn't work.

    I really don't understand where  is the mistake :(

     

    Fabio

    And I don't see any extra } 

    This is the procedure you are showing:

    proc ::ExtBB::01_MyStart_rev04 {key} {     ::hwt::Source C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc     } }

    Without having more details I might expect something like this:

    proc ::ExtBB::01_MyStart_rev04 {} {     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc} }

    The next thing I would do to debug is add puts statements to see how far it is getting in your code. Maybe something like this.

    proc ::ExtBB::01_MyStart_rev04 {} {     puts "before source"     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}     puts "after source" }

    and maybe another puts statement in your file to see if it is actually reading it.

    You could also try sourcing your file straight from the xml.

    Helllo FaForno and Ben,

    Did you ever figure out how to get your .tcl script to work? I am having the same issue with trying to run a separate .tcl script inside of the InitExtBB.tcl file. I too am unable to get the ribbon icon in hyperview run the .tcl script that I want it to. I have tried many different avenues and inputs but only to get nothing working eachtime.

    If you have anyfeedback on this it would great if you shared.

    I have the following .

    image

    image

    Thank you.

    You are sourcing the file within a proc which I imagine isn't getting called. Source the file outside of the proc command.

  • FaForno
    FaForno Altair Community Member
    edited April 28

    FaForno said:

    FaForno said:

    FaForno said:

    Dear Ben,

    I have fixed the topic of icon but now ...

    I am struggling adding the file with the script in the starting file.

    I don't understand how call an externalmacro and not a procedure inside the InitExt.tcl

    image

    And then I call this procedure in the Actionlist:

    image

    but seems there is something wrong...

     

    Can you, pleas, help me?

     

    Thanks a lot,

    Fabio

    Try it with {} around the path.

    ::hwt::Source {c:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}

    Ooh and it looks like you have and extra } on the line afte the source command.

    No, it doesn't work.

    I really don't understand where  is the mistake :(

     

    Fabio

    And I don't see any extra } 

    This is the procedure you are showing:

    proc ::ExtBB::01_MyStart_rev04 {key} {     ::hwt::Source C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc     } }

    Without having more details I might expect something like this:

    proc ::ExtBB::01_MyStart_rev04 {} {     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc} }

    The next thing I would do to debug is add puts statements to see how far it is getting in your code. Maybe something like this.

    proc ::ExtBB::01_MyStart_rev04 {} {     puts "before source"     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}     puts "after source" }

    and maybe another puts statement in your file to see if it is actually reading it.

    You could also try sourcing your file straight from the xml.

    Helllo FaForno and Ben,

    Did you ever figure out how to get your .tcl script to work? I am having the same issue with trying to run a separate .tcl script inside of the InitExtBB.tcl file. I too am unable to get the ribbon icon in hyperview run the .tcl script that I want it to. I have tried many different avenues and inputs but only to get nothing working eachtime.

    If you have anyfeedback on this it would great if you shared.

    I have the following .

    image

    image

    Thank you.

    Dear Luke,

    at the end I manage this adding, in the file: hm-toolbar-actions.xml

    the line, written as the follow:

    <action tag="01_MyStart" tooltip="General starting model" image="01_MyStart.png" command="tcl: source C:/MacroAltair/Script/01_MyStart_rev105.tbc"/>
     
    I am still not sure but, the BBB file, for my structure, have no real needs to be placed in hte folder.
     
    Fabio
  • Luke Dykstra
    Luke Dykstra Altair Community Member
    edited May 1

    FaForno said:

    FaForno said:

    FaForno said:

    Dear Ben,

    I have fixed the topic of icon but now ...

    I am struggling adding the file with the script in the starting file.

    I don't understand how call an externalmacro and not a procedure inside the InitExt.tcl

    image

    And then I call this procedure in the Actionlist:

    image

    but seems there is something wrong...

     

    Can you, pleas, help me?

     

    Thanks a lot,

    Fabio

    Try it with {} around the path.

    ::hwt::Source {c:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}

    Ooh and it looks like you have and extra } on the line afte the source command.

    No, it doesn't work.

    I really don't understand where  is the mistake :(

     

    Fabio

    And I don't see any extra } 

    This is the procedure you are showing:

    proc ::ExtBB::01_MyStart_rev04 {key} {     ::hwt::Source C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc     } }

    Without having more details I might expect something like this:

    proc ::ExtBB::01_MyStart_rev04 {} {     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc} }

    The next thing I would do to debug is add puts statements to see how far it is getting in your code. Maybe something like this.

    proc ::ExtBB::01_MyStart_rev04 {} {     puts "before source"     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}     puts "after source" }

    and maybe another puts statement in your file to see if it is actually reading it.

    You could also try sourcing your file straight from the xml.

    Helllo FaForno and Ben,

    Did you ever figure out how to get your .tcl script to work? I am having the same issue with trying to run a separate .tcl script inside of the InitExtBB.tcl file. I too am unable to get the ribbon icon in hyperview run the .tcl script that I want it to. I have tried many different avenues and inputs but only to get nothing working eachtime.

    If you have anyfeedback on this it would great if you shared.

    I have the following .

    image

    image

    Thank you.

    You are sourcing the file within a proc which I imagine isn't getting called. Source the file outside of the proc command.

    Thank you Ben. I need to apologize for my ignorance in this manner, but what would it look like to source the file outside the proc? I am pretty new to programming in general and vrey new to working with tcl.

    Thank you,

    Luke

  • Ben Buchanan
    Ben Buchanan
    Altair Employee
    edited May 1

    FaForno said:

    FaForno said:

    FaForno said:

    Dear Ben,

    I have fixed the topic of icon but now ...

    I am struggling adding the file with the script in the starting file.

    I don't understand how call an externalmacro and not a procedure inside the InitExt.tcl

    image

    And then I call this procedure in the Actionlist:

    image

    but seems there is something wrong...

     

    Can you, pleas, help me?

     

    Thanks a lot,

    Fabio

    Try it with {} around the path.

    ::hwt::Source {c:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}

    Ooh and it looks like you have and extra } on the line afte the source command.

    No, it doesn't work.

    I really don't understand where  is the mistake :(

     

    Fabio

    And I don't see any extra } 

    This is the procedure you are showing:

    proc ::ExtBB::01_MyStart_rev04 {key} {     ::hwt::Source C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc     } }

    Without having more details I might expect something like this:

    proc ::ExtBB::01_MyStart_rev04 {} {     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc} }

    The next thing I would do to debug is add puts statements to see how far it is getting in your code. Maybe something like this.

    proc ::ExtBB::01_MyStart_rev04 {} {     puts "before source"     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}     puts "after source" }

    and maybe another puts statement in your file to see if it is actually reading it.

    You could also try sourcing your file straight from the xml.

    Helllo FaForno and Ben,

    Did you ever figure out how to get your .tcl script to work? I am having the same issue with trying to run a separate .tcl script inside of the InitExtBB.tcl file. I too am unable to get the ribbon icon in hyperview run the .tcl script that I want it to. I have tried many different avenues and inputs but only to get nothing working eachtime.

    If you have anyfeedback on this it would great if you shared.

    I have the following .

    image

    image

    Thank you.

    You are sourcing the file within a proc which I imagine isn't getting called. Source the file outside of the proc command.

    Thank you Ben. I need to apologize for my ignorance in this manner, but what would it look like to source the file outside the proc? I am pretty new to programming in general and vrey new to working with tcl.

    Thank you,

    Luke

    No worries. Glad to help.

    Here is a help page for proc:
    https://www.tcl.tk/man/tcl8.5/TclCmd/proc.htm

    A proc or procedure is how tcl creates functions. So when the file is run these are stored and can be called later but aren't actually run.

    So, if you have this:

    proc ::ExtBB::ColdCruelWorld {key} {
        switch $key {
            hi {tk_messageBox -message "Hello, Cold Cruel World!"}
            bye {tk_messageBox -message "Goodbye, Cold Cruel World!"}
        }
    }
    Neither message will popup until you call that procedure in another part of your code. Like so:
    ::ExtBB::ColdCruelWorld hi
     
    So you probably just want to source your file outside the braces of the proc command. Something like this:
    proc ::ExtBB::ColdCruelWorld {key} {
        #can delete this procedure since you aren't using it anymore.
    }
    hwtk::source {filename}
  • Luke Dykstra
    Luke Dykstra Altair Community Member
    edited May 1

    FaForno said:

    FaForno said:

    FaForno said:

    Dear Ben,

    I have fixed the topic of icon but now ...

    I am struggling adding the file with the script in the starting file.

    I don't understand how call an externalmacro and not a procedure inside the InitExt.tcl

    image

    And then I call this procedure in the Actionlist:

    image

    but seems there is something wrong...

     

    Can you, pleas, help me?

     

    Thanks a lot,

    Fabio

    Try it with {} around the path.

    ::hwt::Source {c:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}

    Ooh and it looks like you have and extra } on the line afte the source command.

    No, it doesn't work.

    I really don't understand where  is the mistake :(

     

    Fabio

    And I don't see any extra } 

    This is the procedure you are showing:

    proc ::ExtBB::01_MyStart_rev04 {key} {     ::hwt::Source C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc     } }

    Without having more details I might expect something like this:

    proc ::ExtBB::01_MyStart_rev04 {} {     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc} }

    The next thing I would do to debug is add puts statements to see how far it is getting in your code. Maybe something like this.

    proc ::ExtBB::01_MyStart_rev04 {} {     puts "before source"     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}     puts "after source" }

    and maybe another puts statement in your file to see if it is actually reading it.

    You could also try sourcing your file straight from the xml.

    Helllo FaForno and Ben,

    Did you ever figure out how to get your .tcl script to work? I am having the same issue with trying to run a separate .tcl script inside of the InitExtBB.tcl file. I too am unable to get the ribbon icon in hyperview run the .tcl script that I want it to. I have tried many different avenues and inputs but only to get nothing working eachtime.

    If you have anyfeedback on this it would great if you shared.

    I have the following .

    image

    image

    Thank you.

    You are sourcing the file within a proc which I imagine isn't getting called. Source the file outside of the proc command.

    Thank you Ben. I need to apologize for my ignorance in this manner, but what would it look like to source the file outside the proc? I am pretty new to programming in general and vrey new to working with tcl.

    Thank you,

    Luke

    No worries. Glad to help.

    Here is a help page for proc:
    https://www.tcl.tk/man/tcl8.5/TclCmd/proc.htm

    A proc or procedure is how tcl creates functions. So when the file is run these are stored and can be called later but aren't actually run.

    So, if you have this:

    proc ::ExtBB::ColdCruelWorld {key} {
        switch $key {
            hi {tk_messageBox -message "Hello, Cold Cruel World!"}
            bye {tk_messageBox -message "Goodbye, Cold Cruel World!"}
        }
    }
    Neither message will popup until you call that procedure in another part of your code. Like so:
    ::ExtBB::ColdCruelWorld hi
     
    So you probably just want to source your file outside the braces of the proc command. Something like this:
    proc ::ExtBB::ColdCruelWorld {key} {
        #can delete this procedure since you aren't using it anymore.
    }
    hwtk::source {filename}

    Great. Thank you Ben.

    That is very smooth operation when the extension is turned on and off from the manager window. 

    I just need to work on getting that same procedure to work when I click the ribbon icon that i setup. Thought it was as easy as calling the Init.tcl script in the command line of the .xml script but seems to be more complicated than that.

  • Luke Dykstra
    Luke Dykstra Altair Community Member
    edited May 1

    FaForno said:

    FaForno said:

    FaForno said:

    Dear Ben,

    I have fixed the topic of icon but now ...

    I am struggling adding the file with the script in the starting file.

    I don't understand how call an externalmacro and not a procedure inside the InitExt.tcl

    image

    And then I call this procedure in the Actionlist:

    image

    but seems there is something wrong...

     

    Can you, pleas, help me?

     

    Thanks a lot,

    Fabio

    Try it with {} around the path.

    ::hwt::Source {c:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}

    Ooh and it looks like you have and extra } on the line afte the source command.

    No, it doesn't work.

    I really don't understand where  is the mistake :(

     

    Fabio

    And I don't see any extra } 

    This is the procedure you are showing:

    proc ::ExtBB::01_MyStart_rev04 {key} {     ::hwt::Source C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc     } }

    Without having more details I might expect something like this:

    proc ::ExtBB::01_MyStart_rev04 {} {     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc} }

    The next thing I would do to debug is add puts statements to see how far it is getting in your code. Maybe something like this.

    proc ::ExtBB::01_MyStart_rev04 {} {     puts "before source"     ::hwt::Source {C:/Marcro_Altair/2022/Script/01_MyStart_rev04.tbc}     puts "after source" }

    and maybe another puts statement in your file to see if it is actually reading it.

    You could also try sourcing your file straight from the xml.

    Helllo FaForno and Ben,

    Did you ever figure out how to get your .tcl script to work? I am having the same issue with trying to run a separate .tcl script inside of the InitExtBB.tcl file. I too am unable to get the ribbon icon in hyperview run the .tcl script that I want it to. I have tried many different avenues and inputs but only to get nothing working eachtime.

    If you have anyfeedback on this it would great if you shared.

    I have the following .

    image

    image

    Thank you.

    You are sourcing the file within a proc which I imagine isn't getting called. Source the file outside of the proc command.

    Thank you Ben. I need to apologize for my ignorance in this manner, but what would it look like to source the file outside the proc? I am pretty new to programming in general and vrey new to working with tcl.

    Thank you,

    Luke

    No worries. Glad to help.

    Here is a help page for proc:
    https://www.tcl.tk/man/tcl8.5/TclCmd/proc.htm

    A proc or procedure is how tcl creates functions. So when the file is run these are stored and can be called later but aren't actually run.

    So, if you have this:

    proc ::ExtBB::ColdCruelWorld {key} {
        switch $key {
            hi {tk_messageBox -message "Hello, Cold Cruel World!"}
            bye {tk_messageBox -message "Goodbye, Cold Cruel World!"}
        }
    }
    Neither message will popup until you call that procedure in another part of your code. Like so:
    ::ExtBB::ColdCruelWorld hi
     
    So you probably just want to source your file outside the braces of the proc command. Something like this:
    proc ::ExtBB::ColdCruelWorld {key} {
        #can delete this procedure since you aren't using it anymore.
    }
    hwtk::source {filename}

    Great. Thank you Ben.

    That is very smooth operation when the extension is turned on and off from the manager window. 

    I just need to work on getting that same procedure to work when I click the ribbon icon that i setup. Thought it was as easy as calling the Init.tcl script in the command line of the .xml script but seems to be more complicated than that.

    I have it figured out with some troubleshooting. Pretty simple to do once you figure out what it needs in order to operate correctly. 

    Thank you again for the input and help. 

    If you every come up with more scripts or insight into using the extension manager I would not mind connecting and discussing.

  • Peter H.
    Peter H. Altair Community Member
    edited July 12

    Is there a possibility to run a python script (Version 2024)?

    I can use <entry name="script" in the extension.xml, but this script is executed on loading.
    I'd like to run a function on click on a ribbon icon.
    If I add an '<action tag.... command="py:' it is possible to run python commands, but not parts of any custom python file or the file I loaded before. 

    Tanks,

    Peter