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

How to check part exist already in session/ or disk using Creo Toolkit?

AG_10775338
3-Newcomer

How to check part exist already in session/ or disk using Creo Toolkit?

Hi, I'm new to Toolkit development, I'm using Creo Parametric 8
I'm developing a feature where to check Solid part with certain name say "X" already in an assembly if not I'm creating new part with API ProAsmcompMdlnameCreateCopy().
Problem is whenever there is part of with same name "X"(which is not assembled) in session or Current working directory it throws me an error PRO_TK_GENERAL_ERROR (-1).

I explored found API ProSessionMdlList() to get all model in session. This may be partially solves the problem.

Using loop I can avoid creating new part.

But I don't know how to check in Current working directory or any other specified location.

Please help me out.
If there is any better way for this problem, I highly appreciate it. 

Thanks, in advance!

 

 

ACCEPTED SOLUTION

Accepted Solutions
msteffke
14-Alexandrite
(To:AG_10775338)

The function ProFilesList will list files in a directory.  Heres a sample how I called it. 

 

  err = ProArrayAlloc(0, sizeof(ProPath), 1, (ProArray*)&file_list);
           err = ProArrayAlloc(0, sizeof(ProPath), 1, (ProArray*)&dir_list);
           strcpy(mystr, "*.prt,*.asm,*.lay");
           ProStringToWstring(w_line, mystr);
       err = ProFilesList(wname, w_line, PRO_FILE_LIST_ALL,  &file_list, &dir_list);
 
Or... you could just use the fact that your're getting a -1 as a return value, that could be your existence test.  (Its not documented that's what causes a general error, but seems to be what triggers that return.  its a reach but..)

View solution in original post

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

The function ProFilesList will list files in a directory.  Heres a sample how I called it. 

 

  err = ProArrayAlloc(0, sizeof(ProPath), 1, (ProArray*)&file_list);
           err = ProArrayAlloc(0, sizeof(ProPath), 1, (ProArray*)&dir_list);
           strcpy(mystr, "*.prt,*.asm,*.lay");
           ProStringToWstring(w_line, mystr);
       err = ProFilesList(wname, w_line, PRO_FILE_LIST_ALL,  &file_list, &dir_list);
 
Or... you could just use the fact that your're getting a -1 as a return value, that could be your existence test.  (Its not documented that's what causes a general error, but seems to be what triggers that return.  its a reach but..)

@msteffke thanks for your answer, you are right Error returned in turn a check.

RPN
17-Peridot
17-Peridot
(To:AG_10775338)

extern

ProError

ProMdlnameInit ( ProMdlName name, ProMdlfileType type,ProMdl *p_mdl_handle);

 

Just Check for

PRO_TK_E_NOT_FOUND - Unable to find the required model.

Announcements


Top Tags