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

Managing dimensions in the SOLIDWORKS macro feature using xCAD framework


Dimensions is an additional source of input for macro feature. Dimensions can be defined in the following way:

using Xarial.XCad.Features.CustomFeature.Attributes;
using Xarial.XCad.Features.CustomFeature.Enums;

namespace Xarial.XCad.Documentation
{
    public class DimensionMacroFeatureParams
    {
        [ParameterDimension(CustomFeatureDimensionType_e.Linear)]
        public double FirstDimension { get; set; } = 0.01;

        [ParameterDimension(CustomFeatureDimensionType_e.Radial)]
        public double SecondDimension { get; set; }
    }    
}

It is required to arrange the dimensions within rebuild by specifying the alignDim delegate. Use IXCustomFeatureDefinition.AlignDimension and extension helper methods to align the dimension.

using Xarial.XCad.Features.CustomFeature;
using Xarial.XCad.Features.CustomFeature.Delegates;
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
{
    public class MyDimRegenDataMacroFeature : SwMacroFeatureDefinition<DimensionMacroFeatureParams>
    {        
        private IXBody[] GetBodies()
        {
            //TODO: create bodies for geometry
            return null;
        }

        public override CustomFeatureRebuildResult OnRebuild(ISwApplication app, ISwDocument model, ISwMacroFeature feature, DimensionMacroFeatureParams parameters, out AlignDimensionDelegate<DimensionMacroFeatureParams> alignDim)
        {
            var resBodies = GetBodies(); //generating bodies

            alignDim = (name, dim) => 
            {
                switch (name) 
                {
                    case nameof(DimensionMacroFeatureParams.FirstDimension):
                        this.AlignLinearDimension(dim, new Point(0, 0, 0), new Vector(1, 0, 0));
                        break;

                    case nameof(DimensionMacroFeatureParams.SecondDimension):
                        this.AlignRadialDimension(dim, new Point(0, 0, 0), new Vector(0, 0, 1));
                        break;
                }
            };

            return new CustomFeatureBodyRebuildResult() { Bodies = resBodies }; //returning custom rebuild result
        }
    }
}

Origin is a starting point of the dimension.

For linear dimensions orientation represents the vector along the direction of the dimension (i.e. the direction of measured entity) For radial dimensions orientation represents the normal of the dimension (i.e. the vector of rotation of the dimension)

Orientation of dimensions
Orientation of dimensions


Powered by Docify