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

Edit SOLIDWORKS macro feature definition


Edit definition allows to modify the parameters of an existing feature. Edit definition is called when Edit Feature command is clicked form the feature manager tree.

Edit Feature Command
Edit Feature Command

Use ISwMacroFeature.Parameters property to read and write the parameters of this macro feature. Set the value to null to revert changes and rollback the feature.

using System.Runtime.InteropServices;
using Xarial.XCad.Features.CustomFeature.Delegates;
using Xarial.XCad.Features.CustomFeature.Structures;
using Xarial.XCad.SolidWorks;
using Xarial.XCad.SolidWorks.Documents;
using Xarial.XCad.SolidWorks.Features.CustomFeature;

namespace Xarial.XCad.Documentation
{
    public class EditMacroFeatureDefinitionParameters
    {
        //add properties
    }

    [ComVisible(true)]
    public class EditMacroFeatureDefinition : SwMacroFeatureDefinition<EditMacroFeatureDefinitionParameters>
    {
        public override CustomFeatureRebuildResult OnRebuild(ISwApplication app, ISwDocument model, 
            ISwMacroFeature<EditMacroFeatureDefinitionParameters> feature, out AlignDimensionDelegate<EditMacroFeatureDefinitionParameters> alignDim)
        {
            alignDim = null;
            return new CustomFeatureRebuildResult() { Result = true };
        }

        public override bool OnEditDefinition(ISwApplication app, ISwDocument model, ISwMacroFeature<EditMacroFeatureDefinitionParameters> feature)
        {
            using (var editor = feature.Edit())
            {
                if (ShowPage(feature.Parameters, out EditMacroFeatureDefinitionParameters newParams))
                {
                    feature.Parameters = newParams;
                    return true;
                }
                else
                {
                    editor.Cancel = true;
                    return false;
                }
            }
        }

        private bool ShowPage(EditMacroFeatureDefinitionParameters parameters, out EditMacroFeatureDefinitionParameters newParameters)
        {
            //Show property page or any other user interface

            newParameters = null;
            return true;
        }
    }
}


Powered by Docify