全站搜索
文章正文
排钻CAM文件脚本使用例子
Published:2020-05-19 16:24:22    Text Size:【BIG】【MEDIUM】【SMALL
------------------------------------------------------------------------------------
--- 板件载入后自动处理脚本(LUA语言) 此文件放到setting目录下,加载数据后会自动执行
----          常用函数说明
----
----  GetBanData  得到板件信息
----  RotateBan 旋转板件
----  TrunBan  翻板
----  MirrorBan  镜像板件
----  EnableHoles 禁用孔槽
----  RotateBanByXslot 旋转板件根据X方形槽
----  RotateBanByYslot 旋转板件根据Y方形槽
----  GetPoint  得到点坐标
----  GetReal   得到小数值
----  GetLong   得到整数值
----  GetSubObject  得到元素(孔 槽 等)
----  OriginBan 板件基点重置
----  GetRectByType 得到孔槽元素外框
----------------------------------------------------------------------------------------

----常量定义
M_PI = 3.14159265358979323846;
HOLE_FACE =100; --直孔
HOLE_SIDE_TOP =200; --水平孔
HOLE_SIDE_LEFT =300;
HOLE_SIDE_BOTTOM     =400;
HOLE_SIDE_RIGHT     =500;
HOLE_SIDE_YADD =200;
HOLE_SIDE_XSUB =300;
HOLE_SIDE_YSUB     =400;
HOLE_SIDE_XADD     =500;
SLOT_CUTTER =700; --槽,直线,曲线,不割穿
SLOT_SIDE_TOP =720; --侧面槽 上
SLOT_SIDE_LEFT =730; --侧面槽 左
SLOT_SIDE_BOTTOM =740; --侧面槽 下
SLOT_SIDE_RIGHT =750; --侧面槽 右
SLOT_SIDE_YADD =720; --侧面槽Y+
SLOT_SIDE_XSUB =730; --侧面槽X-
SLOT_SIDE_YSUB =740; --侧面槽Y-
SLOT_SIDE_XADD =750; --侧面槽X+
CUT_THROUGH =800;--直线,曲线,割穿了
WILLING_FILL =900; --铣型,将某个区域铣到一个深度
HOLE_BACK =1000; --背面直孔
WILLING_CUTTER_BACK =1700; --背面铣型
SLOT_CUTTER_BACK =1800;
WILLING_FILL_BACK =1900; --背面铣型,将某个区域铣到一个深度
MACHINE_SIDE_AUTO  =0;
MACHINE_SIDE_XADD  =1;
MACHINE_SIDE_XSUB  =2;
MACHINE_SIDE_YADD  =3;
MACHINE_SIDE_YSUB  =4;
MACHINE_SIDE_ZADD  =5;
MACHINE_SIDE_ZSUB  =6;

---板件信息
curban = 
{id=0         --板件句柄
,name=""      --名称
,code=""      --编码(二维码)
,xlen=0       --X方向尺寸
,ylen=0      --Y方向尺寸
,zlen=0  --Z方向尺寸
,fbtop=0 --封边厚度 上
,fbbottom=0 --封边厚度 下
,fbleft=0 --封边厚度 左
,fbright=0 --封边厚度 右
,vholes=0 --直孔数量
,bholes=0 --背面孔数量
,hholes=0 --水平孔数量
,fslots=0 --正面槽数量
,bslots=0 --背面槽数量
,fslots_x=0 --正面X槽数量
,fslots_y=0 --正面Y槽数量
,bslots_x=0 --背面X槽数量
,bslots_y=0 --背面Y槽数量
,cutlines=0   --切割线数量
,fcutlines=0   --正面切割线数量
,bcutlines=0   --背面切割线数量
};

---禁用的孔和槽个数
disableholes =
{vholes=0
,bholes=0
,hholes=0
,fslots=0
,bslots=0
,fslots_x=0
,fslots_y=0
,bslots_x=0
,bslots_y=0
,cutlines=0
,cutlines=0   --切割线数量
,fcutlines=0   --正面切割线数量
,bcutlines=0   --背面切割线数量
};


GetBanInfo(curban,disableholes); ---初始化BAN数据
OriginBan(2);
---------------------------------------------------------------
---
---                 对接设定
---  1 前端已经开槽并且数据内没有槽的信息
---  2 规律是槽靠基准,孔距离基准34 或 44
---
--  解决办法:
--     找到距离板边34 44 的孔就可以确定那个边是基准边了,
--  如果基准边是长边则靠近侧靠, 短板则靠近定位柱,规则可以自己修改
---------------------------------------------------------------

