HyperMesh12.0中API的变化
模型ID管理变化
新的模型ID管理与以前版本不同(官方发布在12.0.110升级包中),模型ID信息范围将按照子模型(或者Include模型)区分范围。例如:HM中包含连个include文件,include1文件与include2文件的ID范围分别是1001-2000和3001-4000,如果include1被设置为当前文件,则新的或者被导入的模型ID信息将在ID范围1001-2000内设置,并不是按照全部HM数据ID的进行更改。
于此更改相关的API命令为hm_entitymaxid。以前版本中中的ID将范围这个歌HM数据中对应类型的最大的ID,而更新后的命令将返回当前使用模型的最大的ID。
当前,hm_entitymaxid主要有两种用途:
(1)获取创建类型最大的ID,如下:
procCreateGRNOD { args } {
set d_nodesList [lindex $args 0];
if { [llength $d_nodesList] } {
set str_setName [::hwat::utils::GetUniqueName sets [lindex$args 1]];
eval *createmark nodes 1 $d_nodesList;
*entitysetcreate "$str_setName" nodes 1;
*createmark sets 1 -1;
*dictionaryload sets 1 $::str_templatePath"GRNOD";
return [hm_entitymaxidsets];
} else {
return 0;
}
}
(2)获取唯一的ID赋给指定的名称的对象,如下:
procHandleNewInDefineMaterialProperties { args } {
# First find out the maximum material ID used.
set max_mat_col_id [hm_entitymaxid mats];
# The new material ID will be one more than the existing maximum mat ID.
set ::material_id [ expr { $max_mat_col_id + 1 }];
# Set the default mu value.
set ::material_mu 0.2;
# Set the Material collector default name by adding name and ID.
# This is to make sure that it is a unique name.
set ::material_name "";
append ::material_name "TARGET_CONTACT" "_MAT_"$::material_id;
}
为了避免新的数据结构对hm_entitymaxid命令带来的影响,引入了新的命令函数hm_latestentityid,直接替换程序中的和hm_entitymaxid,如下:
procCreateGRNOD { args } {
set d_nodesList [lindex $args 0];
if { [llength $d_nodesList] } {
set str_setName [::hwat::utils::GetUniqueName sets [lindex$args 1]];
eval *createmark nodes 1 $d_nodesList;
*entitysetcreate "$str_setName" nodes 1;
*createmark sets 1 -1;
*dictionaryload sets 1 $::str_templatePath"GRNOD";
return [hm_latestentityidsets];
} else {
return 0;
}
}
解决上述问题,还可以使用其他的函数,比如hm_entityinfo maxid。如下:
procHandleNewInDefineMaterialProperties { args } {
# First find out the maximum material ID used.
set max_mat_col_id [hm_entityinfo maxidmats];
# The new material ID will be one more than the existing maximum mat ID.
set ::material_id [ expr { $max_mat_col_id + 1 }];
# Set the default mu value.
set ::material_mu 0.2;
# Set the Material collector default name by adding name and ID.
# This is to make sure that it is a unique name.
set ::material_name "";
append ::material_name "TARGET_CONTACT" "_MAT_"$::material_id;
}
对于方便模型中产生唯一的对象名称,可以使用命令hm_getincrementalname。命令格式如下:
hm_getincrementalname entity_type_list base_name ?start_num? ?num_digits?
上述命令可以在已经有的名称后面自动添加索引,以区别已经有的数据名称,参考帮助手册。
另外,对于数据选择方面的,在12.0版本中也有加强,以前使用带有负参数的命令*createmark或者hm_createmark来选择当前创建的数据ID。新版本中同样可以使用,并且,获取的数据与使用hm_latestentityid获取的ID相同。
换句话说,在新的数据结构中,HM数据中最新的ID并不一定是最大ID,而以前版本中获取最新的ID基本就是获取最大的ID,但是,随着模型数据变得复杂,新的ID并非就是最大ID,为了与新的数据ID管理结构对应,在使用有关数据ID的时候需要特别注意。