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

Storing data (parameters, bodies, selection) in SOLIDWORKS macro feature


Macro feature can store additional metadata and entities. The data includes

  • Parameters
  • Selections
  • Edit bodies
  • Dimensions

Required data can be defined within the macro feature data model. Special parameters (such as selections, edit bodies or dimensions) should be decorated with appropriate attributes, all other properties will be considered as parameters.

Data model is used both as input and output of macro feature. Parameters can be accessed via SwMacroFeature.Parameters property and also passed to OnRebuild handler.

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

namespace Xarial.XCad.Documentation
{   
    public class MacroFeatureParams
    {
        // text metadata
        public string TextParameter { get; set; }

        // boolean metadata
        public bool ToggleParameter { get; set; }

        // any dependency selection
        public IXSelObject FaceSelectionParameter { get; set; }

        // edit body - base body which macro feature is modifying
        [ParameterEditBody]
        public IXBody InputBody { get; set; }

        // macro feature dimension. Value of the dimension will be sync with the proeprty
        [ParameterDimension(CustomFeatureDimensionType_e.Linear)]
        public double LinearDimension { get; set; }
    }

    [ComVisible(true)]
    public class MyParamsMacroFeature : SwMacroFeatureDefinition<MacroFeatureParams>
    {
        public override CustomFeatureRebuildResult OnRebuild(ISwApplication app, ISwDocument model, 
            ISwMacroFeature<MacroFeatureParams> feature, out AlignDimensionDelegate<MacroFeatureParams> alignDim)
        {
            var parameters = feature.Parameters;

            var txt = parameters.TextParameter;
            var inputBody = parameters.InputBody;

            alignDim = null;
            return new CustomFeatureRebuildResult();
        }
    }
}


Powered by Docify