/// <summary>
        /// 退出草图编辑状态
        /// </summary>
        /// <param name="skeMgr"><see cref="ISketchManager"/> Interface</param>
        /// <param name="UpdateEditRebuild"></param>
        /// <returns><see cref="ISketch"/></returns>
        /// <remarks>
        /// 如果SolidWorks不在编辑状态,将会抛出 <see cref="InvalidOperationException"/> 异常
        /// </remarks>
        public static ISketch ExitSketch(this ISketchManager skeMgr, bool UpdateEditRebuild = false)
        {
            var sketch = skeMgr.ActiveSketch;

            if (sketch == null)
            {
                throw new InvalidOperationException($"There is not a active skecth,so you cannot exit sketch");
            }

            skeMgr.InsertSketch(UpdateEditRebuild);

            return(sketch);
        }
예제 #2
0
        /// <summary>
        /// 创建分流板主体,并关联ManiH全局变量
        /// </summary>
        private void ManifoldBody()
        {
            ModelDoc2      swDoc = (ModelDoc2)swApp.ActiveDoc;
            ISketchManager ikm   = swDoc.SketchManager;

            #region 1.创建临时Cube
            for (int i = 0; i < runnerSegments.Count; i++)
            {
                CreateRunnerCube(runnerSegments[i], i);
            }
            #endregion

            #region 2.得到边的几何数据,重新绘图

            contourLine = GetManifoldEdge();

            swDoc.ClearSelection2(true);

            bool boolstatus = swDoc.Extension.SelectByID2("前视基准面", "PLANE", 0, 0, 0, false, 0, null, 0);
            ikm.InsertSketch(true);

            for (int i = 0; i < contourLine.Count; i++)
            {
                ikm.CreateLine(contourLine[i].Start.X, contourLine[i].Start.Y, contourLine[i].Start.Z,
                               contourLine[i].End.X, contourLine[i].End.Y, contourLine[i].End.Z);
            }

            #endregion

            #region 3.标注尺寸

            Sketch  thisSketch = ikm.ActiveSketch;
            Feature thisFet    = (Feature)thisSketch;
            thisFet.Name = "ManifoldSketch";

            //1. 分流板宽度
            contourSegmentLine = thisSketch.GetSegmentLine(swApp);
            DimensionManiW();
            swApp.SetFunction("ManiW", "\"ManiW2\" * 2");
            #endregion

            #region 3.生成特征

            boolstatus = swDoc.Extension.SelectByID2(thisFet.Name, "SKETCH", 0, 0, 0, false, 0, null, 0);

            Feature myFeature = swDoc.SingleEndExtrusion(maniH, false, true);
            myFeature.Name = "Manifold";

            swApp.SetGlobalVariable("D1@Manifold", "ManiH");

            #endregion

            #region 4.删除临时特征
            for (int i = runnerSegments.Count - 1; i > -1; i--)
            {
                boolstatus = swDoc.Extension.SelectByID2("runnerCube" + i.ToString(),
                                                         "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
                swDoc.Extension.DeleteSelection2((int)swDeleteSelectionOptions_e.swDelete_Absorbed);
            }
            #endregion
        }