@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(); CommandManager.AddCommandGroup ().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