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

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.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(SwApplication app, SwDocument model, SwMacroFeature feature)
        {
            return new CustomFeatureRebuildResult()
            {
                Result = true
            };
        }
    }

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

    //return body
    [ComVisible(true)]
    public class RegenerationBodyMacroFeature : SwMacroFeatureDefinition
    {
        public override CustomFeatureRebuildResult OnRebuild(SwApplication app, SwDocument model, SwMacroFeature feature)
        {
            var body = app.GeometryBuilder.CreateBox(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 = new IXBody[] { body }
            };
        }
    }
}

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


Powered by Docify