Is there an alternative way to delete file other than Promdldelete() api in toolkit?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
Solved! Go to Solution.
- Labels:
-
ProToolkit
-
Toolkit
- Tags:
- howto
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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); });
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
You must check the origin of the model before deleting. This must match with your current working dir.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
HI, thanks for the info.
i didn't know i can do that with a drawing like that, will try later, thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
yes, it is an option.
just wonder if i can delete the outdated drawing file directly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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(...)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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); });
