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); } }
//This is how the STL export preferences need to be to properly export public void setSTLExportPreferences() { iSwApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSTLBinaryFormat, true); iSwApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSTLDontTranslateToPositive, true); iSwApp.SetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swExportStlUnits, 2); iSwApp.SetUserPreferenceIntegerValue((int)swUserPreferenceIntegerValue_e.swSTLQuality, (int)swSTLQuality_e.swSTLQuality_Coarse); iSwApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSTLShowInfoOnSave, false); iSwApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSTLPreview, false); iSwApp.SetUserPreferenceDoubleValue((int)swUserPreferenceDoubleValue_e.swViewTransitionHideShowComponent, 0); iSwApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSTLComponentsIntoOneFile, true); }
/// <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); } }
public Feature[] AddTMPBasePlaneFromSelectFace() { Feature[] tempFeatures = new Feature[2]; //连接到Solidworks ModelDoc2 swModel = (ModelDoc2)iSwApp.ActiveDoc; //设定标注尺寸时 不输入值 iSwApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate, false); // Get the pre-selected planar face Face2 swSelFace = default(Face2); SelectionMgr swSelMgr = (SelectionMgr)swModel.SelectionManager; //获取选择数据 SelectData swSelData = default(SelectData); swSelData = swSelMgr.CreateSelectData(); swSelFace = (Face2)swSelMgr.GetSelectedObject6(1, 1); //var ps = swSelFace.GetTessTriStrips(false); //获取屏幕鼠标选择的那个点 var mousePoint = (double[])swSelMgr.GetSelectionPoint2(1, 1); List <Edge> thisFaceEdgeList = GetSelectFaceEdgeList(swSelFace); swModel.ViewZoomtofit2(); Entity swSelFaceEntity = (Entity)swSelFace; string skFirstName = ""; tempFeatures[0] = DrawnSketchOnFace(swModel, mousePoint, thisFaceEdgeList, swSelFaceEntity, out skFirstName); var t = (double[])swSelFace.Normal; swModel.ClearSelection2(true); swSelFaceEntity.Select4(false, swSelData); return(tempFeatures); }