Efficiency Boosting Techniques
SolidDNA is a framework designed for developers to simplify the interaction with SOLIDWORKS APIs, making it easier to automate tasks, customise the user interface, and extend SOLIDWORKS capabilities. Here’s a step-by-step tutorial on how to get started with SolidDNA, along with a practical use case to illustrate its application.
Getting Started with SolidDNA
Step 1: Setting Up Your Environment
- Install SOLIDWORKS: Ensure you have SOLIDWORKS installed on your machine. SolidDNA is compatible with multiple versions, but it’s best to have the latest version for maximum compatibility.
- Visual Studio Setup: Download and install Visual Studio, if you haven’t already. The Community Edition is free and sufficient for SolidDNA development.
- NuGet Package: Open Visual Studio and create a new Class Library project in C#. Then, use the NuGet Package Manager to install the SolidDNA package. This can be done by searching for “SolidDNA” in the NuGet Package Manager and installing the latest version.
Step 2: Initialising SolidDNA in Your Project
- Reference SolidDNA: In your project, add a reference to the SolidDNA library.
- Initialise SolidDNA: Create a new class that will serve as the entry point for your SolidDNA application. In this class, initialise SolidDNA by calling its initialisation method and setting up any plugins or add-ins you wish to use.
public class SolidDnaApplication
{
public void Initialize()
{
// Initialize SolidDNA
SolidDnaIntegration.Initialize();
// Add your custom logic or plugins here
}
}
Step 3: Creating a Plugin
- Define a Plugin: Create a new class that inherits from
SolidPlugIn. This class will represent your custom plugin. - Implement Required Methods: Override the
ConnectedToSolidWorksandDisconnectedFromSolidWorksmethods to handle the connection and disconnection logic for SOLIDWORKS.
public class MyCustomPlugin : SolidPlugIn
{
public override string AddInTitle => "My Custom Plugin";
public override string AddInDescription => "This plugin does amazing things with SOLIDWORKS";
public override void ConnectedToSolidWorks()
{
// Your code to execute when connected to SOLIDWORKS
}
public override void DisconnectedFromSolidWorks()
{
// Cleanup code
}
}
Step 4: Running Your Application
- Compile your project and run it. Your plugin should initialise and connect to SOLIDWORKS, ready to execute your custom logic.
Real Use Case: Automating Part Creation
Now, let’s dive into a real-world scenario where SolidDNA can be utilised to automate the creation of a simple part in SOLIDWORKS, such as a rectangular prism.
Use Case Description
Imagine you’re working on a project that requires creating multiple configurations of a rectangular prism with varying dimensions, okay this is a little contrived but stick with it. Doing this manually for each configuration can be time-consuming. Using SolidDNA, you can automate this process.
Steps to Automate Part Creation
- Create a New Plugin Method: In your
MyCustomPluginclass, add a new method calledCreateRectangularPrismthat takes width, height, and depth as parameters. - Implement Part Creation Logic:
- Use SolidDNA’s model creation APIs to start a new part document.
- Add a new sketch on the desired plane.
- Draw a rectangle with the given dimensions.
- Extrude the sketch to create a solid body with the specified depth.
public void CreateRectangularPrism(double width, double height, double depth)
{
// Start a new part
var part = new PartDocument();
part.CreateNew();
// Add a sketch
var sketch = part.Sketches.AddNewSketch("Front Plane");
// Draw a rectangle
sketch.DrawRectangle(0, 0, width, height);
// Extrude the sketch
part.Features.Extrude(sketch, depth);
}
- Invoke the Method: Use the
ConnectedToSolidWorksmethod to call yourCreateRectangularPrismmethod with the desired dimensions.
This use case illustrates how SolidDNA can be leveraged to automate repetitive tasks in SOLIDWORKS, significantly improving productivity and reducing the potential for human error.

Added Functionalities with SolidDNA
Custom User Interface
SolidDNA allows for the customisation of the SOLIDWORKS user interface, enabling you to add custom buttons, menus, and panels that can interact with your plugin logic.
- Adding a Toolbar Button:
- Use the
SolidWorksApplicationobject to add a toolbar button within theConnectedToSolidWorksmethod of your plugin. - Assign an action to the button, such as triggering the
CreateRectangularPrismmethod or any other functionality you wish to expose.
- Use the
public override void ConnectedToSolidWorks()
{
var myButton = SolidWorksApplication.AddButton("My Toolbar", "Create Prism", "Creates a rectangular prism", "PrismIcon.png");
myButton.Click += (s, e) => CreateRectangularPrism(100, 50, 25);
}
Handling Events
SolidDNA provides access to various SOLIDWORKS events, allowing your plugin to respond to actions such as file openings, pre- and post-save actions, model changes, etc.
- Subscribing to an Event:
- Choose an event from the SOLIDWORKS API, such as
FileOpened. - Use SolidDNA’s event manager to subscribe to the event and define a callback function.
- Choose an event from the SOLIDWORKS API, such as
public override void ConnectedToSolidWorks()
{
SolidWorksApplication.FileOpened += OnFileOpened;
}
private void OnFileOpened(string fileName)
{
// Your logic to execute when a file is opened
}
Custom Properties and Data Management
With SolidDNA, you can easily manage custom properties within your SOLIDWORKS documents, facilitating tasks like metadata management, configuration-specific information, and more.
- Adding Custom Properties:
- Access the active model’s CustomPropertyManager.
- Add or modify custom properties as needed.
public void AddCustomProperty(string propertyName, string propertyValue)
{
var model = SolidWorksApplication.ActiveModel;
if(model != null)
{
model.CustomPropertyManager.AddProperty(propertyName, CustomPropertyType.Text, propertyValue);
}
}
Considerations for Efficient SolidDNA Development
- Performance: When automating tasks, consider the performance implications, especially when dealing with large assemblies or complex operations. Optimise your code to minimise computational overhead.
- Error Handling: Implement robust error handling to manage exceptions, especially when interacting with the SOLIDWORKS API, which might behave unpredictably depending on the state of the application.
- SOLIDWORKS API Limitations: While SolidDNA abstracts much of the complexity of the SOLIDWORKS API, there might be specific functionalities that are not directly exposed. In such cases, you may need to dive deeper into the SOLIDWORKS API documentation and possibly extend SolidDNA to cover your requirements.
- Community and Support: Engage with the SolidDNA community for support, feature requests, and contributions. Collaborating with other developers can provide insights and solutions to common challenges.
Expanding Your SolidDNA Projects
As you become more comfortable with SolidDNA, consider exploring more advanced aspects of SOLIDWORKS automation and customisation:
- Macro Recording: Use SOLIDWORKS macro recording to understand the underlying API calls for specific actions, which can then be translated into SolidDNA logic.
- Custom Data Management: Develop plugins that integrate with SOLIDWORKS PDM or other data management systems, automating tasks like document control, revision management, and lifecycle workflows.
- Advanced Modeling Techniques: Explore advanced modelling techniques such as feature-based modelling, surface modelling, and assembly automation to create more complex and configurable designs.
Summary
By continuing to build on the foundational knowledge provided in this tutorial, you can leverage SolidDNA to create powerful, customised solutions that enhance your SOLIDWORKS projects and workflows. Experiment with different functionalities and consider contributing to the SolidDNA community to share your insights and learn from others.