Example #1
0
        private void ExtractUserPreferences(IModelDocExtension modelExt, string outFilePath, Dictionary <Type, PreferenceHandlerDelegate> handlers)
        {
            using (StreamWriter fileWriter = new StreamWriter(outFilePath))
            {
                fileWriter.WriteLine("Type,Preference,Options,Value");

                foreach (KeyValuePair <Type, PreferenceHandlerDelegate> prefData in handlers)
                {
                    foreach (Enum pref in Enum.GetValues(prefData.Key))
                    {
                        if (pref.ToString().StartsWith("swDetailing"))
                        {
                            foreach (swUserPreferenceOption_e opt in Enum.GetValues(typeof(swUserPreferenceOption_e)))
                            {
                                OutputValue(fileWriter, prefData.Value, modelExt, pref, opt);
                            }
                        }
                        else
                        {
                            OutputValue(fileWriter, prefData.Value, modelExt, pref, swUserPreferenceOption_e.swDetailingNoOptionSpecified);
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// 重新对文档命名
        /// </summary>
        /// <param name="docExtension"><see cref="IModelDocExtension"/></param>
        /// <param name="newName">新名称</param>
        /// <param name="throwError">是否抛出异常</param>
        /// <returns></returns>
        public static swRenameDocumentError_e RenameDocumentEx(this IModelDocExtension docExtension, string newName, bool throwError = true)
        {
            var result = docExtension.RenameDocument(newName).CastObj <swRenameDocumentError_e>();

            if (throwError && result != swRenameDocumentError_e.swRenameDocumentError_None)
            {
                throw new InvalidOperationException($"Cannot rename the document with new Name:{newName},Error type: {result.ToString()}");
            }
            return(result);
        }
Example #3
0
        private void OutputValue(System.IO.StreamWriter fileWriter, PreferenceHandlerDelegate handler,
                                 IModelDocExtension ext, Enum pref, swUserPreferenceOption_e opt)
        {
            int prefVal = Convert.ToInt32(pref);

            string type;
            object value = handler.Invoke(ext, prefVal, opt, out type);

            string line = string.Format("{0},{1},{2},\"{3}\"", type, pref, opt, value);

            fileWriter.WriteLine(line);
        }
Example #4
0
        public void Main()
        {
            try
            {
                IModelDoc2 model = swApp.IActiveDoc2;

                if (model != null)
                {
                    IModelDocExtension modelExt = model.Extension;

                    Dictionary <Type, PreferenceHandlerDelegate> handlers = InitHandlers();

                    string outFilePath = OUT_FILE_PATH;

                    if (string.IsNullOrEmpty(outFilePath))
                    {
                        outFilePath = Path.GetFileNameWithoutExtension(model.GetTitle()) + "_prefs.csv";
                    }

                    if (!Path.IsPathRooted(outFilePath))
                    {
                        string curModelPath = model.GetPathName();

                        if (string.IsNullOrEmpty(curModelPath))
                        {
                            throw new NullReferenceException("Current model is not saved. Either save the model or specify the full path to the output file");
                        }

                        outFilePath = Path.Combine(Path.GetDirectoryName(curModelPath), outFilePath);
                    }

                    ExtractUserPreferences(modelExt, outFilePath, handlers);
                }
                else
                {
                    throw new NullReferenceException("Please open the model");
                }
            }
            catch (Exception ex)
            {
                swApp.SendMsgToUser2(ex.Message, (int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk);
            }
        }
Example #5
0
 /// <summary>
 /// Sets the source interops
 /// </summary>
 /// <param name="doc"></param>
 public SolidworksDocument(IModelDoc2 doc)
 {
     _doc          = doc;
     _extension    = doc.Extension;
     _selectionMgr = doc.SelectionManager;
 }
 /// <summary>
 /// 通过名字调用 SelectByID2
 /// </summary>
 /// <param name="feat"></param>
 /// <param name="extension"></param>
 /// <param name="name"></param>
 /// <param name="type"></param>
 /// <param name="append"></param>
 /// <param name="mark"></param>
 /// <returns></returns>
 public static bool SelectByName(this IFeature feat, IModelDocExtension extension, string name, string type, bool append, int mark = 0)
 {
     return(extension.SelectByID2(name, type, 0, 0, 0, append, mark, null, 0));
 }
Example #7
0
 private object GetTogglePreferenceValue(IModelDocExtension ext, int pref, swUserPreferenceOption_e opt, out string type)
 {
     type = "Toggle";
     return(ext.GetUserPreferenceToggle(pref, (int)opt));
 }
Example #8
0
 private object GetIntegerPreferenceValue(IModelDocExtension ext, int pref, swUserPreferenceOption_e opt, out string type)
 {
     type = "Integer";
     return(ext.GetUserPreferenceInteger(pref, (int)opt));
 }