OnFileDirty event

OnFileDirty event

rthelkap
Enthusiast Enthusiast
441 Views
2 Replies
Message 1 of 3

OnFileDirty event

rthelkap
Enthusiast
Enthusiast

Hello,

 

Some files () should not be modified by user explicitly. To handle this in the addin we have handled FileAccessEvents.OnFileDirty  event and in this we show an error message to the user that the file can not be modifie.

 

However the problem is this event is firing for all the other reasons like references change whereas we only want to handle the event when user explicitly performs some action (modify geometry) 

 

We have tried the below code and that does not seem to work. Any suggestions?

 

STDMETHODIMP CInventorEvents::OnFileDirty(BSTR RelativeFileName,BSTR LibraryName,SAFEARRAY * * CustomLogicalName,BSTR FullFileName,struct Document * DocumentObject,enum EventTimingEnum BeforeOrAfter,struct NameValueMap * Context,enum HandlingCodeEnum * HandlingCode)
{
	_bstr_t bstrFullFileName = DocumentObject->FullFileName; 
	/*public enum CommandTypesEnum
    {
        kShapeEditCmdType = 1,
        kQueryOnlyCmdType = 2,
        kFileOperationsCmdType = 4,
        kFilePropertyEditCmdType = 8,
        kUpdateWithReferencesCmdType = 16,
        kNonShapeEditCmdType = 32,
        kEditMaskCmdType = 57,
        kReferencesChangeCmdType = 64,
        kSchemaChangeCmdType = 128,
    }*/

	_variant_t val = Context->GetItem(_variant_t(L"ReasonsForChange"));
	logFile.Writeln(val.iVal);
	if(	((val.iVal & 16) == 16) || ((val.iVal & 64) == 64))
	{
		//"Reference change. Ignore";
		*HandlingCode = kEventNotHandled;
		return S_OK;
	}

	if( strFullFileName.IsEmpty() )
	{
		*HandlingCode = kEventNotHandled;
		return S_OK;
	}
	switch( BeforeOrAfter )
	{
	case kBefore:
		{
			// show  a message to the user that file can not be modified.
			*HandlingCode = kEventHandled;
		}
		break;
	case kAfter:
		break;
	}
	return S_OK;
}

Thank You,

Rakesh

 

0 Likes
442 Views
2 Replies
Replies (2)
Message 2 of 3

zadazLWJJ4
Enthusiast
Enthusiast

I am not sure if this resolved your case but could you instead use commandmanager and check which command is being run?

0 Likes
Message 3 of 3

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi Rakesh,

 

As per Inventor 2018 API documentation for OnFileDirty event, value of context gives reason why the event is fired. This is explained in the following.

 

"Input NameValueMap object that can be used to determine the context of why the event fired. Additional information is provided through this argument to help in understanding the context of the notification.

 

Name = "AffectedFiles". Value = An array of Strings that contains a list of full filenames of the files being dirtied. Typically this will contain a single filename, but in the case of referenced files, changing one document can also cause others to become dirty. For example, editing a part in the context of the assembly can cause other parts to reposition within other assemblies and in the case of adaptivity can cause parts to update. Each of these documents becomes dirty as a result of editing the single part. This list returns the filenames of the files affected. An OnFileDirty event notification is also made for each document as it is dirtied.

 

Name = "ReasonsForChange". Value = A value from the CommandTypesEnum list, which represents the different categories of changes that can be made. Typically this will be a single value from the list but it can represent multiple values that have been combined together so you need to use bitwise operations to check for a specific change.

 

Name = "Reason". Value = Returns "Update" or "FilesOpened" indicating the dirty reason. 

 

Name = "DirtyByRecompute". Value = A Boolean value indicates if the dirty is caused by recompute only."

 

For more reference, please go through the following link.

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-82104A63-2582-40D3-B29D-9BA9852A178F

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes