cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Replace assy comp with other fam tab instance

Highlighted
Newbie

Replace assy comp with other fam tab instance

Does anyone have example code of how to replace a component by in an
assembly another instance? (Edit-->Replace-->Replace By *Family Table)

Any help would be appreciated.
1 REPLY 1

Re: Replace assy comp with other fam tab instance

#include <protoolkit.h>
#include <promenu.h>
#include <promessage.h>
#include <promdl.h>
#include <promodelitem.h>
#include <profamtable.h>
#include <profaminstance.h>
#include <proparameter.h>
#include <proselection.h>
#include <profeature.h>
#include <profeattype.h>
#include <proutil.h>
#include <prosolid.h>
#include <progtol.h>
#include <prowindows.h>
#include <pd_prototype.h>
#include <proasmcomp.h>

#include "TestFamTab.h"
#include "TestError.h"
#include "UtilFiles.h"
#include "UtilMessage.h"
#include "UtilString.h"
#include "UtilMenu.h"
#include "UtilCollect.h"


#include <testmenu.h>

FILE *fp;


int ComponentReplace ()
{
ProError status;
ProFileName msgfile;
ProMdl asm_mdl, genMdl, inst_mdl;
ProSelection *sel;
int num_sel, num_inst_sel;
ProModelitem *p_mdl_item;
ProFamtable *p_famTable;
ProFaminstanceList p_inst_list;
int *replace_id_list;


fp = fopen("comp_replace.txt", "w");
ProStringToWstring (msgfile, "messages.txt");


p_mdl_item = (ProModelitem *) malloc( sizeof( ProModelitem ) );

status = ProMdlCurrentGet(&asm_mdl);
fprintf(fp,"ProMdlCurrentGet status is %d\n", status);

status = ProSelect("part", 1, NULL, NULL, NULL, NULL, &sel, &num_sel);
fprintf(fp,"ProSelect status is %d\n", status);
//fprintf(fp, "The id of the selected component is %d\n", sel[0]->selected_id);

status = ProSelectionModelitemGet(sel[0], p_mdl_item);
fprintf(fp,"ProSelectionModelitemGet status is %d\n", status);
fprintf(fp, "The id of the selected component is %d\n", p_mdl_item->id);

status = ProFaminstanceGenericGet( p_mdl_item->owner, 1, &genMdl );
/* if ( status == PRO_TK_NO_ERROR )
// This model is an instance of a family table
{
fprintf(fp,"This model is an instance of a family table\n");
//genStatus = OTIS_INSTANCE;
}
else if ( status == PRO_TK_E_NOT_FOUND )
*/
if ( status == PRO_TK_NO_ERROR || status == PRO_TK_E_NOT_FOUND)
{
//genMdl=p_mdl_item->owner;

p_famTable = (ProFamtable *) malloc( sizeof( ProFamtable ) );
status = ProFamtableInit( genMdl, p_famTable );
status = ProFamtableCheck( p_famTable );
//if ( status == PRO_TK_NO_ERROR )
/* There is a family table, and it's not empty */
//{
fprintf(fp,"There is a family table, and it's not empty\n");

status = ProArrayAlloc( 0, sizeof(ProFaminstance), 1, (ProArray*)(&p_inst_list) );

status = ProFaminstanceSelect(p_famTable, FALSE, &num_inst_sel, &p_inst_list);
fprintf(fp,"ProFaminstanceSelect status is %d\n", status);
if (status!=PRO_TK_NO_ERROR)
return(status);

ProFaminstanceRetrieve(&(p_inst_list[0]), &inst_mdl);
fprintf(fp,"ProFaminstanceRetrieve status is %d\n", status);
if (status!=PRO_TK_NO_ERROR)
return(status);

replace_id_list = (int *) malloc( sizeof( int ) );
replace_id_list[0]=10;

prodb_auto_interchange((Prohandle)asm_mdl, 1, replace_id_list, (Prohandle)inst_mdl);
ProMessageDisplay(msgfile, "USER %0s", "Component replaced successfully");
//fprintf(fp,"Component replaced successfully\n", status);
/*

//genStatus = OTIS_GEN_W_FAMTAB;
//}
else
// Either there's no family table, or it's empty
{
fprintf(fp,"Either there's no family table, or it's empty\n");
//genStatus = OTIS_GEN_WO_FAMTAB;
}
*/
free( (void *) p_famTable );
}
else
{
return( PRO_TK_GENERAL_ERROR );
}


fclose(fp);
return (0);
}


int user_initialize()
{
ProMenuFileRegister ("assembly", "assembly.mnu", NULL);
ProMenuAuxfileRegister ("assembly", "Replace.aux", NULL);
ProMenubuttonActionSet ("assembly", "Comp Replace", (ProMenubuttonAction)ComponentReplace, NULL, 0);
return (0);
}

void user_terminate()
{
}