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

FamTab verify with TK

Level 1

FamTab verify with TK

Hi,

how can I verify a Family Table with WF2 Toolkit? Retrieve every instance and regenerate it?

Thanx,

Ralf
3 REPLIES 3

Re: FamTab verify with TK

is it solved?
if is, please tell me how to verify instance of family table

Highlighted

Re: FamTab verify with TK

Hi

 

you can go through all Instances and just regenerate them.

 

/*** STARTUP SNIPPLET ***/

ret = ProSolidFamtableCheck((ProSolid)mdl);
if (ret == PRO_TK_NO_ERROR) {
ret = ProFamtableInit(mdl, &p_famtab);
ret = ProFamtableInstanceVisit(&p_famtab, verifyFamilytableVisitAction, NULL, NULL);
}

/*** END STARTUP SNIPPLET *///

 

 

ProError verifyFamilytableVisitAction (ProFaminstance * p_instance, ProError status, ProAppData appData) {
err = ProFaminstanceCreate(p_instance, &instance_mdl);
err = ProSolidRegenerate((ProSolid)instance_mdl, PRO_REGEN_NO_FLAGS);
if (err == PRO_TK_REGEN_AGAIN) {
err = ProSolidRegenerate((ProSolid)instance_mdl, PRO_REGEN_NO_FLAGS);
}

}

 

So there are some functions / ideas to fasten it up, but this is the basic mechanism how it works for family tables with one level.

 

Br,

Eike

Re: FamTab verify with TK

The last replay to this topic is fine but here  I found in a old e-mail what I sent  to Toolkit user in the past and may be the info could be helpful here:

I.)How to verify a family table', there is no direct function available in Pro/TOOLKIT to verify a family table. As a workaround, use the following procedure

1) Use ProFamtableInit() to get a handle to the family table

2) Use ProFamtableInstanceVisit() to visit each instance in the family table

For each instance:

3.) check if this is a verified instance by ProFaminstanceIsVerified()

4) if 3.) is true retrieve the instance ProFaminstanceRetrieve()

5) if 3.) is true Regenerate each instance using ProSolidRegenerate() 

6.Save the generic

===============================

 II.)  " "Is there a toolkit function to verify a familly table?"

Answer:

you have to retreive the instance ProFaminstanceRetrieve() and ProSolidRegenerate() using the FLAG PRO_REGEN_FORCE_REGEN (see example in notes)

 

example:
========
#include "ProToolkit.h"
#include "ProMenu.h"
#include "ProMenuBar.h"
#include "ProUtil.h"
#include "ProSolid.h"
#include <ProSimprep.h>
#include <ProFamtable.h>
#include <ProFaminstance.h>

/* Globals */

FILE *logfile;
ProError err_ray;


/* Prototypes */
void print( char* name);

/* macros */
#define ERR(api) { err_ray = api;if(err_ray != PRO_TK_NO_ERROR) {  \
	fprintf(logfile,"\n");\
	fprintf(logfile,#api " <> Error = %d  in File:<%s> Line <%d>)",\
	err_ray, __FILE__,__LINE__); fflush(logfile);return;}}


/*************************************************************************/

int tk_issue (ProAppData arg_1, int arg_2)
{
	toolkit_issue ();
	return(0);
}


int user_initialize()
{
	ProError err;
	uiCmdCmdId   cmd_id;

	logfile = fopen("log.txt", "w");
	fprintf(logfile, "Log started.");
	fprintf(logfile, "\n=============\n");
	fflush(logfile);

	err=ProCmdActionAdd("Toolkit_Issue", (uiCmdCmdActFn) tk_issue, uiProe2ndImmediate,
		NULL, PRO_B_TRUE, PRO_B_TRUE, &cmd_id);
	err=ProMenubarMenuAdd("Toolkit Menu", "Toolkit Menu", "Help", PRO_B_TRUE, L"message.txt");
	err=ProMenubarmenuPushbuttonAdd("Toolkit Menu", "Toolkit Button", "Toolkit Button", "Toolkit Button",
		NULL, PRO_B_TRUE, cmd_id, L"message.txt");


return (0);
}


