how to fix the macro to save file?

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Hi guys, I wrote a macro for saving file, but when I click the button, an error message is displayed. How can I fix it? Thank you!

 

The code of the macro:

 *beginmacro(macrosave) *writefile 'D:/Documents/temp.hm' 1 *answer(yes) *endmacro() *createbutton(5, 'Save File', 20, 0, 10, GREEN, 'Save file', 'macrosave')

 

The error message:

 

image.png.f02f9a67cc5a054a28d61099962e951d.png

 

Tagged:

Answers

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    Hi @Hao Jiang To save file use only this command:

    *writefile 'C:/Users/ABCD/Desktop/a11.hm' 1

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited May 2018

    Hi Jouher, only *writefile can work, but I want to create a button, when the button is clicked, macro is called.

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    @Hao Jiang Please write command : *writefile 'C:/Users/ABCD/Desktop/a11.hm' 1 in separate tcl file and save. 

    go to userpage.mac file: there you add *createbutton. This will work.

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited May 2018

    @Hao Jiang Please write command : *writefile 'C:/Users/ABCD/Desktop/a11.hm' 1 in separate tcl file and save. 

    go to userpage.mac file: there you add *createbutton. This will work.

     

    Thanks,  Jouher, it work. However, how can I call a macro by click a button?

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited May 2018

    in the userpage.mac file add command in this way. then reload hm and go to utility users.

     

    *createbutton(5, 'Name to be displayed on button', 0, 0, 10, BLUE, '',EvalTcl,'Path\Macroname.tcl')

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited May 2018

    Hi,

    You have to pass parameters, separated by commas and enclosed in parentheses:

     *writefile('D:/Documents/temp.hm', 1) 

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited May 2018

    in the userpage.mac file add command in this way. then reload hm and go to utility users.

     

    *createbutton(5, 'Name to be displayed on button', 0, 0, 10, BLUE, '',EvalTcl,'Path\Macroname.tcl')

     

     

    Thank you Jouher, it work. And I test some times, following coad is work:

     *beginmacro('macrosave') *writefile(D:\Documents\temp.hm, 1) *answer(yes) *endmacro()

    Although syntax of “*answer” is 'answer yes', but it doesn't work. When I use '*answer(yes)', it work. I don't know why.

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited May 2018

    Hi,

    You have to pass parameters, separated by commas and enclosed in parentheses:

      *writefile('D:/Documents/temp.hm', 1) 

     

     

    Thank you akitoguc, I found that in .tcl file, '*writefile('D:/Documents/temp.hm', 1)' doesn't work, but  '*writefile 'D:/Documents/temp.hm' 1 ' work,  Is it because the TCL file and the MAC file are different?

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited May 2018

    You are right, Hao.

    Syntax to call a command/procedure with parameters is different between Tcl file and command file. Take parentheses and commans away from Tcl statements to port the code to command file.

     

    Regards,