@AT - I do not understand how to invoke the document handler when a document is loaded. I have a bare bones add in with XCAD and have the following in my add in OnConnect():
public override void OnConnect()
{
Application.Documents.RegisterHandler<DocumentHandler>();
CommandManager.AddCommandGroup<CommandsA_e>().CommandClick += DoEFQuery;
base.OnConnect();
}My DocumentHandler class looks like this:
class DocumentHandler : SwDocumentHandler
{
private IXApplication m_App;
private IXDocument m_Model;
publicvoid Init(IXApplication app, IXDocument model)
{
m_App = app;
m_Model = model;
m_Model.StorageReadAvailable += OnStorageReadAvailable;
m_Model.StorageWriteAvailable += OnStorageWriteAvailable;
}
protected override void AttachPartEvents(PartDoc part)
{
}
protected override void DetachAssemblyEvents(AssemblyDoc assm)
{
}
private void HandleStorage(ISwDocument doc)
{
doc.StorageReadAvailable += OnStorageReadAvailable;
doc.StorageWriteAvailable += OnStorageWriteAvailable;
}
private void OnStorageWriteAvailable(IXDocument doc)
{
MessageBox.Show("Storage write available");
}
private void OnStorageReadAvailable(IXDocument doc)
{
MessageBox.Show("Storage read available");
}
}When I start debugging Solidworks loads and the addin is registered. When I open a document the document handler does not run. What am I missing?
**EDIT** - Using the debugging capability of XCAD I see the following errors when Solidworks starts up. I have added the exception and the line before the exception:
'SLDWORKS.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\\WINDOWS\\Microsoft.Net\\assembly\\GAC_MSIL\\System.Core\\v4.0_4.0.0.0__b77a5c561934e089\\System.Core.dll'. Symbols loaded.
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll...
'SLDWORKS.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\Xceed.Compression.v5.1.dll'. Module was built without symbols.
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll...
'SLDWORKS.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\\WINDOWS\\Microsoft.Net\\assembly\\GAC_MSIL\\System.Deployment\\v4.0_4.0.0.0__b03f5f7f11d50a3a\\System.Deployment.dll'. Symbols loaded.
Exception thrown: 'System.Deployment.Application.InvalidDeploymentException' in System.Deployment.dll
...
Then XCAD starts OK:
XCad.AddIn.SharplineAddIn: [Debug]Loading add-in
XCad.AddIn.SharplineAddIn: [Debug]Creating command group: 0
XCad.AddIn.SharplineAddIn: [Debug]Command ids changed: False
XCad.AddIn.SharplineAddIn: [Debug]Created command Output to robot language:0 for 0
XCad.AddIn.SharplineAddIn: [Debug]Command group-0 Id: No Toolbar
XCad.AddIn.SharplineAddIn: [Debug]Command-0 Id: 32761
XCad.AddIn.SharplineAddIn: [Debug]Creating command tab box
Then when I load a partDoc I get:
XCad.AddIn.SharplineAddIn: [Debug]Adding 'Part1.SLDPRT' to the dispatch queue
XCad.AddIn.SharplineAddIn: [Debug]Dispatching all (1) models
XCad.AddIn.SharplineAddIn: [Debug]Dispatched 'Part1.SLDPRT'
XCad.AddIn.SharplineAddIn: [Debug]Cleared models queue

Eric, DocumentHandler class must be public or just use an overload of RegisterHandler where you can provide the factory function to create an instance. This error will be captured into the log here: https://xcad.xarial.com/troubleshooting/
Hmmm...this just went over my head:
"just use an overload of RegisterHandler where you can provide the factory function to create an instance"
Do you have or can you point to an example?
I did change the DocumentHandler class to public but same result. When does DocumentHandler::Init get executed? I did add an event handler to a Solidworks part doc inside the DocumentHandler and see that it is getting executed. Sorry, I'm still learning :).