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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Toolkit Programming for relations

Sss4598
12-Amethyst

Toolkit Programming for relations

Hello,

 

 

 

I am trying to write a C++ code into Creotoolkit  to import relations from .txt format file and then regenerate the model. Can anybody guide me how can this be achieved?

 

 

TIA

ACCEPTED SOLUTION

Accepted Solutions

Depending on what you need you might be able to use ProInputFileRead with the PRO_RELATION_FILE option. The relations.txt file would be in the working directory, but you can give a full path or most of the toolkit API's support using $ENVIRONMENT_VARIABLE.

 
//Use append_relations = 1 to append the relations and != 1 (ex: append_relations = 0) to replace the existing relations.
int append_relations = 1;
status = ProInputFileRead(mdl, L"relations.txt", PRO_RELATION_FILE, NULL, NULL, &append_relations, NULL);
status = ProSolidRegenerate((ProSolid)mdl, PRO_REGEN_NO_FLAGS);

 

If that doesn't meet your needs (example: needing to edit the post regeneration relations), you can read the text file line by line using something like wifstream to read each line from the text file and put it into an array of text lines. Then you can use ProArrayObjectAdd and ProRelsetRelationsSet like the example code from @msteffke.

View solution in original post

3 REPLIES 3
msteffke
14-Alexandrite
(To:Sss4598)

Below is a chunk of code Ive done a few years ago.   I was adding a line to the end of the relations of parts.  Looking at the code here its not too difficult.   Creo treats relations as an array of text lines.  Its been a while since Ive worked with relations, but this worked for me in Creo 7. 

 

 
ProMdlToModelitem(mdl, &modelitem);
 
 
status = ProArrayAlloc(0, sizeof(ProWstring), 1, (ProArray*)&w_array);
 
status = ProModelitemToRelset(&modelitem, &relset);
 
if (status == PRO_TK_NO_ERROR)
{
status = ProRelsetRelationsGet(&relset, &w_array);
}
else
{
status = ProRelsetCreate(&modelitem, &relset);
}
w_ptr = w_line;    //  My text string
status = ProArrayObjectAdd((ProArray*)&w_array, PRO_VALUE_UNUSED, 1,
&w_ptr);
status = ProArraySizeGet((ProArray)w_array, &n_lines);
status = ProRelsetRelationsSet(&relset, w_array, n_lines);
if (status == PRO_TK_NO_ERROR)
//ProUtilMsgPrint((char*)"gen", (char*)"TEST %0s", (char*)"Relation added successfully");
 
status = ProArrayFree((ProArray*)&w_array);
sprintf(Message, "%s   %s", PartName, RelLine);
ProMessageDisplay(msgfile, "USER %0s", Message);
}
 
 

 

Depending on what you need you might be able to use ProInputFileRead with the PRO_RELATION_FILE option. The relations.txt file would be in the working directory, but you can give a full path or most of the toolkit API's support using $ENVIRONMENT_VARIABLE.

 
//Use append_relations = 1 to append the relations and != 1 (ex: append_relations = 0) to replace the existing relations.
int append_relations = 1;
status = ProInputFileRead(mdl, L"relations.txt", PRO_RELATION_FILE, NULL, NULL, &append_relations, NULL);
status = ProSolidRegenerate((ProSolid)mdl, PRO_REGEN_NO_FLAGS);

 

If that doesn't meet your needs (example: needing to edit the post regeneration relations), you can read the text file line by line using something like wifstream to read each line from the text file and put it into an array of text lines. Then you can use ProArrayObjectAdd and ProRelsetRelationsSet like the example code from @msteffke.

Hi @ss_10739479,


I wanted to see if you got the help you needed.


If so, please mark the appropriate reply as the Accepted Solution. It will help other members who may have the same question.
Please note that industry experts also review the replies and may eventually accept one of them as solution on your behalf.
Of course, if you have more to share on your issue, please pursue the conversation.

Thanks,

Catalina
PTC Community Moderator
Announcements


Top Tags