Beispiel #1
0
        protected sealed override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model, IFeature feature)
        {
            Logger.Log("Rebuilding. Getting parameters");

            var featDef = feature.GetDefinition() as IMacroFeatureData;

            IDisplayDimension[] dispDims;
            IBody2[]            editBodies;

            MacroFeatureOutdateState_e state;

            string[] dispDimParams;
            var      parameters = m_ParamsParser.GetParameters <TParams>(feature, featDef, model, out dispDims,
                                                                         out dispDimParams, out editBodies, out state);

            Logger.Log("Rebuilding. Generating bodies");

            var rebuildRes = OnRebuild(app, model, feature, parameters);

            Logger.Log("Rebuilding. Updating dimensions");

            UpdateDimensions(app, model, feature, rebuildRes, dispDims, dispDimParams, parameters);

            Logger.Log("Rebuilding. Releasing dimensions");

            if (dispDims != null)
            {
                for (int i = 0; i < dispDims.Length; i++)
                {
                    dispDims[i] = null;
                }
            }

            return(rebuildRes);
        }
Beispiel #2
0
        /// <summary>
        /// Replaces existing macro feature with a new one preserving the parameters
        /// </summary>
        /// <typeparam name="TMacroFeature">Type of macro feature</typeparam>
        /// <param name="featMgr">Pointer to feature manager</param>
        /// <param name="feat">Pointer to feature to replace</param>
        /// <returns>Ne replaced feature</returns>
        public static IFeature ReplaceComFeature <TMacroFeature>(this IFeatureManager featMgr, IFeature feat)
            where TMacroFeature : MacroFeatureEx
        {
            if (feat == null)
            {
                throw new ArgumentNullException(nameof(feat));
            }

            var featData = feat.GetDefinition() as IMacroFeatureData;

            if (featData == null)
            {
                throw new NullReferenceException("Specified feature not a macro feature");
            }

            var model = featMgr.Document;

            object parameters = null;

            if (typeof(TMacroFeature).IsAssignableToGenericType(typeof(MacroFeatureEx <>)))
            {
                featData.AccessSelections(model, null);

                var paramsType = typeof(TMacroFeature).GetArgumentsOfGenericType(typeof(MacroFeatureEx <>)).First();
                IDisplayDimension[]        dispDims;
                IBody2[]                   editBodies;
                MacroFeatureOutdateState_e state;
                string[]                   dispDimParams;
                parameters = m_ParamsParser.GetParameters(feat, featData, model, paramsType,
                                                          out dispDims, out dispDimParams, out editBodies, out state);
                MacroFeatureParametersParser.ReleaseDisplayDimensions(dispDims);
            }

            return(featMgr.ReplaceComFeatureBase <TMacroFeature>(feat, parameters));
        }
        /// <summary>
        /// Deserializes the parameters of the macro feature to a structure
        /// </summary>
        /// <typeparam name="TParams">Type of parameters structure</typeparam>
        /// <param name="featData">Pointer to macro feature data</param>
        /// <param name="feat">Pointer to a feature</param>
        /// <param name="model">Pointer to model document</param>
        /// <returns>Parameters</returns>
        public static TParams GetParameters <TParams>(this IMacroFeatureData featData, IFeature feat, IModelDoc2 model)
            where TParams : class, new()
        {
            IDisplayDimension[]        dispDims;
            IBody2[]                   bodies;
            MacroFeatureOutdateState_e state;

            string[] dispDimParams;
            return(m_ParamsParser.GetParameters <TParams>(feat, featData, model,
                                                          out dispDims, out dispDimParams, out bodies, out state));
        }