how to write the nodal mesh information into a txt file using macro

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

Dear Member:

I am trying to write my current model's nodal information and mesh into a txt file, is there a way that I can do it use macro file to do it. I know HyperWorks has a lot of options in the export section but none of them matches my goal. I prefer to write a txt file by macro into the format that I need then I can use that model information directly for my research. Can anyone help me with this?

Tinh, sorry about the misplacement of my last post, I deleted that topic cuz I am pretty new with this forum and do not have a clue how to move the topic but thank you for your help with that. Do you have an idea with this topic in any ways.

Sincerely,

Chong

Answers

  • tinh
    tinh Altair Community Member
    edited January 2013

    Hi, Chong

    we can use tcl macro to write out nodal and mesh. This is a minimum example:

    #File name: output_node_elem.tcl

    set output_file [open output_file_name.txt w]

    puts $output_file '#NODES:'

    foreach nodeid [hm_entitylist nodes id] {

    foreach {x y z} [expr [hm_nodevalue $nodeid]] {break}

    puts $output_file '[format %8i $nodeid][format %.12e $x][format %.12e $y][format %.12e $z]'

    }

    puts $output_file '#ELEMS:'

    foreach elemid [hm_entitylist elems id] {

    set elem_info '[format %8i $elemid]'

    foreach nodeid [hm_nodelist $elemid] {append elem_info '[format %8i $nodeid]'}

    puts $output_file $elem_info

    }

    close $ouput_file

    #end of file output_node_elem.tcl

    But it's better to use template file to output data especially with big model. This will speed up the process by using HM core (instead of tcl)

    Below is a small sample of template file:

    *nodes()

    *before()

    *string('#NODE')

    *end()

    *format()

    *fieldright(integer,id,8)

    *string(' ')

    *fieldright(real,x,12)

    *string(' ')

    *fieldright(real,y,12)

    *string(' ')

    *fieldright(real,z,12)

    *end()

    *output()

    *elements(,,)

    *before()

    *string('#ELEMS')

    *end()

    *format()

    *fieldright(integer,id,8)

    *end()

    *output()

    In export tab, select 'custom' template and browse to this file and then export to text file. Many template files corresponding to solvers are available in [installdir]\templates\feoutput\...

    To output data by template, you should study template commands and syntax and data names using in hypermesh

    If your tasks is simple, it's easier to use tcl macro

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2013

    Hi Tinh,

    Thanks a lot. I will go ahead and try that.

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2013

    Hi Tinh,

    By the way, I have trouble renumbering the elements in hyperworks. I have a 3d structure that I created some 2d elements to refine my 3d mesh on surfaces and after that I deleted all the 2d elements. But no matter I use macro or by direct click the button on tab, the elements number can not be rearranged from 1 to max number after I deleted all the 2d elements. Is there a way I can write a macro to deal with this?

    Best Regards,

    Chong

  • tinh
    tinh Altair Community Member
    edited January 2013

    Hi Chong,

    Please confirm any other element remained, for example some 3D elements of other component which already have id from 1~..., so when you renumber your new elements, their ids will be offset. If solver does not support duplicated ids you need check other elems id (1D, 0D) also

    I think in this case macro cannot overcome, macro just recall commands we done in hm GUI

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2013

    Finally I figured out this problem. By clicking the option menu on Hyperworks, it only renumbers the solverid which applies *renumbersolverid but when I use the command *renumber instead, the id rearranged from 1 to max_number.

  • Unknown
    edited May 2018

    Hi there,

    I have a question. To run the tcl do we need to change anything you Tinh typed here? For example where it says File name do we have to actually replace it with our file name our do we leave the code just as it is?

     

    Sorry if it's a dumb question but I don't understand about this code...

     

    Best Regards,

    Rodrigo

  • tinh
    tinh Altair Community Member
    edited May 2018

    Hi

    any valid name is ok. after '#' is just comment

  • Unknown
    edited May 2018

    Thanks for the quick answer.

    I'm getting always the same error message. It keeps saying:  Error:can't read 'output_file':no such variable.

  • tinh
    tinh Altair Community Member
    edited May 2018

    you are missing this line

    set output_file [open output_file_name.txt w]

     

    or you changed 'output_file' to other name, please keep it

    'output_file_name' can be changed to any valid name

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited March 2019

    Dear tinh,

     

    How can I write the list of node connectvity? (list of nodes attached to each element)

     

    I've tried *fieldright(integer,nodes,8), but it didn't work.

     

    Thanks.

     

     

  • Q.Nguyen-Dai
    Q.Nguyen-Dai Altair Community Member
    edited March 2019

    foreach nodeid [hm_entitylist nodes id] {

    foreach {x y z} [expr [hm_nodevalue $nodeid]] {break}

    puts $output_file '[format %8i $nodeid][format %.12e $x][format %.12e $y][format %.12e $z]'

    }

     

    Instead of using of 4xformat, I write always:

     puts $output_file [format '%8i %.12e %.12e %.12e' $nodeid $x $y $z]

     

  • tinh
    tinh Altair Community Member
    edited March 2019

    Yeah 4x format is very long typing at that time i didn't know how format works!

     

    @meshbeginnerFrom v13, hm_getvalue is a very useful cmd.

    For nodes, use node1.id, node2.id,  ... *field(integer,node1.id,8)