Listing the Members of an Assembly

This example recursively lists the components of an assembly and
writes the name of the solid for each component.

/*----------------------------------------------------------------*\
 Pro/TOOLKIT includes
\*----------------------------------------------------------------*/
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
/*----------------------------------------------------------------*\
 Application includes
\*----------------------------------------------------------------*/
#include 

/*----------------------------------------------------------------*\
 Global definitions
\*----------------------------------------------------------------*/
#define FILENAME "assembly.lst"
typedef struct user_appdata
{
 FILE *fp;
 int level;
} UserAppdata;
/*----------------------------------------------------------------*\
 Function prototypes
\*----------------------------------------------------------------*/
int UserAsmCompVisit(void *dummy, int dummy2);
ProError UserAsmCompFilter(ProFeature *feature,ProAppData app_data);
ProError user_action(ProFeature *feature,ProError status,
 ProAppData appdata);
/*---------------------------------------------------------------------*\
 Write the information to a file
\*---------------------------------------------------------------------*/
ProError user_action(
 ProFeature *feature,
 ProError status,
 ProAppData appdata)
{
 FILE *fp;
 int l,level;
 ProError err;
 ProMdl mdl;
 char name[PRO_NAME_SIZE];
 char type[PRO_TYPE_SIZE];
 wchar_t wname[PRO_NAME_SIZE];
 UserAppdata *appd,appd1;
 ProMdldata mdldata;
 appd = (UserAppdata *)appdata;
 fp = appd->fp;
 level = appd->level;
 err = ProAsmcompMdlGet(feature , &mdl);
 ERROR_CHECK( "user_action", "ProAsmcompMdlGet", err );
 err = ProMdlDataGet(mdl, &mdldata);
 ERROR_CHECK( "user_action", "ProModelitemNameGet", err );
 err = ProWstringToString(name,mdldata.name);
 err = ProWstringToString(type,mdldata.type);
 for(l=0;lfp;
 appd1.level = appd->level+1;

err = ProSolidFeatVisit(mdl, user_action, UserAsmCompFilter, &appd1);
 ERROR_CHECK( "user_action", "ProSolidFeatVisit", err );
 }
 if (feature != NULL) return(PRO_TK_NO_ERROR);
 return(PRO_TK_CONTINUE);
}
/*---------------------------------------------------------------------*\
 Function to write out the members of the current assembly, and
 display the result in an information window.
\*---------------------------------------------------------------------*/
int UserAsmCompVisit(void *dummy, int dummy2)
{
 char name[PRO_NAME_SIZE];
 char type[PRO_TYPE_SIZE];
 wchar_t wname[PRO_NAME_SIZE];
 ProMdldata mdldata;
 ProError err;
 UserAppdata appdata;
 FILE *fp;
 ProMdl p_asm;
 err = ProMdlCurrentGet(&p_asm);
 ERROR_CHECK( "UserAsmCompVisit", "ProMdlCurrentGet", err );
/*----------------------------------------------------------------*\
 Open the text file.
\*----------------------------------------------------------------*/
 strcpy(name,FILENAME);
 fp = PTApplsUnicodeFopen(name,"w");
 err = ProMdlDataGet(p_asm, &mdldata);
 ERROR_CHECK( "UserAsmCompVisit", "ProMdlDataGet", err );
 ProWstringToString(name, mdldata.name);
 ProWstringToString(type, mdldata.type);
 ProTKFprintf(fp, "%s%s\n",name,type);
 appdata.fp = fp;
 appdata.level = 1;
/*----------------------------------------------------------------*\
 List the assembly members.
\*----------------------------------------------------------------*/
 err = ProSolidFeatVisit(p_asm, user_action, UserAsmCompFilter,
 &appdata);
 ERROR_CHECK( "UserAsmCompVisit", "ProSolidFeatVisit", err );
/*----------------------------------------------------------------*\
 Close the file and display it.
\*----------------------------------------------------------------*/
 fclose(fp);
 ProStringToWstring(wname, FILENAME);
 err = ProInfoWindowDisplay(wname, NULL, NULL);
 ERROR_CHECK( "UserAsmCompVisit", "ProInfoWindowDisplay", err );
 return(PRO_TK_NO_ERROR);
}
/*================================================================*\

FUNCTION: UserAsmCompFilter()
PURPOSE: A filter used by ProSolidFeatVisit() to visit
 features that are assembly components
\*================================================================*/
ProError UserAsmCompFilter (
 ProFeature *feature,
 ProAppData app_data)
{
 ProError status;
 ProFeattype ftype;
/*----------------------------------------------------------------*\
 Get the feature type
\*----------------------------------------------------------------*/
 status = ProFeatureTypeGet (feature, &ftype);
/*----------------------------------------------------------------*\
 If the feature is an assembly component,
 return NO ERROR,
 else
 return CONTINUE
\*----------------------------------------------------------------*/
 if(ftype == PRO_FEAT_COMPONENT)
 return(PRO_TK_NO_ERROR);
 return(PRO_TK_CONTINUE);
}

你可能感兴趣的:(Listing the Members of an Assembly)