Jump to content
Chong

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

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×