Using and SolidDNA in the same add-in

I would like to use both the and SolidDNA framework in an add-in that I writing in C#.

The questions are: can I do it? And, most importantly, should I do it?

Why would I would to do it?

From I like that @artem has created a lot of video tutorial that help a beginner like me to get started; I like that the framework handles the add-in registration; then I also appreciate the fact that it exposes the native SolidWorks API (even PDM and Document Manager) and there is no need to dispose the SolidWorks objects.

From SolidDNA I like that the code is well documented, there are the YouTube videos from Luke, and has some very powerful and yet simple method for most the operations I need.

I’m aware of this comparison: SW-API Custom-Frameworks: xCAD vs SolidDNA, but I would like the best of both world.

I started testing it and seems to work without issues but I just started and I’m not very knowledgeable in C#.

I created an add-in with xCAD, then I connect\disconnect SolidDNA in the OnConnect and OnDisconnect method:

using CADBooster.SolidDna;
using CodeWorksLibrary.Properties;
using SolidWorks.Interop.sldworks;
using System.ComponentModel;
using Xarial.XCad.Base.Attributes;
using Xarial.XCad.UI.Commands;
using Xarial.XCad.Extensions.Attributes;
using CodeWorksLibrary.Macros.Files;

namespace CodeWorksLibrary
    public class AddIn : Xarial.XCad.SolidWorks.SwAddInEx
        #region Enumeration
        /// <summary>
        /// Enumeration that contains the commands to be added to SolidWorks
        /// </summary>
        [Description("A collection of macros for SolidWorks")]
        public enum CwCommands_e
            [Title("Set author")]
            [Description("Write the component author in the custom properties")]
            [Icon(typeof(Resources), nameof(Resources.SetAuthor))]
            [Title("Export file")]
            [Description("Export the current file in different formats")]


        #region Public properties
        public static SldWorks swApp {  get; set; }


        /// <summary>
        /// Handle the connection to SolidWorks
        /// </summary>
        public override void OnConnect()
            AddInIntegration.ConnectToActiveSolidWorks(this.Application.Sw.RevisionNumber(), this.AddInId);

            CommandManager.AddCommandGroup<CwCommands_e>().CommandClick += OnCommandClick;

            swApp = (SldWorks)this.Application.Sw;

        public override void OnDisconnect()

        private void OnCommandClick(CwCommands_e spec)
            switch (spec)
                case CwCommands_e.SetAuthorE:
                case CwCommands_e.ExportFileE:

The use of xCAD allows to write a method like this:

/// <summary>
/// Set the value of a custom property
/// </summary>
/// <param name="swModel">The model object that needs the property to be changed</param>
/// <param name="propertyName">The name of the property to be changed</param>
/// <param name="prpValue">The value of the property to be changed</param>
public void SetCustomProperty(ModelDoc2 swModel, string propertyName, string prpValue)
    CustomPropertyManager swCustPrpMgr = swModel.Extension.get_CustomPropertyManager("");

    swCustPrpMgr.Add3(propertyName, (int)swCustomInfoType_e.swCustomInfoText, prpValue, (int)swCustomPropertyAddOption_e.swCustomPropertyReplaceValue);

and in the same project with SolidDNA:

/// <summary>
/// Save the active drawing as DWG in a sub-folder "\DWG\"  of GlobalConfig.ExportPath
/// </summary>
/// <param name="model">The Model object of the drawing</param>
public static void ExportDrawingAsDwg(Model model)
    // Check if the model is a drawing
    if (model?.IsDrawing != true)
        Application.ShowMessageBox("Export to PDF allowed only for drawings", SolidWorksMessageBoxIcon.Stop);


    // Get the full path for the export
    var path = ComposeOutFileName("DWG");

    // Check is the export full path is empty or null
    if (string.IsNullOrEmpty(path))
        Application.ShowMessageBox("The export path isn't valid", SolidWorksMessageBoxIcon.Stop);


    // Save new file
    var result = model.SaveAs(
        options: SaveAsOptions.Silent | SaveAsOptions.Copy | SaveAsOptions.UpdateInactiveViews,
        pdfExportData: null);

    if (!result.Successful)
        Application.ShowMessageBox("Failed to export drawing as PDF", SolidWorksMessageBoxIcon.Stop);

The code is available on Github.

Sorry for the lengthy post, and thanks in advance to whoever will respond.

Personally, I started with SolidDNA, which is very well suited to exclusive use with Solidworks.
Nevertheless, I often used UnsafeObjects.

I migrated my projects to Xcad mainly because I needed to have several addins running at the same time and at the time, before the intervention of Peter from CADbooster, this wasn’t possible.
I find Artem’s idea of making a “CAD-Agnostic” framework really interesting.
What’s more, he’s very active and provides lots of videos.
Finally, some of Xcad’s features are very interesting, such as the ability to communicate between an addin and a standalone application via COM interfaces.
The ability to switch between Solidworks and Document manager is also a real plus.
PropertyManagerPages are very easy to create.
I also think it’s the only framework that lets you make addins in .NET6.0 WPF.

Good luck!

Translated with DeepL Translate: The world's most accurate translator (free version)

1 Like