
E:\DISK1\VisionPro\Images\bracket_std.idb創建兩個塊第一個做模板匹配和定位第二個是卡尺把8位圖給輸出為什么不是參數而是圖片因為參數綁定圖片上了。第二個卡尺塊分別設置好給的坐標查看運行正常開始寫代碼測試代碼可跳過我想寫個測試代碼用來輸出內容這一部分可以不用看//測試類的標簽定義一下CogGraphicLabel test;//創建標簽組件類 - 用來測試GroupRun里面的test new CogGraphicLabel();//設置標簽的參數test.Font new Font(微軟雅黑,12); //字體test.Color CogColorConstants.Yellow; //設置顏色test.X 20;//x坐標test.Y 20;//y坐標test.Text string.Format(測試);//在ModifyLastRunRecord里面寫//輸出標簽mToolBlock.AddGraphicToRunRecord(test,lastRecord,CogCaliperTool1.InputImage,script);就OJBK了開始寫代碼代碼列表集合包using System.Collections.Generic;//集合的包運行函數里面寫的代碼//先找到mToolBlock塊的類拿到里面的三個卡尺工具//卡尺1CogCaliperTool kc1 mToolBlock.Tools[CogCaliperTool1] as CogCaliperTool;//獲取值類型CogCaliperResult kc1zlx kc1.Results[0];//卡尺2CogCaliperTool kc2 mToolBlock.Tools[CogCaliperTool2] as CogCaliperTool;//獲取值類型CogCaliperResult kc2zlx kc2.Results[0];//卡尺3CogCaliperTool kc3 mToolBlock.Tools[CogCaliperTool3] as CogCaliperTool;//獲取值類型CogCaliperResult kc3zlx kc3.Results[0];//清空每次執行清空防止多次執行。bqlb.Clear();//創建第1個卡尺坐標,獲取寬度//設置標簽的參數CogGraphicLabel test1 new CogGraphicLabel();//創建標簽組件類test1.Font new Font(微軟雅黑, 12); //字體test1.Color CogColorConstants.Yellow; //設置顏色test1.X kc1zlx.PositionX;//x坐標test1.Y kc1zlx.PositionY;//y坐標test1.Text string.Format(卡尺1寬度{0}, kc1zlx.Width);//設置標簽內容bqlb.Add(test1);//添加到集合里面//創建第2個卡尺坐標,獲取寬度CogGraphicLabel test2 new CogGraphicLabel();//創建標簽組件類test2.Font new Font(微軟雅黑, 12); //字體test2.Color CogColorConstants.Yellow; //設置顏色test2.X kc2zlx.PositionX;//x坐標test2.Y kc2zlx.PositionY;//y坐標test2.Text string.Format(卡尺2寬度{0}, kc2zlx.Width);//設置標簽內容bqlb.Add(test2);//添加到集合里面//創建第3個卡尺坐標,獲取寬度CogGraphicLabel test3 new CogGraphicLabel();//創建標簽組件類test3.Font new Font(微軟雅黑, 12); //字體test3.Color CogColorConstants.Yellow; //設置顏色test3.X kc3zlx.PositionX;//x坐標test3.Y kc3zlx.PositionY;//y坐標test3.Text string.Format(卡尺3寬度{0}, kc3zlx.Width);//設置標簽內容bqlb.Add(test3);//添加到集合里面圖片輸出里面寫public override void ModifyLastRunRecord(Cognex.VisionPro.ICogRecord lastRecord){//輸出列表里的所有標簽foreach(CogGraphicLabel dgbq in bqlb){//輸出測試標簽mToolBlock.AddGraphicToRunRecord(dgbq,lastRecord,CogCaliperTool1.InputImage,script);}}結果