/*===========================================================*\
FUNCTION: UserApplyAndUpdateMaterial()
PURPOSE: Read a material from file, read some of its properties, and
add a user-defined parameter to it. Then assign it to the model
and calculate the model mass properties.
\*======================================================*/
ProError UserApplyAndUpdateMaterial ()
{
ProError status;
ProFileName msg_file;
ProName fopen_label;
ProLine filter_string;
ProPath* shortcut_paths;
ProName* shortcut_names;
ProPath mtl_file;
ProPath mtl_file_path;
ProPath current_dir;
ProName mtl_name;
ProMaterialItem material_item;
ProParamvalue mtl_type, mtl_density;
ProUnititem units;
int mtl_type_value;
ProParamvalue mtl_prop_value;
ProName mtl_prop_name;
ProParameter param;
ProMaterial material;
ProPath unit_expression;
ProMassProperty mass_prop;
ProPart part;
ProMdlCurrentGet((ProMdl*)&part);
/*-------------------------------------------------*\
Set up the message file.
\*------------------------------------------------*/
ProStringToWstring (msg_file, "HelpMessage.txt");
/*------------------------------------------------*\
Get the material file name from the user.
\*----------------------------------------------*/
ProStringToWstring (fopen_label, "Select material file");
ProStringToWstring (filter_string, "*.mtl");
ProArrayAlloc (0, sizeof (ProPath), 1, (ProArray*)&shortcut_paths);
ProArrayAlloc (0, sizeof (ProName), 1, (ProArray*)&shortcut_names);
status = ProFileOpen (fopen_label, filter_string, shortcut_paths,shortcut_names, NULL, NULL, mtl_file);
ProArrayFree ((ProArray*)&shortcut_paths);
ProArrayFree ((ProArray*)&shortcut_names);
if (status != PRO_TK_NO_ERROR)
{
return (status);
}
/*-------------------------------------------------*\
Change Pro/ENGINEER to the material file directory
\*-----------------------------------------------*/
ProFilenameParse (mtl_file, mtl_file_path, mtl_name, NULL, NULL);
ProDirectoryCurrentGet (current_dir);
ProDirectoryChange (mtl_file_path);
/*-------------------------------------------------*\
Read the material from the file.
\*-------------------------------------------------*/
status = ProMaterialfileRead (part, mtl_name);
ProDirectoryChange (current_dir);
if (status != PRO_TK_NO_ERROR)
{
ProMessageDisplay (msg_file, "UG MaterialFile %0s Read Error",mtl_name);//要對mtl_name進行轉換
ProDirectoryChange (current_dir);
return (status);
}
/*----------------------------------------------*\
Get the material type and density.
\*-----------------------------------------------*/
status = ProModelitemByNameInit (part, PRO_RP_MATERIAL, mtl_name,&material_item);
status = ProMaterialPropertyGet (&material_item, PRO_MATPROP_TYPE,&mtl_type, &units);
status = ProMaterialPropertyGet (&material_item,PRO_MATPROP_MASS_DENSITY,&mtl_density, &units); //由此函數,輸入想要的ProMaterialPropertyType
//可以得到所有的參數值
/*-------------------------------------------------*\
Convert the density units to a user-readable format.
\*------------------------------------------------*/
status = ProUnitExpressionGet (&units, unit_expression);
/*---------------------------------------------*\
Create a user-defined material property based on the type.
\*----------------------------------------------*/
ProStringToWstring (mtl_prop_name, "STRUCTURAL_TYPE");
mtl_type_value = mtl_type.value.i_val;
mtl_prop_value.type = PRO_PARAM_STRING;
if (mtl_type_value & PRO_MATERIAL_TYPE_STRUCTURAL_ISOTROPIC)
{
ProStringToWstring (mtl_prop_value.value.s_val, "Isotropic");
}
else if (mtl_type_value & PRO_MATERIAL_TYPE_STRUCTURAL_ORTHOTROPIC)
{
ProStringToWstring (mtl_prop_value.value.s_val, "Orthotropic");
}
else
ProStringToWstring (mtl_prop_value.value.s_val, "Transversely orthotropic");
status = ProParameterCreate (&material_item, mtl_prop_name, &mtl_prop_value, ¶m);
/*--------------------------------------------*\
Assign the material, and compute the mass properties.
\*----------------------------------------*/
material.part = part;
ProWstringCopy (mtl_name, material.matl_name, PRO_VALUE_UNUSED);
status = ProMaterialCurrentSet (&material);
status = ProSolidMassPropertyGet (part, NULL, &mass_prop);
ProMessageDisplay (msg_file, "UG MaterialFile Mass Info:mtl_name:%s; mtl_density:%f ;unit:%s; mass:%f", mtl_name,
&mtl_density.value.d_val, unit_expression,
&mass_prop.mass);//這句話未能顯示出來!
return (PRO_TK_NO_ERROR);
}