-----------------------------------------
---
---  第一步  如果Y方向大于X方向,旋转90度
---
----------------------------------------
if(curban.ylen>curban.xlen)  then
  RotateBan(-1.0*M_PI/2.0);
  GetBanInfo(curban,disableholes);
  OriginBan(2);    
end


-------------------------------------
---
---  第二步 根据34  33的规律找基准边
---
------------------------------------
 jizhun=-1;
 allrect={ltx=0, lty=0, rbx=0, rby=0};
 GetRectByType(allrect,{},-3); --参数-3,得到的是板的最外框
 curholes = {};
 EnumObjects(curholes);--枚举当前板件内的孔和槽
 for i = 0, #curholes do
    pos1 = {};
GetPoint(curholes[i],-1,pos1);---得到起点坐标
ldist = pos1[0] - allrect.ltx;  --x-孔到边距离
tdist = allrect.lty - pos1[1];  --y+到边距离
rdist = allrect.rbx - pos1[0];  -- x+孔到边距离
bdist = pos1[1] - allrect.rby;  -- y-到边距离

if((ldist==34) or (ldist==44)) then  --当前基准边是 x-边
   jizhun=0;
elseif((tdist==34) or (tdist==44)) then  --当前基准边是 y+
   jizhun=1;
elseif((rdist==34) or (rdist==44)) then  --当前基准边是 x+
   jizhun=2;
elseif((bdist==34) or (bdist==44)) then  --当前基准边是 y-
   jizhun=3;
end
if(jizhun>-1) then --找到了基准
  --MsgBox("X-:",holerect.ltx,"-",allrect.ltx,"=",ldist,"  Y+:",allrect.lty,"-",holerect.lty,"=",tdist,"  X+:", allrect.rbx, "-", holerect.rbx  ,"=",rdist,"  Y-",holerect.rby, "-" ,allrect.rby,"=",bdist);  
  break;
end
  end  
  

--MsgBox(0);
------------------------
---
---  第三步 根据规则旋转  
---
-----------------------
--guize=0 放板规则:长槽靠侧靠(Y+),短槽靠定位柱(x+)
--guize=1 放板规则:长槽靠夹具(Y-),短槽靠定位柱(x+)
guize=0; 


if(guize==0) then
if(jizhun==0) then  --当前基准边是 x-边
RotateBan(M_PI);
GetBanInfo(curban,disableholes);
OriginBan(2);  
--MsgBox("x-  --> x+"); 
elseif(jizhun==1) then  --当前基准边是 y+
-- MsgBox("IS Y+");  
    elseif(jizhun==2) then  --当前基准边是 x+
--MsgBox("IS X+");
elseif(jizhun==3) then  --当前基准边是 y-
RotateBan(M_PI);--旋转到y+边
GetBanInfo(curban,disableholes);
OriginBan(2);
--MsgBox("y- --> y+");  
    end   
elseif(guize==1) then
if(jizhun==0) then  --当前基准边是 x-边
RotateBan(M_PI);
GetBanInfo(curban,disableholes);
OriginBan(2);  
--MsgBox("x-  --> x+"); 
elseif(jizhun==1) then  --当前基准边是 y+
RotateBan(M_PI);
GetBanInfo(curban,disableholes);
OriginBan(2);  
--MsgBox("Y+  --> Y-");  
    elseif(jizhun==2) then  --当前基准边是 x+
--MsgBox("IS X+");
elseif(jizhun==3) then  --当前基准边是 y-
--MsgBox(" ISA Y-");  
    end  
end
 
 
 
*******************************  厚封边调整例子*******************************
-- 2 厚封边靠夹具或定位柱, 支持多个厚边
--Y+ X+是厚封边,需要绕X轴翻板
if((curban.fbtop>curban.fbbottom) and (curban.fbright>curban.fbleft)) then
    TrunBan(1);
 OriginBan(2);
 --MsgBox("1"); 
 
--Y- X-是厚封边 需要绕 Y轴翻板
elseif((curban.fbbottom>curban.fbtop) and (curban.fbleft>curban.fbright)) then
    TrunBan(0);
 OriginBan(2);
    --MsgBox("2"); 
 
--Y+ 是厚封边 旋转180度 
elseif(curban.fbtop>curban.fbbottom)  then
     RotateBan(M_PI);
  OriginBan(2);
  --MsgBox("3"); 
 
--X-是厚封边 旋转180度
elseif (curban.fbleft>curban.fbright) then
     RotateBan(M_PI);
  OriginBan(2);
   --MsgBox("4"); 
else
    --MsgBox("4"); 
end
 
 

 

搜索
脚注信息

广州微兆信息科技有限公司   地址:广州大道北 梅岗路1号 北方工业A108
Tel:020-87748855 Email:support@microdraw.com QQ2353925505