XCAD.NET
XCAD.NET
Framework for .NET (C# and VB.NET) to create modern application for CAD systems (SOLIDWORKS)
Get technical support Access source code Explore code and application examples

Managing SOLIDWORKS documents life cycle via xCAD framework


xCAD frameworks provides utility class to manage document life cycle by creating a specified instance handler as a wrapper of a model.

Call IXDocumentCollection::RegisterHandler method and pass the type of document handler as a generic argument. Handle common events (e.g. saving, selection, rebuilding, 3rd party storage access) or specific event within the handler implementation.

public override void OnConnect()
{
    this.Application.Documents.RegisterHandler<MyDocHandler>();
}

Define the document handler either by implementing the IDocumentHandler interface or SwDocumentHandler class.

public class MyDocHandler : SwDocumentHandler
{
    protected override void AttachPartEvents(PartDoc part)
    {
        part.AddItemNotify += OnAddItemNotify;
    }

    protected override void DetachPartEvents(PartDoc part)
    {
        part.AddItemNotify -= OnAddItemNotify;
    }

    private int OnAddItemNotify(int EntityType, string itemName)
    {
        //Implement
        return 0;
    }
}

Override methods of document handler and implement required functionality attached for each specific SOLIDWORKS model (such as handle events, load, write data etc.)

Framework will automatically dispose the handler. Unsubscribe from the custom events within the Dispose method. The pointer to the document attached to the handler is assigned to Model property of SwDocumentHandler.

Refer Events Handler Example which demonstrates how to subscribe to native SOLIDWORKS events.


Powered by Docify