Пример #1
0
 //Saves the preferences that the user had setup so that I can change them and revert back to their configuration
 public void saveUserPreferences()
 {
     mBinary = iSwApp.GetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSTLBinaryFormat);
     mTranslateToPositive       = iSwApp.GetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSTLDontTranslateToPositive);
     mSTLUnits                  = iSwApp.GetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swExportStlUnits);
     mSTLQuality                = iSwApp.GetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swSTLQuality);
     mshowInfo                  = iSwApp.GetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSTLShowInfoOnSave);
     mSTLPreview                = iSwApp.GetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSTLPreview);
     mHideTransitionSpeed       = iSwApp.GetUserPreferenceDoubleValue((int)swUserPreferenceDoubleValue_e.swViewTransitionHideShowComponent);
     mSaveComponentsIntoOneFile = iSwApp.GetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSTLComponentsIntoOneFile);
 }
Пример #2
0
        protected IDisposable NewDocument(swDocumentTypes_e docType)
        {
            var useDefTemplates = m_SwApp.GetUserPreferenceToggle((int)swUserPreferenceToggle_e.swAlwaysUseDefaultTemplates);

            try
            {
                m_SwApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swAlwaysUseDefaultTemplates, true);

                var defTemplatePath = m_SwApp.GetDocumentTemplate(
                    (int)docType, "", (int)swDwgPaperSizes_e.swDwgPapersUserDefined, 100, 100);

                if (string.IsNullOrEmpty(defTemplatePath))
                {
                    throw new Exception("Default template is not found");
                }

                var model = (IModelDoc2)m_SwApp.NewDocument(defTemplatePath, (int)swDwgPaperSizes_e.swDwgPapersUserDefined, 100, 100);

                if (model != null)
                {
                    var docWrapper = new DocumentWrapper(m_SwApp, model);
                    m_Disposables.Add(docWrapper);
                    return(docWrapper);
                }
                else
                {
                    throw new NullReferenceException($"Failed to create new document from '{defTemplatePath}'");
                }
            }
            finally
            {
                m_SwApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swAlwaysUseDefaultTemplates, useDefTemplates);
            }
        }
 /// <summary>
 /// 设置一个选项后执行动作,执行完后设置回系统默认值
 /// </summary>
 /// <param name="app">ISldwork interface</param>
 /// <param name="toggleSetting">需要设置的枚举值</param>
 /// <param name="value">值</param>
 /// <param name="action">执行的动作</param>
 public static void WithToggleState(this ISldWorks app, swUserPreferenceToggle_e toggleSetting, bool value, Action action)
 {
     try
     {
         bool fileLockState = app.GetUserPreferenceToggle(toggleSetting.SWToInt());
         app.SetUserPreferenceToggle(swUserPreferenceToggle_e.swLockRecentDocumentsList.SWToInt(), true);
         action?.Invoke();
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         app.SetUserPreferenceToggle(toggleSetting.SWToInt(), value);
     }
 }