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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

ProRule Object to retrieve models by an expresion

sergio72
1-Newbie

ProRule Object to retrieve models by an expresion

Hello everyone, i'm using the ProRule object to retrieve all components
from an assembly wich has a parameter set to a particular value wich i'm
loking. This is the code that i used:




ProRule rule;
ProAsmcomppath* p_comp_list;
int p_list_size;
ProLine line;
ProExpression proexpr;

err=ProArrayAlloc(0,sizeof(ProLine),1,(ProArray*)&proexpr);
err=ProMessageStringRead( PRO_LINE_SIZE, line );
err=ProArrayObjectAdd( (ProArray*)&proexpr,0, 1,line);
err=ProRuleInitExpr(proexpr,&rule);
err=ProRuleEval ((ProSolid)this
->aMdl,&rule,&p_comp_list,&p_list_size);




When i execute the code ProE shows an input window for write the
expresion that i want, thats right, i write the following expresion: TEST
== "MyTest" where TEST it's a parameter that it's in all models wich are
hanging from my top level assembly (this->aMdl variable in code shown
before) some models have the TEST parameter empty and others are filled
with "MyTest" value (10 models exactly).
Well the expected result of ProRuleEval execution would be a
component list with exactly 10 items, one for each model that has TEST
parameter equal to "MyTest". But the real result it's zero!!! it looks
like ProRuleEval doesn't find models that can satisfy the expresion
despite off i knowns that there are 10 models that have exactly the value
wich i'm looking for. I have tried to do it manually using ProE interface
and simplified representations. I write the same expresion as used in code
sample inside my simplified representation rule and when i execute it give
to me exactly 10 components, as expected, so im sure that the expresion
it's not the problem. So the problem must be in the code, but where? What
i am doing wrong? I hope someone can help me, im really confused.

Thanks in advance.




This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
2 REPLIES 2

Sergio,
I looked up the example of how to do this in the API Wizard which I have included below. The only difference I see between your code and the example code is that you use a 0 instead of PRO_VALUE_UNUSED in your call to ProArrayObjectAdd but that shouldn't make a difference. I would step through your code with the debugger to make sure that your array is populated correctly and that the assembly pointer (ProMdl) is valid. Also I would analyze the contents of the ProRule object before executing the ProRuleEval call. Make sure all data fields are filled in properly. It's a DHandle (struct) so that should be easy enough to do. Otherwise I would focus on the expression itself. I have not ever done an expression search so I cannot comment on the syntax.

/*---------------------------------------------------------------------*\

Hello Williams, thanks a lot for your quick answer. I have check all you
told me, as result i have modified my code as above:


err=ProMdlCurrentGet(&mdl); /*To be sure that its getting the
displayed assembly*/
err=ProMdlNameGet(mdl,mdlName); /*just for debug mdl name*/
err=ProArrayAlloc(0,sizeof(ProLine),1,(ProArray*)&proexpr);
err=ProMessageStringRead( PRO_LINE_SIZE, line );
err=ProArrayObjectAdd( (ProArray*)&proexpr,PRO_VALUE_UNUSED, 1
,line); /*replaced 0 by this macro as shown in API help sample*/
err=ProRuleInitExpr(proexpr,&rule);
err=ProRuleEval((ProSolid)mdl,&rule,&p_comp_list,&p_list_size);

The problem is still there, nothing has change and still give me nothing,
0 components that satisfies the expresion. If you look in the Toolkit's
help they show how the expresion syntaxis must be:
Top Tags