把jon_wu以前发给我的一个例子共享一下:
希望能解除你的疑惑
extern UFUNEXPORT int UF_KF_create_child_rule (
tag_t part_of_rule, /* <I> Part to create or modify rule in */
const char *name_chain, /* <I> Reference chain of instance here rule will be created or modified. If create then must be "Root:" or NULL. Child rules can only be created on the "Root:" */
const char *rule_name, /* <I> Name of rule. */
const char *child_class_name, /* <I> Class of instance */
int num_parameters, /* <I> number of parameters in the parameter_names array */
char **parameter_names, /* <I,len:num_parameters> num_parameters array of names of parameters specified by the user.*/
char **parameter_rules, /* <I,len:num_parameters> num_parameters array of rules for the parameters whose names are in "parameter_names" above. Each rule may or may not have a trailing
semicolon. */
char **generated_name /* <OF> name generated for the child object. Currently always returns NULL. */
);
part_of_rule - 当前part的tag <BR> name_chain - 总是“Root:”
rule_name - 要创建的child rule的名字
child_class_name - 类名,如ug_block <BR> num_parameters - 有多少个参数规则要输入,如3个
parameter_names - 那些参数名字要输入,如"length", "width", "height"
parameter_rules - 对应的参数规则或值,如“10”,“20”,“30”
generated_name - 没有使用
例:
tag_t part_of_rule = UF_ASSM_ask_work_part();
char *name_chain = "Root:";
char *rule_name = "myblock";
char *child_class_name = "ug_block";
int num_parameters = 3;
char **parameter_names = NULL;
char **parameter_rules = NULL;
char *generated_name = NULL;
int error = 0;
int i = 0;
parameter_names = (char **) UF_allocate_memroy( num_parameters * sizeof ( char * ), [$error )] parameter_rules = (char **) UF_allocate_memroy( num_parameters * sizeof ( char * ), [$error )] for ( i = 0; i < num_parameters; i++ )
{
parameter_names = (char *) UF_allocate_memroy( MAX_LINE_SIZE * sizeof ( char ), [$error )] parameter_rules = (char *) UF_allocate_memroy( MAX_LINE_SIZE * sizeof ( char ), [$error )]
}
strcpy( parameter_names[0], "length" );
strcpy( parameter_rules[0], "10" );
strcpy( parameter_names[1], "width" );
strcpy( parameter_rules[1], "20" );
strcpy( parameter_names[2], "height" );
strcpy( parameter_rules[2], "30" );
error = UF_KF_create_child_rule( part_of_rule, name_chain, rule_name, child_class_name,
num_parameters, parameter_names, parameter_rules, [$generated_name )]
UF_MODL_update();
/* free memory */
for (i=0; i< num_parameters; i++)
{
UF_free( parameter_names );
UF_free( parameter_rules );
}
UF_free( paramter_names );
UF_free( parameter_rules ); |