void user_terminate()
{
	fprintf(logfile, "\n\n================================================\n");
	fprintf(logfile,   "Pro/TOOLKIT application terminated successfully.");
	fprintf(logfile, "\n================================================\n");

	fflush(logfile);
	fclose(logfile);
}


void print( char* name)
{
	fprintf(logfile, "\n%s", name);
	fflush(logfile);
}
void wprint(ProName wname )
{
	char name[256];
	print(ProWstringToString(name,wname));
}


/*************************************************************************/
/********   ISSUE RELATED Programming Code  bellow            ************/
/*************************************************************************/

void toolkit_issue ()
{
	ProError err,status;
	ProMdl model;
	ProMdlType mtype;
	ProSimprep simp_rep,simp_rep_new;
	ProSimprepType simp_type;
	ProSimprepdata *simp_data;
	char name[256];
	ProName wname;
	ProSimprepitem    *p_simprepitems;
	int size,i;
	ProMdl gen_model,active_model;

	ProFamtable famtab;
	int nb_instances=0, cpt_instances, idx;



    ProError FamTNotVerifIntancesFilter ( ProFaminstance *mdl_item, ProAppData app_data);

    ProError FamTInstanceAdd  ( ProFaminstance *mdl_item, ProError status, ProAppData app_data);

    ProError CptInstances  ( ProFaminstance *mdl_item, ProError status, ProAppData app_data);




/************************************************************************/



	ProMdlCurrentGet(&active_model);


    status = ProFaminstanceGenericGet ( active_model, PRO_B_TRUE, &gen_model);

    if (status!=PRO_TK_NO_ERROR)
    {
    gen_model=active_model;
    fprintf(logfile, "generic \n");

	}

	 status = ProSolidFamtableCheck ( gen_model );

     status = ProFamtableInit(gen_model,&famtab);

     status = ProFamtableInstanceVisit ( &famtab, (ProFamtableInstanceAction) CptInstances, (ProFamtableInstanceFilter) PRO_TK_NO_ERROR, &nb_instances);



return;
}




/************************************************************/
/************************************************************/


ProError FamTNotVerifIntancesFilter ( ProFaminstance *mdl_item, ProAppData app_data)

{

        ProError                                        status;

        ProFaminstanceVerifyStatus      verified_inst;


         fprintf(logfile, "verif \n");

        status = ProFaminstanceIsVerified ( mdl_item, &verified_inst );

        if (verified_inst==PRO_INST_NOT_VERIFIED && status==PRO_TK_NO_ERROR)

                return(PRO_TK_NO_ERROR);

        else

                return(PRO_TK_CONTINUE);

}




ProError CptInstances  ( ProFaminstance *mdl_item, ProError status, ProAppData app_data)

{

        ProError err;
        ProFaminstanceVerifyStatus      verified_inst;
        ProMdl          mdl_inst;

        int     *cpt=(int*)app_data;

        /*ProName lname;*/



        status = ProFaminstanceIsVerified ( mdl_item, &verified_inst );

        if (status!=PRO_TK_NO_ERROR) fprintf(logfile, " ERROR \n");

	    if (verified_inst==PRO_INST_NOT_VERIFIED)

	    {
       /* ProMdlNameGet(mdl_inst,lname);*/


       fprintf(logfile, "NOT verified \n %s",lname);

       ProFaminstanceRetrieve( mdl_item,&mdl_inst);


       /*ProSolidRegenerate(mdl_inst, PRO_REGEN_NO_FLAGS);*/
       ProSolidRegenerate(mdl_inst,  PRO_REGEN_FORCE_REGEN);




		 return(PRO_TK_NO_ERROR);
	    }

	    else
	    {

        fprintf(logfile, "Verified \n");
        /*return(PRO_TK_CONTINUE);*/
         return(PRO_TK_NO_ERROR);

	    }

        (*cpt)++;

        return(PRO_TK_NO_ERROR);
}

