Skip to main content
9-Granite
December 11, 2023
Solved

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

  • December 11, 2023
  • 4 replies
  • 3503 views

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.

Best answer by FV_01

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); });

 

4 replies

JonC_169-GraniteAuthor
9-Granite
December 11, 2023

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.

12-Amethyst
December 11, 2023

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

JonC_169-GraniteAuthor
9-Granite
December 12, 2023

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.

18-Opal
December 11, 2023

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

JonC_169-GraniteAuthor
9-Granite
December 12, 2023

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. 

17-Peridot
December 12, 2023

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

JonC_169-GraniteAuthor
9-Granite
December 13, 2023

HI, thanks for the info.

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

December 12, 2023
  • 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_169-GraniteAuthor
9-Granite
December 13, 2023

yes, it is an option.

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

December 14, 2023

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