{"id":37054341,"url":"https://github.com/codestackdev/swex-macrofeature","last_synced_at":"2026-01-14T06:08:09.826Z","repository":{"id":116159266,"uuid":"151818762","full_name":"codestackdev/swex-macrofeature","owner":"codestackdev","description":"SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS add-ins","archived":false,"fork":false,"pushed_at":"2019-10-04T11:53:20.000Z","size":263,"stargazers_count":14,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-12-30T16:32:39.217Z","etag":null,"topics":["addin","macrofeature","solidworks","solidworksapi"],"latest_commit_sha":null,"homepage":"https://www.codestack.net/labs/solidworks/swex/macro-feature/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codestackdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-10-06T08:13:48.000Z","updated_at":"2025-12-09T15:46:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"19ba8d9f-47d1-4d8f-9abe-ca7cef60086f","html_url":"https://github.com/codestackdev/swex-macrofeature","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codestackdev/swex-macrofeature","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codestackdev%2Fswex-macrofeature","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codestackdev%2Fswex-macrofeature/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codestackdev%2Fswex-macrofeature/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codestackdev%2Fswex-macrofeature/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codestackdev","download_url":"https://codeload.github.com/codestackdev/swex-macrofeature/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codestackdev%2Fswex-macrofeature/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28412188,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T05:26:33.345Z","status":"ssl_error","status_checked_at":"2026-01-14T05:21:57.251Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["addin","macrofeature","solidworks","solidworksapi"],"created_at":"2026-01-14T06:08:09.320Z","updated_at":"2026-01-14T06:08:09.819Z","avatar_url":"https://github.com/codestackdev.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Documentation](https://img.shields.io/badge/-Documentation-green.svg)](https://www.codestack.net/labs/solidworks/swex/macro-feature/)\n[![NuGet](https://img.shields.io/nuget/v/CodeStack.SwEx.MacroFeature.svg)](https://www.nuget.org/packages/CodeStack.SwEx.MacroFeature/)\n[![Issues](https://img.shields.io/github/issues/codestackdev/swex-macrofeature.svg)](https://github.com/codestackdev/swex-macrofeature/issues)\n\n# SwEx.MacroFeature\n![SwEx.MacroFeature](https://www.codestack.net/labs/solidworks/swex/macro-feature/logo.png)\nSwEx.MacroFeature enables SOLIDWORKS add-in developers to develop applications utilizing the macro feature functionality.\n\n## Getting started\nCreate a public COM visible class for macro feature. Inherit one of the [MacroFeatureEx](https://docs.codestack.net/swex/macro-feature/html/N_CodeStack_SwEx_MacroFeature.htm) class overloads.\n\nIt is recommended to explicitly assign guid and prog id for the macro feature.\n\nOptionally assign additional [options](https://docs.codestack.net/swex/macro-feature/html/T_CodeStack_SwEx_MacroFeature_Attributes_OptionsAttribute.htm) and [icon](https://docs.codestack.net/swex/macro-feature/html/T_CodeStack_SwEx_MacroFeature_Attributes_IconAttribute.htm)\n\n~~~ cs\n    [ComVisible(true)]\n    [Guid(\"47827004-8897-49F5-9C65-5B845DC7F5AC\")]\n    [ProgId(Id)]\n    [Options(\"CodeStack.MyMacroFeature\", swMacroFeatureOptions_e.swMacroFeatureAlwaysAtEnd)]\n    [Icon(typeof(Resources), nameof(Resources.macro_feature_icon), \"CodeStack\\\\MyMacroFeature\\\\Icons\")]\n    public class MyMacroFeature : MacroFeatureEx\u003cRoundStockFeatureParameters\u003e\n    {\n\n    }\n~~~\n\n[Read More...](https://www.codestack.net/labs/solidworks/swex/macro-feature/getting-started)\n\n## Lifecycle\nMacro feature resides in the model and saved together with the document. Macro feature can handle various events during its lifecycle\n\n* Regeneration\n* Editing\n* Updating state\n\nMacro feature is a singleton service. Do not create any class level variables in the macro feature class. If it is required to track the lifecycle of particular macro feature use [Feature Handler](#feature-handler).\n\n[Read More...](https://www.codestack.net/labs/solidworks/swex/macro-feature/lifecycle)\n\n### Regeneration\nThis handler called when feature is being rebuilt (either when regenerate is invoked or when the parent elements have been changed).\n\nUse [MacroFeatureRebuildResult](https://docs.codestack.net/swex/macro-feature/html/T_CodeStack_SwEx_MacroFeature_Base_MacroFeatureRebuildResult.htm) class to generate the required output.\n\nFeature can generate the following output\n\n* None\n* Rebuild Error\n* Solid or surface body\n* Array of solid or surface bodies\n\nUse [IModeler](http://help.solidworks.com/2017/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.imodeler.html) interface if feature needs to create new bodies. Only temp bodies can be returned from the regeneration method.\n\n~~~ cs\nprotected override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model, IFeature feature, MyParameters parameters)\n{\n    var body = GenerateBodyFromParameters(parameters);\n    return MacroFeatureRebuildResult.FromBody(body, feature.GetDefinition() as IMacroFeatureData);\n}\n~~~\n\n[Read More...](https://www.codestack.net/labs/solidworks/swex/macro-feature/lifecycle/regeneration)\n\n### Edit Definition\n\nEdit 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.\n\n![Edit Feature Command](https://www.codestack.net/labs/solidworks/swex/macro-feature/lifecycle/edit-definition/menu-edit-feature.png)\n\n~~~ cs\nprotected override bool OnEditDefinition(ISldWorks app, IModelDoc2 model, IFeature feature)\n{\n    var featData = feature.GetDefinition() as IMacroFeatureData;\n\n    //rollback feature\n    featData.AccessSelections(model, null);\n\n    //read current parameters\n    var parameters = GetParameters(feature, featData, model);\n\n    //Show property page or any other user interface\n    var res = ShowPage(parameters);\n\n    if (res)\n    {\n        //set parameters and update feature data\n        SetParameters(model, feature, featData, parameters);\n        feature.ModifyDefinition(featData, part, null);\n    }\n    else\n    {\n        //cancel modifications\n        featData.ReleaseSelectionAccess();\n    }\n\n    return true;\n}\n~~~\n\nIt is important to use the same pointer to [IMacroFeatureData](http://help.solidworks.com/2016/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.imacrofeaturedata.html) while calling the [IMacroFeatureData::AccessSelections](http://help.solidworks.com/2016/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IMacroFeatureData~AccessSelections.html), [GetParameters](https://docs.codestack.net/swex/macro-feature/html/M_CodeStack_SwEx_MacroFeature_MacroFeatureEx_1_GetParameters.htm), [SetParameters](https://docs.codestack.net/swex/macro-feature/html/M_CodeStack_SwEx_MacroFeature_MacroFeatureEx_1_SetParameters.htm) and [IFeature::ModifyDefinition](http://help.solidworks.com/2016/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IFeature~ModifyDefinition.html) methods.\n\n[Read More...](https://www.codestack.net/labs/solidworks/swex/macro-feature/lifecycle/edit-definition)\n\n### State\nThis handler is called everytime state of the feature is changed. It should be used to provide additional security for macro feature\n\n~~~ cs\nprotected override swMacroFeatureSecurityOptions_e OnUpdateState(ISldWorks app, IModelDoc2 model, IFeature feature)\n{\n    //disallow editing or suppressing of the feature\n    return swMacroFeatureSecurityOptions_e.swMacroFeatureSecurityCannotBeDeleted \n                | swMacroFeatureSecurityOptions_e.swMacroFeatureSecurityCannotBeSuppressed;\n}\n~~~\n\n[Read More...](https://www.codestack.net/labs/solidworks/swex/macro-feature/lifecycle/state)\n\n### Feature Handler\n\n[MacroFeatureEx\u003cTParams, THandler\u003e Class]() overload of macro feature allows defining the handler class which will be created for each feature. This provides a simple way to track the macro feature lifecycle (i.e. creation time and deletion time).\n\n~~~ cs\npublic class LifecycleMacroFeatureParams\n{\n}\n\npublic class LifecycleMacroFeatureHandler : IMacroFeatureHandler\n{\n    public void Init(ISldWorks app, IModelDoc2 model, IFeature feat)\n    {\n        //feature is created or loaded\n    }\n\n    public void Unload()\n    {\n        //feature is deleted or model is closed\n    }\n}\n\n[ComVisible(true)]\npublic class LifecycleMacroFeature : MacroFeatureEx\u003cLifecycleMacroFeatureParams, LifecycleMacroFeatureHandler\u003e\n{\n    protected override MacroFeatureRebuildResult OnRebuild(LifecycleMacroFeatureHandler handler, LifecycleMacroFeatureParams parameters)\n    {\n        return MacroFeatureRebuildResult.FromStatus(true);\n    }\n}\n~~~\n\n[Read More...](https://www.codestack.net/labs/solidworks/swex/macro-feature/lifecycle/feature-handler)\n\n## Data\n\nMacro feature can store additonal metadata and entities. The data includes\n\n* Parameters\n* Selections\n* Edit bodies\n* Dimensions\n\nRequired 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](https://docs.codestack.net/swex/macro-feature/html/N_CodeStack_SwEx_MacroFeature_Attributes.htm), all other proeprties will be considered as parameters.\n\n[Read More...](https://www.codestack.net/labs/solidworks/swex/macro-feature/data)\n\n### Parameters\n\n~~~ cs\npublic class MacroFeatureParams\n{\n    public string Parameter1 { get; set; }\n    public int Parameter2 { get; set; }\n}\n\n//this macro feature has two parameters (Parameter1 and Parameter2)\n[ComVisible(true)]\npublic class MyMacroFeature : MacroFeatureEx\u003cMacroFeatureParams\u003e\n{\n}\n~~~\n\n[Read More...](https://www.codestack.net/labs/solidworks/swex/macro-feature/data/parameters)\n\n### Selections\n\n~~~ cs\npublic class MacroFeatureParams\n{\n    //selection parameter of any entity (e.g. face, edge, feature etc.)\n    [ParameterSelection]\n    public object AnyEntity { get; set; }\n\n    //selection parameter of body\n    [ParameterSelection]\n    public IBody2 Body { get; set; }\n\n    //selection parameter of array of faces\n    [ParameterSelection]\n    public List\u003cIFace2\u003e Faces { get; set; }\n~~~\n\nParameter proeprties can be specified either using the direct SOLIDWORKS type or as object if type is unknown. List of selections is also supported.\n\n[OnRebuild](https://docs.codestack.net/swex/macro-feature/html/M_CodeStack_SwEx_MacroFeature_MacroFeatureEx_OnRebuild.htm) handler will be called if any of the selections have changed.\n\n[Read More...](https://www.codestack.net/labs/solidworks/swex/macro-feature/data/selections)\n\n### Edit Bodies\n\nEdit bodies are input bodies which macro feature will acquire. For example when boss-extrude feature is created using the merge bodies option the solid body it is based on became a body of the new boss-extrude. This could be validated by selecting the feature in the tree which will select the body as well. In this case the original body was passed as an edit body to the boss-extrude feature.\n\n~~~ cs\npublic class MacroFeatureParams\n{\n    [ParameterEditBody]\n    public IBody2 InputBody { get; set; }\n}\n~~~\n\n[Read More...](https://www.codestack.net/labs/solidworks/swex/macro-feature/data/edit-bodies)\n\n### Dimensions\nDimensions is an additional source of input for macro feature. Dimensions can be defined in the follwing way:\n\n~~~ cs\npublic class DimensionMacroFeatureParams\n{\n    [ParameterDimension(swDimensionType_e.swLinearDimension)]\n    public double FirstDimension { get; set; } = 0.01;\n\n    [ParameterDimension(swDimensionType_e.swLinearDimension)]\n    public double SecondDimension { get; set; }\n}\n~~~\n\nIt is required to arrange the dimensions after rebuild by overriding the [OnSetDimensions](https://docs.codestack.net/swex/macro-feature/html/M_CodeStack_SwEx_MacroFeature_MacroFeatureEx_1_OnSetDimensions.htm) method. Use [DimensionData::SetOrientation](https://docs.codestack.net/swex/macro-feature/html/M_CodeStack_SwEx_MacroFeature_Data_DimensionDataExtension_SetOrientation.htm) helper method to align the dimension.\n\n~~~ cs\nprotected override void OnSetDimensions(ISldWorks app, IModelDoc2 model, IFeature feature, MacroFeatureRebuildResult rebuildResult, DimensionDataCollection dims, BoundingCylinderMacroFeatureParams parameters)\n{\n    dims[0].SetOrientation(new Point(0, 0, 0), new Vector(0, 1, 0));\n\n    dims[1].SetOrientation(new Point(0, 0, 0), new Vector(0, 0, 1));\n}\n~~~\n\n[Read More...](https://www.codestack.net/labs/solidworks/swex/macro-feature/data/dimensions)\n\n### Backward Compatibility\n\nMacro feature parameters might need to change from version to version. And SwEx.MacroFeature framework provides a mechanism to handle the backward compatibility of existing features.\n\nMark current version of parameters with [ParametersVersionAttribute](https://docs.codestack.net/swex/macro-feature/html/T_CodeStack_SwEx_MacroFeature_Attributes_ParametersVersionAttribute.htm) and increase the version if any of the parameters changed.\n\nImplement the [Paramater Version Converter](https://docs.codestack.net/swex/macro-feature/html/T_CodeStack_SwEx_MacroFeature_Base_IParametersVersionConverter.htm) to convert from the latest version of the parameters to the nevest one. Framework will take care of aligning versions in case parameters are older than one version.\n\nOld version of parameters\n~~~ cs\n[ParametersVersion(\"1.0\", typeof(MacroFeatureParamsVersionConverter))]\npublic class MacroFeatureParams\n{\n    public string Param1 { get; set; }\n    public int Param2 { get; set; }\n}\n~~~\n\nNew version of parameters\n\n~~~ cs\n[ParametersVersion(\"2.0\", typeof(MacroFeatureParamsVersionConverter))]\npublic class MacroFeatureParams\n{\n    public string Param1A { get; set; }//parameter renamed\n    public int Param2 { get; set; }\n    public string Param3 { get; set; }//new parameter added\n}\n\npublic class MacroFeatureParamsVersionConverter : ParametersVersionConverter\n{\n    private class VersConv_1_0To2_0 : ParameterConverter\n    {\n        public override Dictionary\u003cstring, string\u003e ConvertParameters(IModelDoc2 model, IFeature feat, Dictionary\u003cstring, string\u003e parameters)\n        {\n            var paramVal = parameters[\"Param1\"];\n            parameters.Remove(\"Param1\");\n            parameters.Add(\"Param1A\", paramVal);//renaming parameter\n            parameters.Add(\"Param3\", \"Default\");//adding new parameter with default value\n            return parameters;\n        }\n    }\n\n    public ParamsMacroFeatureParamsVersionConverter()\n    {\n        //conversion from version 1.0 to 2.0\n        Add(new Version(\"2.0\"), new VersConv_1_0To2_0());\n        //TODO: add more version converters\n    }\n}\n~~~\n\n[Read More...](https://www.codestack.net/labs/solidworks/swex/macro-feature/data/backward-compatibility)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodestackdev%2Fswex-macrofeature","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodestackdev%2Fswex-macrofeature","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodestackdev%2Fswex-macrofeature/lists"}