Esempio n. 1
0
        //装配体中插入新零件
        public void InsretComponent()
        {
            string[] strCompName  = new string[3];
            string[] firstSelect  = new string[15];
            string[] secondSelect = new string[15];
            swModel    = (ModelDoc2)swApp.OpenDoc6("G:\\CodeTest\\planetAssembly.SLDASM", (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swAssembly = (AssemblyDoc)swModel;                          //////
            string assemblyTitle = swModel.GetTitle();                  //获取装配体名称

            string[] strings = assemblyTitle.Split(new Char[] { '.' }); //使用分隔符分割装配体实例号
            assemblyName = (string)strings[0];                          //获得装配体名称
            //打开零件并添加零件到装配体
            swModel = (ModelDoc2)swApp.OpenDoc6("G:\\CodeTest\\内齿轮.SLDPRT", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            //swComponent = (IComponent2)swAssembly.AddComponent5("内齿轮.sldprt", (int)swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, "", false, "", 0, 0, 0);
            //strCompName[0] = swComponent.Name2; //获取内齿轮名称
            //swApp.DocumentVisible(false, (int)swDocumentTypes_e.swDocPART);
            //swModel = (ModelDoc2)swApp.OpenDoc6("G:\\CodeTest\\行星轮.SLDPRT", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            //swComponent = (IComponent2)swAssembly.AddComponent5("行星轮.sldprt", (int)swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, "", false, "", 0, -0.0456, 0);
            //strCompName[1] = swComponent.Name2; //获取行星轮名称
            //swApp.DocumentVisible(false, (int)swDocumentTypes_e.swDocPART);
            //swModel = (ModelDoc2)swApp.OpenDoc6("G:\\CodeTest\\输入轴.SLDPRT", (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            //swComponent = (IComponent2)swAssembly.AddComponent5("输入轴.sldprt", (int)swAddComponentConfigOptions_e.swAddComponentConfigOptions_CurrentSelectedConfig, "", false, "", 0, 0, 0);
            //strCompName[2] = swComponent.Name2; //获取输入轴名称
            //swApp.DocumentVisible(false, (int)swDocumentTypes_e.swDocPART);

            //添加同心配合关系
            firstSelect[0]  = "前视基准面@" + strCompName[0] + "@" + assemblyName; //第一个选择选项
            secondSelect[0] = "前视基准面@" + strCompName[2] + "@" + assemblyName; //第二个选择选项
            swModel.ClearSelection2(true);
            swModelEx = swModel.Extension;
            swModelEx.SelectByID2(firstSelect[0], "PLANE", 0, 0, 0, false, 1, null, 0);//?????????
            swModelEx.SelectByID2("前视基准面@输入轴-1@planetAssembly", "PLANE", 0, 0, 0, true, 0, null, 0);

            swAssembly.AddMate3((int)swMateType_e.swMateCOINCIDENT, (int)swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, 0, 0, 0, false, out mateError);
            swModel.ClearSelection2(true);
            //添加距离约束
            swModelEx.SelectByID2("Point1@原点@行星轮-1@装配体5", "EXTSKETCHPOINT", 0, 0, 0, true, 1, null, 0);
            swModelEx.SelectByID2("Point1@原点@输入轴-1@装配体5", "EXTSKETCHPOINT", 0, 0, 0, true, 1, null, 0);
            swAssembly.AddMate3((int)swMateType_e.swMateDISTANCE, (int)swMateAlign_e.swMateAlignALIGNED, false, 0.0455, 0.0455, 0.0455, 0, 0, 0, 0, 0, false, out mateError);
            //添加齿轮配合
        }