using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using Cognex.VisionPro.Exceptions;
using Cognex.VisionPro.PMAlign;
using Cognex.VisionPro.Display;
using System.Drawing;
using Cognex.VisionPro.CalibFix;
//New tool
public void VisionPro_Add()
{
//Instantiate tool
CogToolBlock CogToolBlock1 = new CogToolBlock();
CogPMAlignTool CogPMAlignTool1 = new CogPMAlignTool();
CogFixtureTool CogFixtureTool1 = new CogFixtureTool();
CogPMAlignTool CogPMAlignTool2 = new CogPMAlignTool();
//Save the tool separately on loading
CogPMAlignTool CogPMAlignTool3 = new CogPMAlignTool();
CogPMAlignTool3 = CogSerializer.LoadObjectFromFile(@"E:\CogPMAlignTool1.vtt") as CogPMAlignTool;
//Named the tool
CogToolBlock1.Name = "CogToolBlock1";
CogPMAlignTool1.Name = "CogPMAlignTool1";
CogFixtureTool1.Name = "CogFixtureTool1";
CogPMAlignTool2.Name = "CogPMAlignTool2";
//Add the tool to the CogtoolBlock tool and save the CogtoolBlock tool.
CogToolBlock1.Tools.Add(CogPMAlignTool1);
CogToolBlock1.Tools.Add(CogFixtureTool1);
CogToolBlock1.Tools.Add(CogPMAlignTool2);
CogSerializer.SaveObjectToFile(CogToolBlock1, @"E:\ToolBlock2.vpp");
MessageBox.Show("Saved successfully");
}
result:
Method 2: Add Tool Output
//New tool
public void VisionPro_Add()
{
//Instantiate tool
CogToolBlock CogToolBlock1 = new CogToolBlock();
CogPMAlignTool CogPMAlignTool1 = new CogPMAlignTool();
CogFixtureTool CogFixtureTool1 = new CogFixtureTool();
CogPMAlignTool CogPMAlignTool2 = new CogPMAlignTool();
//Save the tool separately on loading
CogPMAlignTool CogPMAlignTool3 = new CogPMAlignTool();
CogPMAlignTool3 = CogSerializer.LoadObjectFromFile(@"E:\CogPMAlignTool1.vtt") as CogPMAlignTool;
//Named the tool
CogToolBlock1.Name = "CogToolBlock1";
CogPMAlignTool1.Name = "CogPMAlignTool1";
CogFixtureTool1.Name = "CogFixtureTool1";
CogPMAlignTool2.Name = "CogPMAlignTool2";
string[] s1 = new string[1];
string[] s2 = new string[5];
s1[0] = "|InputImage|InputImage";
s2[0] = "| Results.Item[0].GetPose() | Results.Item[0].GetPose()";
s2[1] = "|Results.Item[0].GetPose().TranslationX|Results.Item[0].GetPose().TranslationX";
s2[2] = "|Results.Item[0].GetPose().TranslationX|Results.Item[0].GetPose().TranslationY";
s2[3] = "|Results.Item[0].GetPose().Rotation|Results.Item[0].GetPose().Rotation";
s2[4] = "|Results.Item[0].Score|Results.Item[0].Score";
CogPMAlignTool1.UserData.Add("_ToolInputTerminals", s1);//Add Terminal -InputImage
CogPMAlignTool1.UserData.Add("_ToolOutputTerminals", s2);
//Add the tool to the CogtoolBlock tool and save the CogtoolBlock tool.
CogToolBlock1.Tools.Add(CogPMAlignTool1);
CogToolBlock1.Tools.Add(CogFixtureTool1);
CogToolBlock1.Tools.Add(CogPMAlignTool2);
CogSerializer.SaveObjectToFile(CogToolBlock1, @"E:\ToolBlock2.vpp");
MessageBox.Show("Saved successfully");
}
Method 3: Separate save tools to load
System Tool Default Address:
Save tool template
Click Right click to save the tool template (.vtt) file
//Loading system initial tool
CogPMAlignTool CogPMAlignTool1 = CogSerializer.LoadObjectFromFile(@"C:\Program Files\Cognex\VisionPro\bin\Templates\Tools\C#\CogPMAlignTool.vtt") as CogPMAlignTool;
CogPMAlignTool CogPMAlignTool2 = CogSerializer.LoadObjectFromFile(@"C:\Program Files\Cognex\VisionPro\bin\Templates\Tools\C#\CogPMAlignTool.vtt") as CogPMAlignTool;
CogFixtureTool CogFixtureTool1 = CogSerializer.LoadObjectFromFile(@"C:\Program Files\Cognex\VisionPro\bin\Templates\Tools\C#\CogFixtureTool.vtt") as CogFixtureTool;
CogToolBlock CogToolBlock1 = CogSerializer.LoadObjectFromFile(@"C:\Program Files\Cognex\VisionPro\bin\Templates\Tools\C#\CogToolBlock.vtt") as CogToolBlock;