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

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
    {
        //TODO: add properties
    }

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

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

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

            newParameters = null;
            return true;
        }
    }
}


Powered by Docify