void UserReplaceInstanceInAssembly()
{
int n_sel, *ids;
ProSelection *p_sel = NULL;
ProError err;
ProAsmcomppath path;
ProMdl mdl;
ProFamtable p_famtab;
std::vector famtable_instance;
ProMdl p_model, p_insMdl;
err = ProMdlCurrentGet(&mdl);
err = ProSelect("prt_or_asm", 1, NULL, NULL, NULL, NULL, &p_sel, &n_sel);
if (err != PRO_TK_NO_ERROR || n_sel < 1) return;
err = ProMdlLoad(_T("E:\\mll_a-48.prt"), PRO_MDL_PART, PRO_B_FALSE, &p_insMdl);
err = ProFamtableInit(p_insMdl, &p_famtab); // 初始化簇表
if (err != PRO_TK_NO_ERROR)
return;
err = ProFamtableInstanceVisit(&p_famtab, famtab_instance_visit_action, famtab_instance_filter_action, (ProAppData)&famtable_instance); // 簇表实例遍历
if (err != PRO_TK_NO_ERROR)
return;
for (int i = 0; i < famtable_instance.size(); i ++)
{
CString famNameStr = famtable_instance[i].name;
if (famNameStr == _T("46")) // 要替换的实例名称
{
err = ProFaminstanceCreate( &famtable_instance[i], &p_model );
if (err != PRO_TK_NO_ERROR) return;
err = ProFaminstanceMdlGet( &famtable_instance[i], &p_model );
if (err != PRO_TK_NO_ERROR) return;
}
}
err = ProSelectionAsmcomppathGet(p_sel[0], &path);
if (err != PRO_TK_NO_ERROR) return;
ProAsmcomppath father_path = path;
father_path.table_num--;
ProMdl father_mdl;
err = ProAsmcomppathMdlGet(&father_path,&father_mdl);
ProFeature del_feat;
del_feat.owner = father_mdl;
del_feat.id = path.comp_id_table[path.table_num-1];
del_feat.type = PRO_FEATURE;
err = ProArrayAlloc (0, sizeof(int), 1, (ProArray*)&ids);
if ( err != PRO_TK_NO_ERROR) return;
err = ProArrayObjectAdd((ProArray*)&ids, PRO_VALUE_UNUSED, 1, &(del_feat.id) );
if ( err != PRO_TK_NO_ERROR) return;
int p_size;
err = ProArraySizeGet(ids, &p_size);
if ( err != PRO_TK_NO_ERROR) return;
err = ProAssemblyAutointerchange((ProAssembly)father_mdl, ids, p_model);
if ( err != PRO_TK_NO_ERROR) return;
err = ProArrayFree((ProArray*)&ids);
if ( err != PRO_TK_NO_ERROR) return;
err = ProSolidRegenerate((ProSolid)mdl, PRO_REGEN_NO_FLAGS);
if ( err != PRO_TK_NO_ERROR) return;
}