机加工(CAM)仿真初探
来源:互联网 发布:朋友圈营销 知乎 编辑:程序博客网 时间:2024/04/19 11:11
最近接触了好几个想做点机加工方面开发的客户。虽然Autodesk有CAM解决方案,甚至云上的CAM 360,但有些用户还是需要自行定制加工过程,尤其走刀的仿真。
Inventor API的Transient Brep和Client Graphics可以帮助得以实现。其实很简单,刀具每走一步,让刀具的实体和基本体进行布尔运算,得到更新的体,然后用Client Graphics体现出来。我尝试做了个小例子,供大家参考。觉得还应有完善的空间。
这个例子,基于附件中的零件,一个体模拟刀具,一个模拟基本体,然后刀具将从处开始向内圆周运动,切削基本体直到圆心。
Inventor.Application oInvApp;Asset toolAppearance;Asset baseAppearance;void CamTest(){ //get active Inventor process oInvApp = System.Runtime.InteropServices.Marshal. GetActiveObject("Inventor.Application") as Inventor.Application; //get active document PartDocument oPartDoc = oInvApp.ActiveDocument as PartDocument; PartComponentDefinition oPartDef = oPartDoc.ComponentDefinition; //Transient Brep object TransientBRep oTBrep = oInvApp.TransientBRep; //Transient Geometry TransientGeometry oTG= oInvApp.TransientGeometry; //base body SurfaceBody oBaseBody = oPartDef.SurfaceBodies[1]; //tool body SurfaceBody oToolBody = oPartDef.SurfaceBodies[2]; //make base body and tool body invisible //we just show client graphics oBaseBody.Visible = false; oToolBody.Visible = false; //make a copy of base body and tool body //we will use them as client graphics SurfaceBody oBaseBody_Copy = oTBrep.Copy(oBaseBody); SurfaceBody oToolBody_Copy = oTBrep.Copy(oToolBody); //Client Graphics ClientGraphics oClientGraphics; try { //delete if the Client Graphics exists oClientGraphics = oPartDef.ClientGraphicsCollection["CAMDemo"]; // An existing client graphics object // was successfully obtained so clean up. oClientGraphics.Delete(); // update the display to see the results. oApp.ActiveView.Update(); } catch { //get the appearance for tool toolAppearance = oPartDoc.Assets["Gold - Metal"]; baseAppearance = oPartDoc.Assets["Plate"]; // Create the ClientGraphics oClientGraphics = oPartDef.ClientGraphicsCollection.Add("CAMDemo"); //add graphics node for base body GraphicsNode _oNode_BaseBody = oClientGraphics.AddNode(1); //add graphics of base body SurfaceGraphics _Gra_BaseBody = _oNode_BaseBody.AddSurfaceGraphics(oBaseBody_Copy); _oNode_BaseBody.Appearance = baseAppearance; //add graphics node for tool body GraphicsNode _oNode_ToolBody = oClientGraphics.AddNode(2); //add graphics of tool body SurfaceGraphics _Gra_ToolBody = _oNode_ToolBody.AddSurfaceGraphics(oToolBody_Copy); _oNode_ToolBody.Appearance = toolAppearance; //CAM Simulation starts: //move tool inside the base along Z Matrix oMovingM = oTG.CreateMatrix(); oMovingM.SetTranslation(oTG.CreateVector(0, 0, -1)); //move tool inside base body: depth = 1 eachCAM(oMovingM, ref oBaseBody_Copy, ref oToolBody_Copy, ref _oNode_BaseBody, ref _oNode_ToolBody, ref _Gra_BaseBody, ref _Gra_ToolBody); // diameter of the tool body double toolDia = 0.5; // how many circle loops the tool will move int loopCount = 10; //from which diamater the tool starts to move double max_CAM_Dia = 4.0; //last matrix of the tool body Matrix oLastMovingM = oTG.CreateMatrix(); oLastMovingM.SetToIdentity(); //tool moves from max diameter to 0 for (int circleLoop = loopCount; circleLoop > 0 ; circleLoop--) { //diameter of this loop double thisDia = max_CAM_Dia * circleLoop / loopCount; //the perimeter of this circle double perimeterofLoop = Math.PI * thisDia; //how many steps the tool needs to move for this loop int circleStepCount = (int)(perimeterofLoop / toolDia) *2; //moving of each circle for (int angleIndex = 1; angleIndex < circleStepCount; angleIndex++) { //get the location the tool will move to double x = thisDia / 2.0 * Math.Cos(angleIndex * Math.PI * 2 / circleStepCount); double y = thisDia/ 2.0 * Math.Sin(angleIndex * Math.PI * 2 / circleStepCount ); //transform matrix Matrix oEachMovingM = oTG.CreateMatrix(); oEachMovingM.SetTranslation(oTG.CreateVector(x, y, 0)); //the last location of the tool affects //so invert and update with the new matrix oLastMovingM.Invert(); oLastMovingM.TransformBy(oEachMovingM); oMovingM = oLastMovingM; //move eachCAM(oMovingM, ref oBaseBody_Copy, ref oToolBody_Copy, ref _oNode_BaseBody, ref _oNode_ToolBody, ref _Gra_BaseBody, ref _Gra_ToolBody); //record the current matrix for next use oLastMovingM = oEachMovingM; } } } }// each step of movingvoid eachCAM(Matrix _oMovingM, ref SurfaceBody _BaseBody, ref SurfaceBody _ToolBody, ref GraphicsNode _BaseBodyNode, ref GraphicsNode _ToolBodyNode, ref SurfaceGraphics _BaseGrap, ref SurfaceGraphics _ToolGrap ){ TransientBRep oTBrep = oInvApp.TransientBRep; // we need to recreate the graphics. _BaseGrap.Delete(); _ToolGrap.Delete(); //transform the tool body oTBrep.Transform(_ToolBody, _oMovingM); //remove material of the base body oTBrep.DoBoolean(_BaseBody, _ToolBody, BooleanTypeEnum.kBooleanTypeDifference); //add the update bodies again _BaseGrap = _BaseBodyNode.AddSurfaceGraphics(_BaseBody); _ToolGrap = _ToolBodyNode.AddSurfaceGraphics(_ToolBody); //assign the appearance to the tool graphics _BaseBodyNode.Appearance = baseAppearance; _ToolBodyNode.Appearance =toolAppearance; //update the view oInvApp.ActiveView.Update(); }
注意,此gif里出现的图像残留,是制作此gif时产生的。用Inventor测试时,没有此现象。
0 0
- 机加工(CAM)仿真初探
- CAM对高速加工的影响
- CAM对高速加工的影响
- CAM
- Sescoi.WorkNC.G3.V20.06 模具加工计算机辅助制造(CAM)软件系统
- Delcam DentMILL 2015 R1(牙科CAM加工编程系统) 官方版下载
- Galileo+wifi+cam(二)
- 加工(单链表)
- 零件加工(贪心)
- 零件加工(贪心)
- 加工
- 进阶篇:3.4)机加工件设计指南
- 设计、仿真、工艺、加工、优化、开发交流 · 行业软件、二次开发、优化技术
- 关于CAM卡(大卡)和智能卡(小卡)
- PCB抄板制版技术(一):CAM
- CAM软件
- ASCII Cam
- CAM表
- 系统开发之概述
- 网友的图解SQL
- 单链表的取元素算法
- 内边距、边框和外边距的关系
- 例解 Linux 下 make 命令
- 机加工(CAM)仿真初探
- 删除win7下的带锁的文件,经测试可行。
- 小强的HTML5移动开发之路(33)—— jqMobi基础
- 2013 工具使用整理
- SQL SERVER2012新分页方式
- 盲转
- Qt中文
- UF超滤膜组件工艺在白酒制备中的应用
- 给C语言添加花指令,抵御反汇编