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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Is there an alternative way to delete file other than Promdldelete() api in toolkit?

JonC_16
7-Bedrock

Is there an alternative way to delete file other than Promdldelete() api in toolkit?

I’m trying to use toolkit to delete .drw files under working directory. There is a situation when the model mounted to the drawing is missing, I can’t manage to delete the drw file with promdlnameretrieve() and Promdldelete(). Does anyone know any other method to delete a file from disk in toolkit, many thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
FV
17-Peridot
17-Peridot
(To:JonC_16)

either use pro/toolkit function to get a ProArray of all files in a directory and extract entries matching name and/or extension from ProArray

ProFilesList(...)

 or use  

#include <filesystem>
std::filesystem::directory_iterator

something like this (verify spelling and function names with cpp reference):

std::filesystem::path p{"directory_in_question"};
std::wstring base_name{"drawing_name_in_question"};
std::vector<std::filesystem::path> delete_me;
for (auto const& dir_entry : std::filesystem::directory_iterator{p}){ 
    if( dir_entry.path().stem().extension().wstring().find(L"drw") == std::wstring::npos){
    continue;
   }
   if( dir_entry.path().stem().stem().wstring() != base_name)
      continue;
    delete_me.push_back(dir_entry.path()); 
    // or std::filesystem::remove( dir_entry.path())
}
std::for_each(delete_me.begin(), delete_me.end(),
 [](auto &p) { std::error_code ec; std::filesystem::remove(p, ec); });

 

View solution in original post

12 REPLIES 12
JonC_16
7-Bedrock
(To:JonC_16)

More details are: there is a C.drw drawing, the model mounted to the drawing is C.prt. For some reason the C.prt is missing, now I try to use toolkit to delete C.drw, it doesn’t work.

MikePhillips
6-Contributor
(To:JonC_16)

Is there a particular reason why the delete must be done with the toolkit API? Could you just use built in C functions to delete the file(s)? 

That would be my last option, also I’m not sure if it works for the version postfix , I think I will try it at last, before that I wonder if there is another option.

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

You must check the origin of the model before deleting. This must match with your current working dir. 

JonC_16
7-Bedrock
(To:RPN)

Yes, but it’s just the origin model is missing or renamed to another name, now I can’t load and display the drw file, so I’m trying to delete it. 

Ithink, you got an error in promdlnameretrieve(), because a model is not found.

You can open a drawing in simplified representation. I do not remember exactly type of the representation. In this representation all drawing views is only bounding rectangles. Linked model will not loaded in to session. But need to turn on old style representations (in config.pro).

HI, thanks for the info.

i didn't know i can do that with a drawing like that, will try later, thanks.

FV
17-Peridot
17-Peridot
(To:JonC_16)

  • you would need to write a function to detect 'missing models in a drawing' condition
  • the next step (if the condition is true) would be to create missing models as empty part/assembly in session and to retrieve a drawing (again)
  • after that you should be able to do whatever needs to be done with the drawing

HIH

JonC_16
7-Bedrock
(To:FV)

yes, it is an option.

just wonder if i can delete the outdated drawing file directly.

FV
17-Peridot
17-Peridot
(To:JonC_16)

Many people were suggesting using out of the box C or C++ functionality already...

Is there anything preventing using any of the following? 

std::remove(...)
std::filesystem::remove(...)
_wunlink(...)
_unlink(...)
DeleteFile(...)

 

JonC_16
7-Bedrock
(To:FV)

Hi, sir. I don’t know how to do with the version numbers, as in *.drw.3. I wouldn’t know the version number beforehand. Even I can have the path of the file, the path would end with.drw, not.3 or.5. Honestly I don’t know what to do here.

FV
17-Peridot
17-Peridot
(To:JonC_16)

either use pro/toolkit function to get a ProArray of all files in a directory and extract entries matching name and/or extension from ProArray

ProFilesList(...)

 or use  

#include <filesystem>
std::filesystem::directory_iterator

something like this (verify spelling and function names with cpp reference):

std::filesystem::path p{"directory_in_question"};
std::wstring base_name{"drawing_name_in_question"};
std::vector<std::filesystem::path> delete_me;
for (auto const& dir_entry : std::filesystem::directory_iterator{p}){ 
    if( dir_entry.path().stem().extension().wstring().find(L"drw") == std::wstring::npos){
    continue;
   }
   if( dir_entry.path().stem().stem().wstring() != base_name)
      continue;
    delete_me.push_back(dir_entry.path()); 
    // or std::filesystem::remove( dir_entry.path())
}
std::for_each(delete_me.begin(), delete_me.end(),
 [](auto &p) { std::error_code ec; std::filesystem::remove(p, ec); });

 

Top Tags