Of course!
In general the Add-In opens a WPF dialog when saving a file, e.g. an IPT or IAM file and writes back into custom iProperties.
I'm attaching event handlers to the following events:
- ApplicationEvents.OnActivateDocument
- ApplicationEvents.OnSaveDocument
I already tried to comment these lines so only a config file gets read in the "Activate" method of the Add-In - but no success.
Plus in debug all code in the "Activate" method is executed without exceptions.
Here's the code of the "Activate" method:
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
{
try
{
AppSettings.Log.Info($"Loading AddIn... (Assembly={this.GetType().Assembly})");
// Read reg keys
// >>
AppSettings.ServerPath = RegHandler.GetConfigPathFromReg();
if (string.IsNullOrWhiteSpace(AppSettings.ServerPath))
throw new Exception(@"Add-In could not be loaded. ServerPath is missing in Windows Registry");
AppSettings.Log.Info($"ServerPath={AppSettings.ServerPath}");
AppSettings.AssemblyFolder = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
AppSettings.Log.Info($"AssemblyFolder={AppSettings.AssemblyFolder}");
AppSettings.Log.Info($"LayoutFolder={AppSettings.LayoutDir}");
AppSettings.ConfigFileName = System.IO.Path.Combine(AppSettings.ServerPath, AppSettings.ConfigFile);
AppSettings.DbConfigFileName = System.IO.Path.Combine(AppSettings.ServerPath, AppSettings.DbConfigFile);
AppSettings.UserConfigFileName = System.IO.Path.Combine(AppSettings.ServerPath, AppSettings.UserConfigFile);
AppSettings.Log.Info($"ConfigFileName={AppSettings.ConfigFileName}");
AppSettings.Log.Info($"DbConfigFileName={AppSettings.DbConfigFileName}");
AppSettings.Log.Info($"UserConfigFileName={AppSettings.UserConfigFileName}");
if (!Directory.Exists(AppSettings.LayoutDir))
Directory.CreateDirectory(AppSettings.LayoutDir);
if (!System.IO.File.Exists(AppSettings.ConfigFileName))
throw new Exception($"File not found: {AppSettings.ConfigFileName}");
if (!System.IO.File.Exists(AppSettings.DbConfigFileName))
throw new Exception($"File not found: {AppSettings.DbConfigFileName}");
if (!System.IO.File.Exists(AppSettings.UserConfigFileName))
throw new Exception($"File not found: {AppSettings.UserConfigFileName}");
// <<
// Read config files
// >>
PropertyDialog.LoadConfig(AppSettings.ConfigFileName);
PropertyDialog.LoadDbConfig(AppSettings.DbConfigFileName);
PropertyDialog.GetAllowedUsers();
// <<
m_inventorApplication = addInSiteObject.Application;
m_inventorApplication.ApplicationEvents.OnActivateDocument += ApplicationEvents_OnActivateDocument;
m_inventorApplication.ApplicationEvents.OnSaveDocument += OnSaving;
AppSettings.Log.Debug($"Event handlers attached");
AppSettings.Log.Info("AddIn activated");
}
catch (Exception ex)
{
AppSettings.Log.Error(ex.Message);
if (ex.InnerException != null)
AppSettings.Log.Error(ex.InnerException.Message);
}
}
This is a snippet of the VS project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<ProjectType>Local</ProjectType>
<ApplicationIcon>favicon.ico</ApplicationIcon>
<AssemblyKeyContainerName>
</AssemblyKeyContainerName>
<AssemblyOriginatorKeyFile>addinname.pfx</AssemblyOriginatorKeyFile>
<DefaultClientScript>JScript</DefaultClientScript>
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
<DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign>
<OutputType>Library</OutputType>
<RootNamespace>InvAddIn</RootNamespace>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<StartupObject>
</StartupObject>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<Configurations>Debug_23;Debug_24;Debug_26;Debug;Release_23;Release</Configurations>
<AssemblyName>addinname</AssemblyName>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<!-- ... -->
</Project>
These are the references I use for the Add-In:

I don't understand why there is popping up an empty dialog when the Add-In only is loaded and I try to open a file even if I don't attach the event handlers.
Plus the "" event handler doesn't do anything regarding dialogs:
private void ApplicationEvents_OnActivateDocument(_Document DocumentObject, EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode)
{
HandlingCode = HandlingCodeEnum.kEventNotHandled;
if (BeforeOrAfter == EventTimingEnum.kAfter)
{
AppSettings.Log.Info($"ApplicationEvents_OnActivateDocument() DisplayName={DocumentObject.DisplayName}, FileName={DocumentObject.FullFileName}");
m_openedDoc = DocumentObject;
Savecounter = 0; // reset save counter
HandlingCode = HandlingCodeEnum.kEventHandled;
}
}
Any help is much appreciated.