Further information related to the topic :

 

  1. Is there a function for verification of famtily tables inside Pro/E Toolkit or do you need to bring up every instance ?

 

  1. Is there a function for get a value from an existing instance parameter value, i.e  how to "read" in a family table and get  feedback of the actual value or if the value is inhereted from the generics value ?

 ==================================================================================

 

 1.)to verify family table instance follow this procedure 1)  Use ProFamtableInit() to get a handle to the family table 2) Use  ProFamtableInstanceVisit() to visit each instance in the family table 3) Retrieve each instance ProFaminstanceRetrieve() 4) Regenerate each

instance using ProSolidRegenerate()

 2.) To get and set a value of instance parameter use:the functions ProFaminstanceValueGet() and ProFaminstanceValueSet().These functions 

enable you to modify the values of family table items (columns). As input, these functions require the instance and the item handles, both of which are available via the visit functions.

Here again detailed information:

=========================

1.) Getting a handle for family table from a mdl handle

ProFamtableInit (  ProMdl model 

 /* (In)  The model handle.  */

 ProFamtable *p_famtab )

 /* (Out)  The handle to the family table. You must allocate the memory for this argument.  */

2.)ProFamtableCheck(ProFamtable *p_famtab)

Then use ProFamtableCheck() to determine whether the family table is empty (for a ProSolid, ProPart, or ProAssembly object, use

ProSolidFamtableCheck()).

3.)ProFamtableInstanceVisit()

Visits all the instances in a family table

 the function ProFamtableInstanceVisit() visits all the family's instances and calls the user-supplied functions of type ProFamtableInstanceAction()

and ProFamtableInstanceFilter().

 For the specified family table instance, the functions ProFaminstanceValueGet() and ProFaminstanceValueSet() enable you to modify the values

of family table items (columns). As input, these functions require the instance and the item handles, both of which are available via the visit

functions. Example 1: Writing a Family Table to a File uses the function ProFaminstanceValueGet() to write the contents of the visited family

table items to a file.Example 1 show also  how to use ProFamtableInstanceVisit() and ProFamtableItemVisit() to completely traverse a family

table and write its contents to a file. (see bellow )

 4.)ProFaminstanceRetrieve( ProFaminstance *p_inst 

 /* (In) The instance to retrieve. */

 ProMdl *pp_model )  /* (Out)  The handle to the instance model. You must allocate the space for this argument.

 Retrieves an instance of a model from disk

 5.)ProSolidRegenerate ( ProSolid p_handle 

 /* (In)  The ProSolid to regenerate. */

 PRO_B_TRUE )

 The function regenerate the faminstance. If this function returns PRO_TK_NO_ERROR then the instance is  verified OK.

 To get a solid handle cast the model handle  get by ProFaminstanceRetrieve() to ProSolid  example:

 err =ProSolidRegenerate ( (ProSolid) *pp_model,   PRO_B_TRUE );

======================================================

 

Example 2: Writing a Family Table to a File (I believe is from user guide)

 /*----------------------------------------------------------------*\
Application data
\*----------------------------------------------------------------*/
typedef struct userdata {
    FILE           *fp;        /* file pointer */
    ProFaminstance *fam_inst;  /* family table instance */
    ProFamtable     fam_table; /* family table */ 
} UserData;

