private void button_CAM_Calc_Click(object sender, EventArgs e) { try { //Initialization SolidWorks Type swType = Type.GetTypeFromProgID("SldWorks.Application"); SldWorks swApp = (SldWorks)Activator.CreateInstance(swType); //Initialization CAMWorks CWApp cwAPP = new CWApp(); // Extract Machinable Features by AFR ICWDoc3 cwActiveDoc = cwAPP.IGetActiveDoc(); cwActiveDoc.ExtractMachinableFeatures(); // Generate Operation cwAPP.ActiveDocGOP(1); // Generate Tool Path ICWPartDoc cwPartDoc = (ICWPartDoc)cwActiveDoc; cwPartDoc.GenerateToolpath(); // Simulation cwAPP.ActiveDocLaunchSimulation(); cwAPP.ActiveDocPlaySimulation(); } catch { } }
private void button7_Click(object sender, EventArgs e) { CWApp cwApp = new CWApp(); CWPartDoc cwPd = (CWPartDoc)cwApp.IGetActiveDoc(); CWDoc cwDoc = (CWDoc)cwApp.IGetActiveDoc(); int GX = (int)CWMachineType.CW_MACHINE_TYPE_TURN; CAMWORKSLib.CWApp cwapp = new CAMWORKSLib.CWApp(); CAMWORKSLib.CWDoc doc = cwapp.IGetActiveDoc(); ICWDispatchCollection Machines = cwapp.GetMachines(GX); foreach (CWTurnMachine item in Machines) { if ("Turn Dual Turret - Inch" == item.Name) { doc.SetMachine2(item); break; } } }
private void button4_Click(object sender, EventArgs e) { CWApp cwApp = new CWApp(); CWPartDoc cwPd = (CWPartDoc)cwApp.IGetActiveDoc(); CWMillMachine cwMiillMach = (CWMillMachine)cwPd.IGetMachine(); string name = cwMiillMach.Name; string duty = cwMiillMach.MachDuty; double feed = cwMiillMach.FeedRateLimit; string ID = cwMiillMach.MachId; double power = cwMiillMach.Horsepower; double spindle = cwMiillMach.SpindleSpeedLimit; CWDoc cwDoc = (CWDoc)cwApp.IGetActiveDoc(); cwApp.ActiveDocEMF();//提取特征 //cwApp.ActiveDocGOP(1);// (暂时不理解,但是不调用 生成操作计划会有问题) //cwApp.ActiveDocGTP();//生成操作计划 CWPartDoc cwPartDoc = (CWPartDoc)cwDoc; CWMachine cwMach = (CWMachine)cwPartDoc.IGetMachine(); CWDispatchCollection cwDispCol = (CWDispatchCollection)cwMach.IGetEnumSetups(); for (int i = 0; i < cwDispCol.Count; i++)// 铣削零件设置组 { CWBaseSetup cwBaseSetup = (CWBaseSetup)cwDispCol.Item(i); if (cwBaseSetup == null) { continue; } Console.Write("铣削设置" + i.ToString()); CWDispatchCollection FeatList = (CWDispatchCollection)cwBaseSetup.IGetEnumFeatures();//方法获取安装程序上的所有特性 for (int j = 0; j < FeatList.Count; j++) { CWMillFeature cwFeat = (CWMillFeature)FeatList.Item(j); int attr = cwFeat.Attribute; string strAttr = ""; int intAttr = 0; cwFeat.GetAttribute(out strAttr, out intAttr);//获取 int subType = cwFeat.SubType; int volume = cwFeat.VolumeType; double depth = cwFeat.Depth; double taperAngle = cwFeat.IGetTaperAngle(); double topFillRadius = cwFeat.IGetTopFilletRadius(); int island = cwFeat.IGetIslandCount(); double dLeng = 0; double dwidth = 0; double dDepth = 0; cwFeat.GetBoundParams(out dLeng, out dwidth, out dDepth); //string [] attrs = cwFeat.IGetAllAttributes(); int tbdid = cwFeat.GetTdbIdForAttribute(strAttr); // CWTurnFeature cwTurn = (CWTurnFeature) // string strName = cwTurn.GetAttributeName(); } } }