快捷搜索: 王者荣耀 脱发

草图/3D草图的创建、编辑和保存。

关于ISketchManager接口下面的常用方法。

    草图/3D草图的创建、编辑和保存。 画线,画圆弧,画矩形,画圆
//SolidWorks 2020
using SolidWorks.Interop.sldworks;
namespace DemoSketchTest
{
          
   
    class SketchSw
    {
          
   
        private IModelDoc2 swDoc;
        private ISketch mSketch;
        public void setDoc(IModelDoc2 doc)
        {
          
   
            swDoc = doc;
        }
        //创建草图,
        public bool CreateNew(string planeName)
        {
          
   
            //选择平面,作为创建草图的基准面
            bool b1 = swDoc.Extension.SelectByID2(planeName, "PLANE", 0, 0, 0, false, 0, null, 0);
            if (!b1) return false;
           // swDoc.SketchManager.InsertSketch(true);//创建草图
            swDoc.SketchManager.Insert3DSketch(true);//创建3D草图
            int ttt = swDoc.SelectionManager.GetSelectedObjectType3(1, -1);
            object obj1 = swDoc.SelectionManager.GetSelectedObject6(1, -1);
            //AddToDB:获取或设置 是否将草图实体直接添加到 SOLIDWORKS 数据库中。
            //  swDoc.SketchManager.AddToDB = true;没看出什么变化?
            return true;
        }

        public void DrawLine(double X1, double Y1, double X2, double Y2)
        {
          
   
            SketchSegment ss = swDoc.SketchManager.CreateLine(X1, Y1, 0, X2, Y2, 0);
            swDoc.ClearSelection2(true);//确定图形。
        }
        public void DrawCircle(double X1, double Y1, double X2, double Y2)
        {
          
   
            SketchSegment ss = swDoc.SketchManager.CreateCircle(X1, Y1, 0, X2, Y2, 0);
            swDoc.ClearSelection2(true);//确定图形。
        }
        public void DrawRect(double X1, double Y1, double X2, double Y2)
        {
          
   
            swDoc.SketchManager.CreateCenterRectangle(X1, Y1, 0, X2, Y2, 0);
            swDoc.ClearSelection2(true);//确定图形。
        }
        public void DrawArc(double X1, double Y1, double X2, double Y2, double X3, double Y3)
        {
          
   
            SketchSegment ss = swDoc.SketchManager.CreateArc(X1, Y1, 0, X2, Y2, 0, X3, Y3, 0, 1);
            swDoc.ClearSelection2(true);//确定图形。
        }
        //保存草图,并重命名草图。
        public bool Save(string file)
        {
          
   
            // swDoc.SketchManager.InsertSketch(true);//保存草图
            swDoc.SketchManager.Insert3DSketch(true);//保存3D草图
            int ttt = swDoc.SelectionManager.GetSelectedObjectType3(1, -1);
            object obj = swDoc.SelectionManager.GetSelectedObject6(1, -1); 
            if(obj!=null)
            {
          
   // hide 草图                
                Feature feat = (Feature)obj;
                object obj2 = feat.GetSpecificFeature2();
                mSketch = (ISketch)obj2;
                //((Entity)isk).Select(true);
                //swDoc.BlankSketch(); //hide草图  
            }
            bool b = swDoc.SelectedFeatureProperties(0, 0, 0, 0, 0, 0, 0, true, false, file);//重命名           
            return b;
        }
        public void Edit()
        {
          
   
            ((Entity)mSketch).Select(true);
            swDoc.EditSketch();
        }
    }
}
经验分享 程序员 微信小程序 职场和发展