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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Changing parameters value in a loop

sivag75
1-Newbie

Changing parameters value in a loop

Hi,

I am very new to pro/toolkit development.

I have a set of parameters list with its new value defined in a txt file.
I read the txt file and store the parameters in a structure array (dataConfig) varaible.
Now, I want to iterate through the structure and change the parameter value to the new value.
The value of the last parameter comes in the iteration is only getting changed.
Can some one guide me on this.


My code:

//Main function

for (i=0; i<cfgcnt; i++)<br="/>{
err = ChangeParameter (dataConfig[i].paramName, dataConfig[i].newValue);
}


ProError ChangeParameter (char name[100], char value[100])
{
ProName tBuf[100];
ProMdl p_model;
ProModelitem p_mdl_item;
ProError err;
ProParameter param;
ProParamvalue param_value;
ProError status;

ProMdlCurrentGet (&p_model);
ProMdlToModelitem(p_model, &p_mdl_item);

ProStringToWstring (tBuf, name);
status = ProParameterInit(&p_mdl_item, tBuf, ¶m);
if (status == PRO_TK_NO_ERROR)
{
ProStringToWstring (tBuf, value);
ProParamvalueSet (¶m_value, tBuf, PRO_PARAM_STRING);
status= ProParameterValueSet(¶m, ¶m_value);
}
return (status);
}

Thanks
Siva


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.
5 REPLIES 5

check the value of paramName in each item


Hi,

Yes, I found the parameters name and values are correct.

Also, if I pass the arguments by values, the parameters are getting updated correctly.

ex: ChangeParameter ("param1", "value1");

When I pass the arguments by variables, the last one only is getting updated.

Any help ?

Siva

Hi,

I have uploaded my source code part and the config file. Please have a look on to this and let me know what I am missing here to do.

Thanks

Siva

Hi,

Sorry. forgot to mention the configuration structure:

typedef struct dcfg
{
char paramName[100];
char newValue[100];
} DSMDataConfig;


DSMDataConfig *dataConfig;

int cfgCnt=0;

Thanks

Siva

error at line 38:

dataConfig = realloc(dataConfig, sizeof(DSMDataConfig) * (cfgCnt+1));

you re-allocate new memory for dataConfig in every while loop, so only the last loop take effect, all others is cleared.

use <vector> or something others to expand your dataConfig

Top Tags