From Hypermesh to XML format

Someone asks me how to export Hypermesh data in XML format? I don’t see any support of Hypermesh for this format. Fortunately, Hypermesh is a open system so anyone can work and do whatever he likes.

I begin the work by writing a template. Here’s my simple template for nodes:

	*string("<Nodes>") *end()
	*string("  <Node Id=") *quote() *field(integer,id,0) *quote() *string(" X=") *quote() *field(exponential,x,15) *quote() *string(" Y=") *quote() *field(exponential,y,15) *quote() *string(" Z=") *quote() *field(exponential,z,15) *quote() *string(" />")
	*string("</Nodes>") *end()

For 2D-elements:

	*string("  <Element Id=") *quote() *field(integer,id,0) *quote() *string(" Type=") *quote() *string("TRIA3") *quote() string(" Type=") quote() string("MINDLIN") quote() *string(" Nodes=") *quote() *field(integer,,0) *string(";") *field(integer,,0) *string(";") *field(integer,,0) *quote() *string(" />")

	*string("  <Element Id=") *quote() *field(integer,id,0) *quote() *string(" Type=") *quote() *string("QUAD4") *quote() string(" Type=") quote() string("MINDLIN") quote() *string(" Nodes=") *quote() *field(integer,,0) *string(";") *field(integer,,0) *string(";") *field(integer,,0) *string(";") *field(integer,,0) *quote() *string(" />")

Full code of my template:

Prepare a simple TCL script (adapt the path to your template):

set tpl "C:/TOTO/xml.tpl"
set myhmdir [file dirname [hm_info hmfilename]]
set output [file join $myhmdir "output.xml"]
hm_answernext yes;
eval *usercheck $tpl $output 1

Run this script on your Hypermesh session to get « output.xml »

<?xml version="1.0" encoding="UTF-8" ?>
  <Node Id="1" X="6.587804204E+00" Y="7.500000000E+01" Z="1.000000000E+01" />
  <Node Id="2" X="2.000000000E+01" Y="7.500000000E+01" Z=" 0.00000000E+00" />
  <Node Id="3" X="1.776356839E-14" Y="7.500000000E+01" Z=" 0.00000000E+00" />
  <Node Id="4" X="-2.27373675E-14" Y="2.000000000E+01" Z="2.000000000E+01" />
  <Node Id="5" X="1.000000000E+01" Y="7.500000000E+01" Z=" 0.00000000E+00" />
  <Node Id="6" X="6.587804204E+00" Y="2.000000000E+01" Z="1.000000000E+01" />
  <Node Id="7" X="2.000000000E+01" Y="7.500000000E+01" Z="2.000000000E+01" />
  <Node Id="8" X="1.000000000E+01" Y="2.000000000E+01" Z="2.000000000E+01" />
  <Node Id="9" X="1.776356839E-14" Y="7.500000000E+01" Z="2.000000000E+01" />
  <Node Id="10" X="-2.27373675E-14" Y="2.000000000E+01" Z="1.000000000E+01" />
  <Element Id="1" Type="TRIA3" Nodes="8;6;4" />
  <Element Id="2" Type="TRIA3" Nodes="13;6;8" />
  <Element Id="3" Type="TRIA3" Nodes="6;11;12" />
  <Element Id="4" Type="TRIA3" Nodes="12;10;6" />
  <Element Id="5" Type="TRIA3" Nodes="11;6;13" />
  <Element Id="6" Type="TRIA3" Nodes="6;10;4" />
  <Element Id="7" Type="QUAD4" Nodes="25;27;28;24" />
  <Element Id="8" Type="QUAD4" Nodes="24;28;22;23" />
  <Element Id="9" Type="QUAD4" Nodes="28;26;21;22" />
  <Element Id="10" Type="QUAD4" Nodes="26;28;27;61" />
  <Element Id="11" Type="TET4" Nodes="54;44;60;59" />
  <Element Id="12" Type="TET4" Nodes="54;44;53;60" />
  <Element Id="13" Type="TET4" Nodes="44;58;56;59" />
  <Element Id="14" Type="TET4" Nodes="60;44;56;59" />
  <Element Id="15" Type="TET4" Nodes="46;44;54;59" />
  <Element Id="16" Type="TET4" Nodes="46;58;44;59" />
  <Element Id="23" Type="PENTA6" Nodes="1;9;17;35;34;19" />
  <Element Id="24" Type="PENTA6" Nodes="5;15;1;36;29;35" />
  <Element Id="25" Type="PENTA6" Nodes="3;1;17;32;35;19" />
  <Element Id="26" Type="PENTA6" Nodes="15;7;16;29;30;31" />
  <Element Id="27" Type="PENTA6" Nodes="2;20;15;33;14;29" />
  <Element Id="28" Type="PENTA6" Nodes="7;15;20;30;29;14" />
  <Element Id="29" Type="PENTA6" Nodes="1;3;5;35;32;36" />
  <Element Id="30" Type="PENTA6" Nodes="15;5;2;29;36;33" />
  <Element Id="31" Type="PENTA6" Nodes="15;16;1;29;31;35" />
  <Element Id="32" Type="PENTA6" Nodes="16;9;1;31;34;35" />
  <Element Id="17" Type="HEXA8" Nodes="47;51;48;57;45;52;50;55" />
  <Element Id="18" Type="HEXA8" Nodes="40;39;51;47;49;42;52;45" />
  <Element Id="19" Type="HEXA8" Nodes="37;40;47;38;43;49;45;41" />
  <Element Id="20" Type="HEXA8" Nodes="38;47;57;62;41;45;55;63" />
  <Element Id="21" Type="HEXA8" Nodes="51;68;66;48;52;69;67;50" />
  <Element Id="22" Type="HEXA8" Nodes="39;64;68;51;42;65;69;52" />


Leave Comment

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *