Skip to main content
3-Newcomer
March 4, 2024
Solved

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

  • March 4, 2024
  • 2 replies
  • 1816 views

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!

 

 

Best answer by msteffke

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..)

2 replies

msteffke15-MoonstoneAnswer
15-Moonstone
March 4, 2024

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..)
3-Newcomer
March 6, 2024

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

18-Opal
March 24, 2024

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.