XCAD.NET
XCAD.NET
Framework for .NET (C# and VB.NET) to create modern application for CAD systems (SOLIDWORKS, SOLIDWORKS Document Manager, Autodesk Inventor, etc.)
Get technical support Connect to xCAD community on Discord server Explore code and application examples xCAD.NET Templates for Visual Studio and VS Code Access source code

Handling Regeneration method of SOLIDWORKS macro feature


This handler called when feature is being rebuilt (either when regenerate is invoked or when the parent elements have been changed).

Use CustomFeatureRebuildResult class to generate the required output.

Feature can generate the following output

using SolidWorks.Interop.sldworks;
using System.Linq;
using System.Runtime.InteropServices;
using Xarial.XCad.Features.CustomFeature.Structures;
using Xarial.XCad.Geometry;
using Xarial.XCad.Geometry.Structures;
using Xarial.XCad.SolidWorks;
using Xarial.XCad.SolidWorks.Documents;
using Xarial.XCad.SolidWorks.Features.CustomFeature;

namespace Xarial.XCad.Documentation
{
    //returns successful regeneration without bodies
    [ComVisible(true)]
    public class RegenerationNoResultsMacroFeature : SwMacroFeatureDefinition
    {
        public override CustomFeatureRebuildResult OnRebuild(ISwApplication app, ISwDocument model, ISwMacroFeature feature)
        {
            return new CustomFeatureRebuildResult()
            {
                Result = true
            };
        }
    }

    // returns regeneration error
    [ComVisible(true)]
    public class RegenerationRebuildErrorMacroFeature : SwMacroFeatureDefinition
    {
        public override CustomFeatureRebuildResult OnRebuild(ISwApplication app, ISwDocument model, ISwMacroFeature feature)
        {
            return new CustomFeatureRebuildResult()
            {
                Result = false,
                ErrorMessage = "Failed to regenerate this feature"
            };
        }
    }

    //return body
    [ComVisible(true)]
    public class RegenerationBodyMacroFeature : SwMacroFeatureDefinition
    {
        public override CustomFeatureRebuildResult OnRebuild(ISwApplication app, ISwDocument model, ISwMacroFeature feature)
        {
            var body = app.MemoryGeometryBuilder.CreateSolidBox(new Point(0, 0, 0),
                new Vector(1, 0, 0), new Vector(0, 1, 0),
                0.1, 0.1, 0.1);

            return new CustomFeatureBodyRebuildResult()
            {
                Bodies = body.Bodies.ToArray()
            };
        }
    }
}

Use IXGeometryBuilder interface if feature needs to create new bodies. Only temp bodies can be returned from the regeneration method.


Powered by Docify