在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1、加载模板 1 tplpath = Application.StartupPath + "\\xxx.vpp"; 2 public Cognex.VisionPro.ToolGroup.CogToolGroup toolGroup= (Cognex.VisionPro.ToolGroup.CogToolGroup)Cognex.VisionPro.CogSerializer.LoadObjectFromFile(tplpath); 2、创建根目录 1 /// <summary> 2 /// 加载相机模板 3 /// </summary> 4 private void LoadCogToolGroup(CogToolGroup tg) 5 { 6 toolGroup = tg; 7 if (toolGroup.Tools.Count > 0) 8 { 9 TreeNode node=new TreeNode("相机模板"); 10 trvTpl.Nodes.Add(node); 11 trvTpl.ExpandAll(); 12 13 foreach (ICogTool icCogTool in toolGroup.Tools) 14 { 15 GetToolBlockTools(icCogTool, node); 16 } 17 } 18 } 3、递归查找 1 private void GetToolBlockTools(ICogTool icCogTool,TreeNode tnode) 2 { 3 if (icCogTool.GetType().Name == "CogToolBlock") 4 { 5 CogToolBlock c = (CogToolBlock)icCogTool; 6 if (icCogTool.Name==tnode.Text) 7 { 8 TreeNode[] tds = trvTpl.Nodes.Find(icCogTool.Name, true); 9 if(tds.Length>0) 10 GetToolBlockTools(icCogTool, tds[0]); 11 } 12 else 13 { 14 TreeNode node = new TreeNode(icCogTool.Name); 15 node.Tag = icCogTool; 16 tnode.Nodes.Add(node); 17 foreach (ICogTool ict in c.Tools) 18 { 19 GetToolBlockTools(ict, node); 20 } 21 } 22 } 23 else 24 { 25 TreeNode node = new TreeNode(icCogTool.Name); 26 node.Tag = icCogTool; 27 tnode.Nodes.Add(node); 28 } 29 }
|
请发表评论