我正在尝试通过C#自动捕获JMP图形图像。 从我通过文档中找到的,正确的方法是使用GetGraphicItemByName或GetGraphicItemByType然后使用SaveGraphicItem来获取图形的句柄。
我在上一篇文章中找到了关于这个主题的一些指导:
https://community.jmp.com/t5/Discussions/GetGraphicItemByName-Requires-the-name-where-are-the-names/td-p/20947
具体来说,这个回复正确使用它(文档真的缺乏这个否则)
https://community.jmp.com/t5/Discussions/GetGraphicItemByName-Requires-the-name-where-are-the-names/mp/20950/highlight/true#M19047
然而... 它对我尝试过的任何东西都不起作用。 一切都抛出了同样无用的错误,这似乎是JMP中的本机级别异常:
The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
我已经使用树中的几个不同对象尝试了两种ByType和ByName。 我觉得我必须遗漏一些东西,但我不知道它可能是什么,因为错误并没有给我一点点线索什么是错的。
JMP.Contour contour = Doc.CreateContourPlot();
contour.LaunchAddX(X1);
contour.LaunchAddX(X2);
contour.LaunchAddY(Y);
contour.FillAreas(true);
contour.ShowContours(true);
contour.Launch();
int handle = -1;
string errors = string.Empty;
for (int n = 0; n < 11; n++)
{
string name = "outline box";
switch (n)
{
case 1: name = "outlinebox"; break;
case 2: name = "Outline Box"; break;
case 3: name = "Outline box"; break;
case 4: name = "outline box"; break;
case 5: name = "framebox"; break;
case 6: name = "FrameBox"; break;
case 7: name = "Frame Box"; break;
case 8: name = "frame box"; break;
case 9: name = "Frame box"; break;
case 10: name = "Framebox"; break;
}
try
{
handle = contour.GetGraphicItemByType(name, 1);
//handle = contour.GetGraphicItemByName(name);
Console.WriteLine("Success with n = " + n);
break;
}
catch (Exception e)
{
errors += e.Message + Environment.NewLine;
}
}
if (handle == -1) throw new Exception("No handle found, errors: " + Environment.NewLine + errors);
我解决了这个问题。 原来我的代码中的其他地方出现了错误。 我不确定它为什么会抛出它所做的错误。 由于我的代码中的另一个错误,我提供的表没有我期望的列。 我本以为JMP应该抓住这么简单的错误并抛出一个更相关的异常,这就是为什么我假设函数本身的问题。
如果其他人遇到类似问题,请务必检查输入的所有其他方面,因为您不能依赖JMP报告有意义的异常...