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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Prevent save and save as not in working directory

tmaoz
4-Participant

Prevent save and save as not in working directory

Hello all,

I'm trying to write toolkit for preventing working outside the working directory.

I tried 2 function:

1.pfcDefaultSessionActionListener::OnBeforeModelSave(pfcDescriptorContainer_ptr Container):

but I can't get any relevant information for where the object will be save.

2.pfcDefaultModelActionListener::OnAfterModelSave(pfcModelDescriptor_ptr Container)

more relevant function but here when I check:

Container->GetPath(),Container->GetDevice() the information I receive is not the new path I set.

Is there any why to do it right?

Many thanks!

4 REPLIES 4
tmaoz
4-Participant
(To:tmaoz)

Just correcting the names of the functions:

1. pfcDefaultSessionActionListener:: onBeforeModelSave(pfcDescriptorContainer_ptr Container)

2. pfcDefaultModelActionListener:: onAfterModelSave(pfcModelDescriptor_ptr Container)

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

Hi all,

tmaoz,

OnBeforeModelSave will not tell you the user-intended target directory, this is not what this method does...

Your best bet is OnAfterModelSave ( OnAfterModelSaveAll). This method will give you a model descriptor of the saved model and therefore the target directory, after this is up to you how to enforce your policies...

To get a full name from a model descriptor I would use something like this:

pfcModel_ptr model_ptr = session->GetModelFromDescr(pfc_mdl_descr); 
xstring fpath = model_ptr->GetOrigin();

 

tmaoz
4-Participant
(To:FV)

But when I use the function:

 

xstring fpath = model_ptr->GetOrigin();

fpath equal to the model that I'm saving and not the new direction I chose.

 

Thanks. 

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

Hello all,

tmaoz,

This is correct, the return value will be the full file system path of the model currently in session.

The information from model descriptor :

auto drive_name = pfc_mdl_descr->GetDevice();
auto extension = pfc_mdl_descr->GetExtension();
auto file_name_with_extension_no_index = pfc_mdl_descr->GetFileName();
auto file_name_no_extension_no_index = pfc_mdl_descr->GetFullName();
auto directory_path_no_drive = pfc_mdl_descr->GetPath(); auto generic_name = pfc_mdl_descr->GetGenericName(); auto host = pfc_mdl_descr->GetHost(); auto instance_name_no_extension = pfc_mdl_descr->GetInstanceName();

Thinking more about your question - I don't believe Pro/E UI for 'Save' command have an option to prompt an end user for the destination directory. 'Save Backup' UI command indeed prompts an end user for the destination directory. There are config.pro options which would allow to store a model in session to the working directory via 'Save' command but I'm assuming you had taken care of config.pro options already.

It looks like you would need to write a couple of listeners:

  • command bracket listener to watch for 'Save Backup' command.
  • OnBeforModelSave - this will be called for the active model. From the active model you could extract the source file path...
  • OnAfterModelSave - from a model descriptor you'd get a destination path, compare it to the acquired source path - if there was a difference then do something...

HIH.

FV.

 

 

Announcements


Top Tags