/*================================================================*\
FUNCTION: UserFamtableInstAct()
PURPOSE:  Action function for ProFamtableInstanceVisit()
\*================================================================*/
ProError UserFamtableInstAct (
    ProFaminstance *instance,      /* In */
    ProError        filt_status,   /* In */
    ProAppData      appdata)       /* In */
{
    UserData     *data = (UserData *) appdata;
    int           status;
    ProCharName   inst_name;
    ProError      UserFamtableItemAct();
    ProFamtable  *p_table = &data->fam_table;
/*----------------------------------------------------------------*\
    Add the instance handle to the data.
\*----------------------------------------------------------------*/
    data->fam_inst = instance;
/*----------------------------------------------------------------*\
    Print the instance name in the family table file.
\*----------------------------------------------------------------*/
    ProWstringToString (inst_name, instance->name);
    fprintf (data->fp, "\nInstance name: %s\n", inst_name);
/*----------------------------------------------------------------*\
    Visit each family table item.
\*----------------------------------------------------------------*/
    status = ProFamtableCheck (p_table);
    status = ProFamtableItemVisit (p_table,
             (ProFamtableItemAction)UserFamtableItemAct, NULL, data);
    return (0);
}
/*================================================================*\
FUNCTION: UserFamtableItemAct()
PURPOSE:  Action function for ProFamtableItemVisit()
\*================================================================*/
ProError UserFamtableItemAct (
    ProFamtableItem  *fam_item,      /* In */
    ProError          filt_status,   /* In */
    ProAppData        appdata)       /* In */
{

    UserData     *data = (UserData *) appdata;
    ProCharName   item_name, string_val;
    char          str1[PRO_NAME_SIZE];
    int           status;
    ProParamvalue item_val;
    int           lock_status;
/*----------------------------------------------------------------*\
    Get the name of the current table item (column).
\*----------------------------------------------------------------*/
    ProWstringToString (item_name, fam_item->string);
/*----------------------------------------------------------------*\
    For the current instance, get the value of the current
    table item.
\*----------------------------------------------------------------*/
    status = ProFaminstanceValueGet (data->fam_inst, fam_item,
             &item_val);

    switch (item_val.type)
    {
        case PRO_PARAM_DOUBLE:
            sprintf (str1, "%lf", item_val.value.d_val);
            break;
        case PRO_PARAM_STRING:
            ProWstringToString (string_val, item_val.value.s_val);
            sprintf (str1, "%s", string_val);
            break;
        case PRO_PARAM_INTEGER:
            sprintf (str1, "%d", item_val.value.i_val);
            break;
        case PRO_PARAM_BOOLEAN:
            sprintf (str1, "%d", item_val.value.l_val);
            break;
        case PRO_PARAM_NOTE_ID:
            sprintf (str1, "%s", "PRO_PARAM_NOTE_ID");
            break;
        case PRO_PARAM_VOID:
            sprintf (str1, "%s", "PRO_PARAM_VOID");
            break;
        default:
            sprintf (str1, "%s", "No value.");
        break;
    }

    fprintf (data->fp, "\tItem : %s \tValue: %s\n", item_name, str1);
    return (0);
}

/*================================================================*\
FUNCTION: UserFamtable()
PURPOSE:  Example function using the family table functions
\*================================================================*/
ProError UserFamtable (ProMdl model)
{
    ProError       UserFamtableInstAct();
    ProFileName    msgfile, wfname;
    ProFamtable   *p_famtable;
    ProCharName    fname;
    int            status;
    UserData       UsrData;

    ProStringToWstring (msgfile, "testmsg.txt");
/*----------------------------------------------------------------*\
    Retrieve the model's family table and add it to the user data.
\*----------------------------------------------------------------*/
    status = ProFamtableInit (model, p_famtable);
    UsrData.fam_table = *p_famtable;
/*----------------------------------------------------------------*\
    Check the family table.
\*----------------------------------------------------------------*/
    status = ProFamtableCheck (p_famtable);
    if (status == PRO_TK_E_NOT_FOUND)
    {
        ProMessageDisplay (msgfile, "TEST %0s", "The family table
             does not exist.");
        return (PRO_TK_E_NOT_FOUND);
    }
/*----------------------------------------------------------------*\
    Open a file for the family table data.
\*----------------------------------------------------------------*/
    UsrData.fp = (FILE *) ProUtilGenFilePtr (model, ".ftb", fname,
         "w+");
    fprintf (UsrData.fp, "\nFamily table filename: %s\n",fname);
/*----------------------------------------------------------------*\
    Visit each instance in the family table.
\*----------------------------------------------------------------*/
    status = ProFamtableInstanceVisit (p_famtable,
             (ProFamtableInstanceAction)UserFamtableInstAct, NULL,
             (ProAppData)&UsrData);
/*----------------------------------------------------------------*\
    Close the family table file.
\*----------------------------------------------------------------*/
    fclose (UsrData.fp);
/*----------------------------------------------------------------*\
    Display the family table.
\*----------------------------------------------------------------*/
    ProStringToWstring (wfname, fname);
    status = ProInfoWindowDisplay (wfname, NULL, NULL);
    return (0);
}